From 6eb1b1efbc5ebcb93646ec1a34c31eb216f302e8 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Sun, 22 Jan 2023 12:50:49 +0100 Subject: [PATCH] bugfix, additional test and CHANGELOG bump --- CHANGELOG.md | 5 +++++ src/time/cds.rs | 12 ++++++++++++ 2 files changed, 17 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6988ea4..54e9bb6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,11 @@ and this project adheres to [Semantic Versioning](http://semver.org/). - Add `Ord` and `PartialOrd` implementations. - Add `Add` and `AddAssign` implementations. +## Fixed + +- `time::cds::TimeProvider`: Fixed a big where subsecond milliseconds were not accounted for + when the provider has no submillisecond precision. + # [v0.5.0] 2023-01-20 The timestamp of `PusTm` is now optional. See Added and Changed section for details. diff --git a/src/time/cds.rs b/src/time/cds.rs index 73b11c5..6ce6a6b 100644 --- a/src/time/cds.rs +++ b/src/time/cds.rs @@ -996,8 +996,10 @@ fn add_for_max_ccsds_days_val( _ => None, } } else { + increment_ms_of_day(&mut next_ms_of_day, duration.subsec_millis(), &mut next_ccsds_days); None }; + // The subsecond millisecond were already handled. let full_seconds = duration.as_secs(); let secs_of_day = (full_seconds % SECONDS_PER_DAY as u64) as u32; let ms_of_day = secs_of_day * 1000; @@ -2102,6 +2104,16 @@ mod tests { } } + #[test] + fn test_addition_on_ref() { + // This test case also tests the case where there is no submillis precision but subsecond + // milliseconds. + let provider_ref = &TimeProvider::new_with_u16_days(2, 500); + let new_stamp = provider_ref + Duration::from_millis(2 * 24 * 60 * 60 * 1000 + 500); + assert_eq!(new_stamp.ccsds_days_as_u32(), 4); + assert_eq!(new_stamp.ms_of_day, 1000); + } + fn check_ps_and_carryover(prec: SubmillisPrecision, ms_of_day: u32, val: u32) { if let SubmillisPrecision::Picoseconds(ps) = prec { assert_eq!(ps, val);