From cd269b3540fb5e3a988c1b59d3763db360b1fb34 Mon Sep 17 00:00:00 2001 From: Joe Carstairs Date: Tue, 17 Sep 2024 13:20:04 +0100 Subject: many, many changes --- backend/src/models/date_time_utc.rs | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) (limited to 'backend/src/models/date_time_utc.rs') diff --git a/backend/src/models/date_time_utc.rs b/backend/src/models/date_time_utc.rs index 6c5dc33..03d5802 100644 --- a/backend/src/models/date_time_utc.rs +++ b/backend/src/models/date_time_utc.rs @@ -32,6 +32,14 @@ impl DateTimeUtc { .abs_diff(other.0.num_days_from_ce()) } + pub fn to_day_str(&self) -> String { + self.0 + .to_rfc3339() + .split_at_checked(10) + .map(|(day_str, _)| String::from(day_str)) + .unwrap_or_else(|| String::from("")) + } + pub fn new(date_time_utc: DateTime) -> Self { Self(date_time_utc) } @@ -46,7 +54,7 @@ impl ToSql for DateTimeUtc { &'b self, out: &mut diesel::serialize::Output<'b, '_, Sqlite>, ) -> serialize::Result { - out.set_value(self.0.to_rfc3339()); + out.set_value(self.to_day_str()); Ok(diesel::serialize::IsNull::No) } } @@ -108,4 +116,16 @@ mod test { assert_eq!(day_diff, 1); assert_eq!(day_diff, neg_day_diff); } + + #[test] + fn given_23_nov_1970_when_to_day_str_then_return_iso_day_str() { + let date_time_utc = DateTimeUtc::new( + Utc.with_ymd_and_hms(1970, 11, 23, 0, 0, 0) + .unwrap() + .to_utc(), + ); + let day_str = date_time_utc.to_day_str(); + + assert_eq!(day_str, "1970-11-23"); + } } -- cgit v1.2.3