Function datealgo::secs_to_dhms
source · pub const fn secs_to_dhms(secs: i64) -> (i32, u8, u8, u8)
Expand description
Split total seconds to days, hours, minutes and seconds
Given seconds counting from Unix epoch (January 1st, 1970) returns a (days, hours, minutes, seconds)
tuple.
Panics
Argument must be between RD_SECONDS_MIN and RD_SECONDS_MAX inclusive.
Bounds are checked using debug_assert
only, so that the checks are not
present in release builds, similar to integer overflow checks.
Examples
use datealgo::{secs_to_dhms, date_to_rd};
assert_eq!(secs_to_dhms(0), (0, 0, 0, 0));
assert_eq!(secs_to_dhms(86400), (1, 0, 0, 0));
assert_eq!(secs_to_dhms(86399), (0, 23, 59, 59));
assert_eq!(secs_to_dhms(-1), (-1, 23, 59, 59));
assert_eq!(secs_to_dhms(1684574678), (date_to_rd((2023, 5, 20)), 9, 24, 38));
Algorithm
See examples 14 and 15 of:
Neri C, Schneider L. “Euclidean affine functions and their application to calendar algorithms”. Softw Pract Exper. 2022;1-34. doi: 10.1002/spe.3172.