diff --git a/src/time/cds.rs b/src/time/cds.rs index fdf08fd..73b11c5 100644 --- a/src/time/cds.rs +++ b/src/time/cds.rs @@ -1038,6 +1038,20 @@ impl Add for TimeProvider { } } +impl Add for &TimeProvider { + type Output = TimeProvider; + + fn add(self, duration: Duration) -> Self::Output { + let (next_ccsds_days, next_ms_of_day, precision) = + add_for_max_ccsds_days_val(self, u16::MAX as u32, duration); + let mut provider = Self::Output::new_with_u16_days(next_ccsds_days as u16, next_ms_of_day); + if let Some(prec) = precision { + provider.set_submillis_precision(prec); + } + provider + } +} + /// Allows adding an duration in form of an offset. Please note that the CCSDS days will rollover /// when they overflow, because addition needs to be infallible. The user needs to check for a /// days overflow when this is a possibility and might be a problem. @@ -1055,6 +1069,20 @@ impl Add for TimeProvider { } } +impl Add for &TimeProvider { + type Output = TimeProvider; + fn add(self, duration: Duration) -> Self::Output { + let (next_ccsds_days, next_ms_of_day, precision) = + add_for_max_ccsds_days_val(self, MAX_DAYS_24_BITS, duration); + let mut provider = + Self::Output::new_with_u24_days(next_ccsds_days, next_ms_of_day).unwrap(); + if let Some(prec) = precision { + provider.set_submillis_precision(prec); + } + provider + } +} + /// Allows adding an duration in form of an offset. Please note that the CCSDS days will rollover /// when they overflow, because addition needs to be infallible. The user needs to check for a /// days overflow when this is a possibility and might be a problem. diff --git a/src/time/cuc.rs b/src/time/cuc.rs index 946b6ef..799769c 100644 --- a/src/time/cuc.rs +++ b/src/time/cuc.rs @@ -696,6 +696,20 @@ impl Add for TimeProviderCcsdsEpoch { } } +impl Add for &TimeProviderCcsdsEpoch { + type Output = TimeProviderCcsdsEpoch; + + fn add(self, duration: Duration) -> Self::Output { + let (new_counter, new_fractional_part) = + get_provider_values_after_duration_addition(self, duration); + if let Some(fractional_part) = new_fractional_part { + // The generated fractional part should always be valid, so its okay to unwrap here. + return Self::Output::new_with_fractions(new_counter, fractional_part).unwrap(); + } + Self::Output::new(new_counter) + } +} + #[cfg(test)] mod tests { use super::*;