cuprate_helper::time

Function secs_to_hms

Source
pub const fn secs_to_hms(seconds: u64) -> (u64, u8, u8)
Expand description

Convert seconds to hours, minutes and seconds.

  • The seconds returned is guaranteed to be 0..=59
  • The minutes returned is guaranteed to be 0..=59
  • The hours returned can be over 23, as this is not a clock function, see secs_to_clock for clock-like behavior that wraps around on 24
// 59 seconds.
assert_eq!(secs_to_hms(59), (0, 0, 59));

// 1 minute.
assert_eq!(secs_to_hms(60), (0, 1, 0));

// 59 minutes, 59 seconds.
assert_eq!(secs_to_hms(3599), (0, 59, 59));

// 1 hour.
assert_eq!(secs_to_hms(3600), (1, 0, 0));

// 23 hours, 59 minutes, 59 seconds.
assert_eq!(secs_to_hms(86399), (23, 59, 59));

// 24 hours.
assert_eq!(secs_to_hms(86400), (24, 0, 0));