Skip to content

Commit e00555c

Browse files
committed
src/lib: Add end-to-end timezone test
Also make the offset test a little bit smarter.
1 parent cc7c143 commit e00555c

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

src/lib.rs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,7 @@ mod tests {
212212

213213
#[cfg(test)]
214214
mod offsets {
215+
use chrono::FixedOffset;
215216
use chrono::{Local, NaiveDate};
216217

217218
use crate::parse_datetime;
@@ -258,12 +259,25 @@ mod tests {
258259

259260
#[test]
260261
fn test_datetime_with_offset() {
261-
let actual = parse_datetime("1997-01-19 08:17:48 +0").unwrap();
262+
let actual = parse_datetime("1997-01-19 08:17:48 +2").unwrap();
262263
let expected = NaiveDate::from_ymd_opt(1997, 1, 19)
263264
.unwrap()
264265
.and_hms_opt(8, 17, 48)
265266
.unwrap()
266-
.and_utc();
267+
.and_local_timezone(FixedOffset::east_opt(2 * 3600).unwrap())
268+
.unwrap();
269+
assert_eq!(actual, expected);
270+
}
271+
272+
#[test]
273+
fn test_datetime_with_timezone() {
274+
let actual = parse_datetime("1997-01-19 08:17:48 BRT").unwrap();
275+
let expected = NaiveDate::from_ymd_opt(1997, 1, 19)
276+
.unwrap()
277+
.and_hms_opt(8, 17, 48)
278+
.unwrap()
279+
.and_local_timezone(FixedOffset::west_opt(3 * 3600).unwrap())
280+
.unwrap();
267281
assert_eq!(actual, expected);
268282
}
269283
}

0 commit comments

Comments
 (0)