pub fn from_timestamp(ts: Timestamp) -> FirestoreResult<DateTime<Utc>>Expand description
Converts a Google prost_types::Timestamp to a chrono::DateTime<Utc>.
Firestore uses Google’s Timestamp protobuf message to represent timestamps.
This function facilitates conversion to the more commonly used chrono::DateTime<Utc>
in Rust applications.
§Arguments
ts: The GoogleTimestampto convert.
§Returns
A FirestoreResult containing the DateTime<Utc> on success, or a
FirestoreError::DeserializeError if the timestamp is invalid or out of range.
§Examples
use firestore::timestamp_utils::from_timestamp;
use chrono::{Utc, TimeZone};
let prost_timestamp = gcloud_sdk::prost_types::Timestamp { seconds: 1670000000, nanos: 0 };
let chrono_datetime = from_timestamp(prost_timestamp).unwrap();
assert_eq!(chrono_datetime, Utc.with_ymd_and_hms(2022, 12, 2, 16, 53, 20).unwrap());