Skip to content

Commit 6f073ad

Browse files
authored
Merge pull request #146 from drinkcat/fix-tests
Fix/improve tests
2 parents cc7c143 + a967662 commit 6f073ad

File tree

2 files changed

+22
-8
lines changed

2 files changed

+22
-8
lines changed

src/items/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -518,7 +518,7 @@ mod tests {
518518
// https://github.com/uutils/coreutils/issues/5177
519519
assert_eq!(
520520
"2023-07-27T13:53:54+00:00",
521-
test_eq_fmt("%+", "@1690466034")
521+
test_eq_fmt("%Y-%m-%dT%H:%M:%S%:z", "@1690466034")
522522
);
523523

524524
// https://github.com/uutils/coreutils/issues/6398
@@ -527,12 +527,12 @@ mod tests {
527527

528528
assert_eq!(
529529
"2024-07-17 06:14:49 +00:00",
530-
test_eq_fmt("%Y-%m-%d %H:%M:%S %Z", "Jul 17 06:14:49 2024 GMT"),
530+
test_eq_fmt("%Y-%m-%d %H:%M:%S %:z", "Jul 17 06:14:49 2024 GMT"),
531531
);
532532

533533
assert_eq!(
534534
"2024-07-17 06:14:49 -03:00",
535-
test_eq_fmt("%Y-%m-%d %H:%M:%S %Z", "Jul 17 06:14:49 2024 BRT"),
535+
test_eq_fmt("%Y-%m-%d %H:%M:%S %:z", "Jul 17 06:14:49 2024 BRT"),
536536
);
537537
}
538538
}

src/lib.rs

Lines changed: 19 additions & 5 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
}
@@ -652,7 +666,7 @@ mod tests {
652666
assert_eq!(
653667
parse_datetime("28 feb 2023 + 1 day")
654668
.unwrap()
655-
.format("%+")
669+
.format("%Y-%m-%dT%H:%M:%S%:z")
656670
.to_string(),
657671
"2023-03-01T00:00:00+00:00"
658672
);
@@ -664,15 +678,15 @@ mod tests {
664678
assert_eq!(
665679
parse_datetime("2024-01-31 + 1 month")
666680
.unwrap()
667-
.format("%+")
681+
.format("%Y-%m-%dT%H:%M:%S%:z")
668682
.to_string(),
669683
"2024-03-02T00:00:00+00:00",
670684
);
671685

672686
assert_eq!(
673687
parse_datetime("2024-02-29 + 1 month")
674688
.unwrap()
675-
.format("%+")
689+
.format("%Y-%m-%dT%H:%M:%S%:z")
676690
.to_string(),
677691
"2024-03-29T00:00:00+00:00",
678692
);

0 commit comments

Comments
 (0)