From e00555cd967aba0e84500bb3425e37b406534f7c Mon Sep 17 00:00:00 2001 From: Nicolas Boichat Date: Sun, 25 May 2025 20:51:30 +0200 Subject: [PATCH] src/lib: Add end-to-end timezone test Also make the offset test a little bit smarter. --- src/lib.rs | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 9462a75..8674238 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -212,6 +212,7 @@ mod tests { #[cfg(test)] mod offsets { + use chrono::FixedOffset; use chrono::{Local, NaiveDate}; use crate::parse_datetime; @@ -258,12 +259,25 @@ mod tests { #[test] fn test_datetime_with_offset() { - let actual = parse_datetime("1997-01-19 08:17:48 +0").unwrap(); + let actual = parse_datetime("1997-01-19 08:17:48 +2").unwrap(); let expected = NaiveDate::from_ymd_opt(1997, 1, 19) .unwrap() .and_hms_opt(8, 17, 48) .unwrap() - .and_utc(); + .and_local_timezone(FixedOffset::east_opt(2 * 3600).unwrap()) + .unwrap(); + assert_eq!(actual, expected); + } + + #[test] + fn test_datetime_with_timezone() { + let actual = parse_datetime("1997-01-19 08:17:48 BRT").unwrap(); + let expected = NaiveDate::from_ymd_opt(1997, 1, 19) + .unwrap() + .and_hms_opt(8, 17, 48) + .unwrap() + .and_local_timezone(FixedOffset::west_opt(3 * 3600).unwrap()) + .unwrap(); assert_eq!(actual, expected); } }