diff --git a/src/duration.rs b/src/duration.rs index d8403c5..aec2875 100644 --- a/src/duration.rs +++ b/src/duration.rs @@ -1027,7 +1027,7 @@ impl Add for Duration { } } - if me.centuries == Self::MIN.centuries && self.nanoseconds < Self::MIN.nanoseconds { + if me.centuries == Self::MIN.centuries { // Then we do the operation backward match me .nanoseconds diff --git a/src/epoch.rs b/src/epoch.rs index dac4058..83c04e8 100644 --- a/src/epoch.rs +++ b/src/epoch.rs @@ -13,9 +13,9 @@ use crate::leap_seconds::{LatestLeapSeconds, LeapSecondProvider}; use crate::parser::Token; use crate::{ Errors, MonthName, TimeScale, BDT_REF_EPOCH, DAYS_PER_YEAR_NLD, ET_EPOCH_S, GPST_REF_EPOCH, - GST_REF_EPOCH, J1900_OFFSET, J1900_REF_EPOCH, J2000_TO_J1900_DURATION, MJD_OFFSET, - NANOSECONDS_PER_DAY, NANOSECONDS_PER_MICROSECOND, NANOSECONDS_PER_MILLISECOND, - NANOSECONDS_PER_SECOND_U32, UNIX_REF_EPOCH, + GST_REF_EPOCH, J1900_OFFSET, J2000_TO_J1900_DURATION, MJD_OFFSET, NANOSECONDS_PER_DAY, + NANOSECONDS_PER_MICROSECOND, NANOSECONDS_PER_MILLISECOND, NANOSECONDS_PER_SECOND_U32, + UNIX_REF_EPOCH, }; use crate::efmt::format::Format; @@ -2504,19 +2504,7 @@ impl Epoch { #[must_use] /// Returns the number of Gregorian years of this epoch in the current time scale. pub fn year(&self) -> i32 { - let mut year = Self::compute_gregorian(self.to_duration()).0; - if self.time_scale.ref_epoch() != J1900_REF_EPOCH { - // We need to correct for the year epoch error - let ref_offset_days = (self - .time_scale - .ref_epoch() - .round(DAYS_PER_YEAR_NLD * Unit::Day) - - J1900_REF_EPOCH) - .to_unit(Unit::Day); - let ref_year_offset = ref_offset_days / DAYS_PER_YEAR_NLD; - year += ref_year_offset.floor() as i32; - } - year + Self::compute_gregorian(self.duration_since_j1900_tai).0 } #[must_use] diff --git a/tests/epoch.rs b/tests/epoch.rs index cdcc521..a9ac9f4 100644 --- a/tests/epoch.rs +++ b/tests/epoch.rs @@ -1883,19 +1883,24 @@ fn regression_test_gh_272() { assert_eq!(years, 2021); // Check that even in GPST, we start counting the days at one. - let epoch2 = Epoch::from_str("2021-12-31T00:00:00 GPST").unwrap(); - let (years, day_of_year) = epoch2.year_days_of_year(); + let epoch = Epoch::from_str("2021-12-31T00:00:00 GPST").unwrap(); + let (years, day_of_year) = epoch.year_days_of_year(); assert_eq!(years, 2021); assert_eq!(day_of_year, 365.0); - let epoch2 = Epoch::from_str("2020-12-31T00:00:00 GPST").unwrap(); - let (years, day_of_year) = epoch2.year_days_of_year(); + let epoch = Epoch::from_str("2020-12-31T00:00:00 GPST").unwrap(); + let (years, day_of_year) = epoch.year_days_of_year(); assert_eq!(years, 2020); // 366 days in 2020, leap year. assert_eq!(day_of_year, 366.0); - let epoch2 = Epoch::from_str("2021-01-01T00:00:00 UTC").unwrap(); - let (years, day_of_year) = epoch2.year_days_of_year(); + let epoch = Epoch::from_str("2021-01-01T00:00:00 UTC").unwrap(); + let (years, day_of_year) = epoch.year_days_of_year(); + assert_eq!(years, 2021); + assert_eq!(day_of_year, 1.0); + + let epoch = Epoch::from_str("2021-01-01T00:00:00 GPST").unwrap(); + let (years, day_of_year) = epoch.year_days_of_year(); assert_eq!(years, 2021); assert_eq!(day_of_year, 1.0); }