src/lib: Add end-to-end timezone test

Also make the offset test a little bit smarter.
This commit is contained in:
Nicolas Boichat
2025-05-25 21:34:22 +02:00
parent cc7c143b21
commit e00555cd96
+16 -2
View File
@@ -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);
}
}