diff options
| author | Botahamec <botahamec@outlook.com> | 2022-03-16 14:52:31 -0400 |
|---|---|---|
| committer | Botahamec <botahamec@outlook.com> | 2022-03-16 14:52:31 -0400 |
| commit | e0e0a18a4bc873583e973d771669e88a92b20d92 (patch) | |
| tree | ba060d810c4621ec7e489afb19ad180a6b2ab755 /src/tai.rs | |
| parent | 5ca69f1830763b689bae9c4873a2912b3f1e23b1 (diff) | |
| parent | 954cfd1385709d41ef0ece9c78b8dcee236f55e4 (diff) | |
Merge branch 'master' of https://github.com/botahamec/botic
Diffstat (limited to 'src/tai.rs')
| -rw-r--r-- | src/tai.rs | 16 |
1 files changed, 9 insertions, 7 deletions
@@ -11,6 +11,7 @@ use crate::{ static GLOBAL_LEAP_SECONDS: RwLock<LeapSeconds> = const_rwlock(LeapSeconds::empty()); +#[derive(Debug)] struct LeapSeconds(Vec<DateTime<Utc>>); impl LeapSeconds { @@ -78,7 +79,7 @@ impl TimeZone for Tai { fn utc_offset(&self, date_time: DateTime<Utc>) -> UtcOffset { let leap_seconds = GLOBAL_LEAP_SECONDS.read(); let past_leap_seconds = leap_seconds.leap_seconds_before_inclusive(date_time); - UtcOffset::from_seconds(-(past_leap_seconds as isize + 10)) + UtcOffset::from_seconds(-(past_leap_seconds as i32 + 10)) } // TODO optimize @@ -93,19 +94,20 @@ impl TimeZone for Tai { // calculate the number of seconds that have passed since date_time in UTC let leap_seconds = GLOBAL_LEAP_SECONDS.read(); let utc_dt = DateTime::from_utc(date_time, Utc); - let mut past_leap_seconds = leap_seconds.leap_seconds_before_inclusive(utc_dt); + let mut past_leap_seconds = dbg!(leap_seconds.leap_seconds_before_inclusive(utc_dt)); let mut prev_pls = 0; // use this to see if the number of leap seconds has been updated // check if any leap seconds were found because of this calculation // keep checking until there is no longer a change in the total leap seconds while past_leap_seconds != prev_pls { prev_pls = past_leap_seconds; - let ndt = date_time.add_seconds(past_leap_seconds as isize); + // TODO think about this discard + let (ndt, _) = dbg!(date_time.add_seconds_overflowing(past_leap_seconds as i64)); let utc_dt = DateTime::from_utc(ndt, Utc); - past_leap_seconds = leap_seconds.leap_seconds_before_inclusive(utc_dt); + past_leap_seconds = dbg!(leap_seconds.leap_seconds_before_inclusive(utc_dt)); } - Ok(UtcOffset::from_seconds(-(past_leap_seconds as isize + 10))) + Ok(UtcOffset::from_seconds(-(past_leap_seconds as i32 + 10))) } } @@ -125,7 +127,7 @@ mod tests { .unwrap() }; - assert_eq!(offset, UtcOffset::from_seconds(-10)) + assert_eq!(offset, UtcOffset::from_seconds(-10)); } #[test] @@ -139,6 +141,6 @@ mod tests { .unwrap() }; - assert_eq!(offset, UtcOffset::from_seconds(-11)) + assert_eq!(offset, UtcOffset::from_seconds(-11)); } } |
