mirror of
https://github.com/uutils/parse_datetime.git
synced 2026-06-10 16:13:15 -07:00
src/lib: Add end-to-end timezone test
Also make the offset test a little bit smarter.
This commit is contained in:
+16
-2
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user