Skip to content

Commit

Permalink
better debug for RD
Browse files Browse the repository at this point in the history
  • Loading branch information
Manishearth committed Dec 6, 2023
1 parent f34cc67 commit f823da1
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion utils/calendrical_calculations/src/rata_die.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::*;

Expand All @@ -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 {
Expand Down Expand Up @@ -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<i64> for RataDie {
type Output = Self;
Expand Down

0 comments on commit f823da1

Please sign in to comment.