use std::{
fmt,
time::{Duration, SystemTime, UNIX_EPOCH},
}; use time::{format_description::well_known::Rfc3339, OffsetDateTime, UtcOffset};
/// A UTC timestamp used for serialization to and from the plist date type. /// /// Note that while this type implements `Serialize` and `Deserialize` it will behave strangely if /// used with serializers from outside this crate. #[derive(Clone, Copy, Eq, Hash, PartialEq)] pubstruct Date {
inner: SystemTime,
}
pub(crate) struct InfiniteOrNanDate;
impl Date { /// The unix timestamp of the plist epoch. const PLIST_EPOCH_UNIX_TIMESTAMP: Duration = Duration::from_secs(978_307_200);
pub(crate) fn from_seconds_since_plist_epoch(
timestamp: f64,
) -> Result<Date, InfiniteOrNanDate> { // `timestamp` is the number of seconds since the plist epoch of 1/1/2001 00:00:00. let plist_epoch = UNIX_EPOCH + Date::PLIST_EPOCH_UNIX_TIMESTAMP;
if !timestamp.is_finite() { return Err(InfiniteOrNanDate);
}
let is_negative = timestamp < 0.0; let timestamp = timestamp.abs(); let seconds = timestamp.floor() as u64; let subsec_nanos = (timestamp.fract() * 1e9) as u32;
let dur_since_plist_epoch = Duration::new(seconds, subsec_nanos);
let inner = if is_negative {
plist_epoch.checked_sub(dur_since_plist_epoch)
} else {
plist_epoch.checked_add(dur_since_plist_epoch)
};
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.