From f823da1a73fd0b4e0c4c7e35621744fc3d751a18 Mon Sep 17 00:00:00 2001 From: Manish Goregaokar Date: Wed, 6 Dec 2023 11:04:59 -0800 Subject: [PATCH] better debug for RD --- utils/calendrical_calculations/src/rata_die.rs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/utils/calendrical_calculations/src/rata_die.rs b/utils/calendrical_calculations/src/rata_die.rs index 2f598edb1dc..1d9db11acb6 100644 --- a/utils/calendrical_calculations/src/rata_die.rs +++ b/utils/calendrical_calculations/src/rata_die.rs @@ -8,6 +8,7 @@ // package root or at http://www.apache.org/licenses/LICENSE-2.0. use core::ops::{Add, AddAssign, Sub, SubAssign}; +use core::fmt; #[allow(unused_imports)] use core_maths::*; @@ -17,7 +18,7 @@ use core_maths::*; /// /// It is a logic error to construct a RataDie /// except from a date that is in range of one of the official calendars. -#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord)] +#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord)] pub struct RataDie(i64); impl RataDie { @@ -75,6 +76,18 @@ impl RataDie { } } +impl fmt::Debug for RataDie { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + + let rd = self.0; + if let Ok((y, m, d)) = crate::iso::iso_from_fixed(*self) { + write!(f, "{rd} R.D. ({y}-{m:02}-{d:02})") + } else { + write!(f, "{rd} R.D. (out of bounds)") + } + } +} + /// Shift a RataDie N days into the future impl Add for RataDie { type Output = Self;