Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/items/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,7 @@ mod tests {
// https://github.com/uutils/coreutils/issues/5177
assert_eq!(
"2023-07-27T13:53:54+00:00",
test_eq_fmt("%+", "@1690466034")
test_eq_fmt("%Y-%m-%dT%H:%M:%S%:z", "@1690466034")
);

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

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

assert_eq!(
"2024-07-17 06:14:49 -03:00",
test_eq_fmt("%Y-%m-%d %H:%M:%S %Z", "Jul 17 06:14:49 2024 BRT"),
test_eq_fmt("%Y-%m-%d %H:%M:%S %:z", "Jul 17 06:14:49 2024 BRT"),
);
}
}
24 changes: 19 additions & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ mod tests {

#[cfg(test)]
mod offsets {
use chrono::FixedOffset;
use chrono::{Local, NaiveDate};

use crate::parse_datetime;
Expand Down Expand Up @@ -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);
}
}
Expand Down Expand Up @@ -652,7 +666,7 @@ mod tests {
assert_eq!(
parse_datetime("28 feb 2023 + 1 day")
.unwrap()
.format("%+")
.format("%Y-%m-%dT%H:%M:%S%:z")
.to_string(),
"2023-03-01T00:00:00+00:00"
);
Expand All @@ -664,15 +678,15 @@ mod tests {
assert_eq!(
parse_datetime("2024-01-31 + 1 month")
.unwrap()
.format("%+")
.format("%Y-%m-%dT%H:%M:%S%:z")
.to_string(),
"2024-03-02T00:00:00+00:00",
);

assert_eq!(
parse_datetime("2024-02-29 + 1 month")
.unwrap()
.format("%+")
.format("%Y-%m-%dT%H:%M:%S%:z")
.to_string(),
"2024-03-29T00:00:00+00:00",
);
Expand Down
Loading