Skip to content

Commit

Permalink
add tests for #61
Browse files Browse the repository at this point in the history
  • Loading branch information
davidhewitt committed Jun 25, 2024
1 parent 9bbeebb commit 6a79b44
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion tests/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ fn date_comparison() {
}

#[test]
fn date_timestamp() {
fn date_timestamp_exact() {
let d = Date::from_timestamp(1_654_560_000, true).unwrap();
assert_eq!(d.to_string(), "2022-06-07");
assert_eq!(d.timestamp(), 1_654_560_000);
Expand All @@ -239,6 +239,16 @@ fn date_timestamp() {
Ok(d) => panic!("unexpectedly valid, {d}"),
Err(e) => assert_eq!(e, ParseError::DateNotExact),
}

// milliseconds
let d = Date::from_timestamp(1_654_560_000_000, true).unwrap();
assert_eq!(d.to_string(), "2022-06-07");
assert_eq!(d.timestamp(), 1_654_560_000);

match Date::from_timestamp(1_654_560_000_001, true) {
Ok(d) => panic!("unexpectedly valid, {d}"),
Err(e) => assert_eq!(e, ParseError::DateNotExact),
}
}

macro_rules! date_from_timestamp {
Expand Down Expand Up @@ -854,6 +864,9 @@ param_tests! {
dt_unix1: ok => "1654646400", "2022-06-08T00:00:00";
dt_unix2: ok => "1654646404", "2022-06-08T00:00:04";
dt_unix_float: ok => "1654646404.5", "2022-06-08T00:00:04.500000";
dt_unix_float_limit: ok => "1654646404.123456", "2022-06-08T00:00:04.123456";
dt_unix_float_ms: ok => "1654646404000.5", "2022-06-08T00:00:04.000500";
dt_unix_float_ms_limit: ok => "1654646404123.456", "2022-06-08T00:00:04.123456";
dt_short_date: err => "xxx", TooShort;
dt_short_time: err => "2020-01-01T12:0", TooShort;
dt: err => "202x-01-01", InvalidCharYear;
Expand Down

0 comments on commit 6a79b44

Please sign in to comment.