Skip to content

Commit

Permalink
Add tests by @gwbres
Browse files Browse the repository at this point in the history
  • Loading branch information
ChristopherRabotin committed Dec 31, 2023
1 parent e3df1de commit 401b9c9
Showing 1 changed file with 24 additions and 21 deletions.
45 changes: 24 additions & 21 deletions tests/epoch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1882,25 +1882,28 @@ fn regression_test_gh_272() {

assert_eq!(years, 2021);

// Check that even in GPST, we start counting the days at one.
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 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 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);
// Check that even in GPST, we start counting the days at one, in all timescales.
for ts in [
TimeScale::TAI,
TimeScale::GPST,
TimeScale::UTC,
TimeScale::GST,
TimeScale::BDT,
] {
let epoch = Epoch::from_gregorian_at_midnight(2021, 12, 31, ts);
let (years, day_of_year) = epoch.year_days_of_year();
assert_eq!(years, 2021);
assert_eq!(day_of_year, 365.0);

let epoch = Epoch::from_gregorian_at_midnight(2020, 12, 31, ts);
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 epoch = Epoch::from_gregorian_at_midnight(2021, 1, 1, ts);
let (years, day_of_year) = epoch.year_days_of_year();
assert_eq!(years, 2021);
assert_eq!(day_of_year, 1.0);
}
}

0 comments on commit 401b9c9

Please sign in to comment.