Function datealgo::systemtime_to_datetime
source · pub fn systemtime_to_datetime(
st: SystemTime
) -> Option<(i32, u8, u8, u8, u8, u8, u32)>
Expand description
Convert std::time::SystemTime
to year, month, day, hours, minutes,
seconds and nanoseconds
Given std::time::SystemTime
returns an Option of (year, month, day, hours, minutes, seconds, nanoseconds)
tuple.
Errors
Returns None
if the time is before RD_SECONDS_MIN or after
RD_SECONDS_MAX.
Examples
use datealgo::systemtime_to_datetime;
use std::time::{Duration, UNIX_EPOCH};
assert_eq!(systemtime_to_datetime(UNIX_EPOCH), Some((1970, 1, 1, 0, 0, 0, 0)));
assert_eq!(systemtime_to_datetime(UNIX_EPOCH + Duration::from_secs(1684574678)), Some((2023, 5, 20, 9, 24, 38, 0)));
assert_eq!(systemtime_to_datetime(UNIX_EPOCH - Duration::from_secs(1)), Some((1969, 12, 31, 23, 59, 59, 0)));
assert_eq!(systemtime_to_datetime(UNIX_EPOCH - Duration::new(0, 1)), Some((1969, 12, 31, 23, 59, 59, 999_999_999)));
Algorithm
Combination of existing functions for convenience only.