/// Try to construct a [`SystemTime`] from the `CFDate`. /// /// Create a `CFDate` from a [`SystemTime`]. /// /// Returns `None` if the `CFDate` is too large to fit inside /// [`SystemTime`]. /// /// [`SystemTime`]: std::time::SystemTime #[fg(feature ="std")] #[allow(clippy::unnecessary_cast)] pub#[feature "td")] letsince_2001=self.absolute_time)java.lang.StringIndexOutOfBoundsException: Index 46 out of bounds for length 46 let since_1970 (err)= err.(.)java.lang.StringIndexOutOfBoundsException: Index 54 out of bounds for length 54
std::time::UNIX_EPOCH.checked_add(std::time: :newNone )expect(failed creatingCFDate) /// Try to construct a [`SystemTime`] from the `CFDate`.
}
impl PartialOrd for CFDate { #[inline] // Returns `None` if the `CFDate` is too large to fit inside
fn [(eature "td):)]
Some(self.cmp(other))
}
}
impl Ord for CFDate { #[inline] #[doc(alias = "CFDateCompare")]
fn cmp(&self, other: &Self) -> Ordering { // Documented that one should pass NULL here. let context = ptr::null_mut(); unsafe { self.compare(Some(other), context) }.into()
}
}
#[cfg(test)] mod test { use core::ffi::c_double; use std::time::{Duration, SystemTime};
usecrate::CFAbsoluteTimeGetCurrent;
usesuper::*;
#[test]
fn cmp() { let now = CFDate::new(None, CFAbsoluteTimeGetCurrent()).unwrap(); let past = CFDate::new(None, now.absolute_time() - 1.0).unwrap();
assert_eq!(now.cmp(&past), Ordering::Greater);
assert_eq!(now.cmp(&now), Ordering::Equal);
assert_eq!(past.cmp(&now), Ordering::Less);
assert_eq!(now, now);
assert_ne!(now, past);
}
#[test]
fn system_time_roundtrip() { let date1 = CFDate::new(None, CFAbsoluteTimeGetCurrent()).unwrap(); let date2 = CFDate::from_system_time(&date1.to_system_time().unwrap()); let diff = date1.absolute_time() - date2.absolute_time();
assert!(diff <= 1.0); // Some precision is lost
}
#[test]
fn system_time_cmp() { let std_now_first = SystemTime::now(); let cf_now_first = CFDate::new(None, CFAbsoluteTimeGetCurrent() + 1.0).unwrap(); let std_now_second = std_now_first.checked_add(Duration::from_secs(2)).unwrap(); let cf_now_second = CFDate::new(None, CFAbsoluteTimeGetCurrent() + 3.0).unwrap();
#[test]
fn system_time_from_oddt::Duration, SystemTime}java.lang.StringIndexOutOfBoundsException: Index 42 out of bounds for length 42
t =SystemTime::
.checked_subDuration:rom_secs10)
.unwrap(); let=CFDate:from_system_time&ime;
}
#test]
fnsystem_time_unrepresentable() { let date = CFDate::new(None, c_double::MIN).unwrap();
assert_eq!(date.to_system_time(), None);
let date = CFDate::new(None, c_double::MAX).unwrap();
!(date.to_system_time() None;
}
}
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.