diff options
Diffstat (limited to 'rust/schist_models')
| -rw-r--r-- | rust/schist_models/src/date_utc.rs | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/rust/schist_models/src/date_utc.rs b/rust/schist_models/src/date_utc.rs index c801585..d3a1d2e 100644 --- a/rust/schist_models/src/date_utc.rs +++ b/rust/schist_models/src/date_utc.rs @@ -69,6 +69,15 @@ impl DateUtc { Ok(Self { chrono_datetime_utc }) } + pub fn sub_days(&self, days: u64) -> Result<Self> { + let chrono_datetime_utc = self + .chrono_datetime_utc + .checked_sub_days(chrono::Days::new(days)) + .with_context(|| format!("failed to subtract {} days from {}", days, self)) + .unwrap(); + Ok(Self { chrono_datetime_utc }) + } + fn is_day_str(str: &str) -> bool { if str.len() != 10 { return false; @@ -151,9 +160,14 @@ impl Dateable for DateUtc { impl From<DatetimeUtc> for DateUtc { fn from(datetime_utc: DatetimeUtc) -> Self { + Self::from(&datetime_utc) + } +} + +impl From<&DatetimeUtc> for DateUtc { + fn from(datetime_utc: &DatetimeUtc) -> Self { Self { chrono_datetime_utc: datetime_utc - .borrow() .to_string() .parse::<DateTime<Utc>>().unwrap() .with_time(NaiveTime::from_hms_opt(0, 0, 0).unwrap()).unwrap(), |
