Skip to main content

chrono_to_timestamp

Function chrono_to_timestamp 

Source
pub fn chrono_to_timestamp(dt: DateTime<Utc>) -> Timestamp
Expand description

Convert a chrono::DateTime<Utc> to a [google.protobuf.Timestamp].

§Safety of the subsec cast

chrono guarantees timestamp_subsec_nanos() is always < 1_000_000_000, so the as i32 truncation is lossless and the as u32i32 reinterpret cannot overflow.

§Example

use api_bones::connect::chrono_to_timestamp;

let ts = chrono_to_timestamp(chrono::Utc::now());
assert!(ts.seconds >= 0);