Skip to content

Commit 5656a9e

Browse files
joroKr21pitdicker
authored andcommitted
Add a test for duration_round close to min / max
1 parent 8eb92d9 commit 5656a9e

File tree

1 file changed

+21
-4
lines changed

1 file changed

+21
-4
lines changed

src/round.rs

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -758,23 +758,40 @@ mod tests {
758758

759759
#[test]
760760
fn test_duration_trunc_close_to_epoch() {
761-
let dt = NaiveDate::from_ymd_opt(1970, 1, 1).unwrap().and_hms_opt(0, 0, 15).unwrap();
762761
let span = TimeDelta::minutes(15);
762+
763+
let dt = NaiveDate::from_ymd_opt(1970, 1, 1).unwrap().and_hms_opt(0, 0, 15).unwrap();
763764
assert_eq!(dt.duration_trunc(span).unwrap().to_string(), "1970-01-01 00:00:00");
764765

765766
let dt = NaiveDate::from_ymd_opt(1969, 12, 31).unwrap().and_hms_opt(23, 59, 45).unwrap();
766-
let span = TimeDelta::minutes(15);
767767
assert_eq!(dt.duration_trunc(span).unwrap().to_string(), "1969-12-31 23:45:00");
768768
}
769769

770770
#[test]
771771
fn test_duration_round_close_to_epoch() {
772-
let dt = NaiveDate::from_ymd_opt(1970, 1, 1).unwrap().and_hms_opt(0, 0, 15).unwrap();
773772
let span = TimeDelta::minutes(15);
773+
774+
let dt = NaiveDate::from_ymd_opt(1970, 1, 1).unwrap().and_hms_opt(0, 0, 15).unwrap();
774775
assert_eq!(dt.duration_round(span).unwrap().to_string(), "1970-01-01 00:00:00");
775776

776777
let dt = NaiveDate::from_ymd_opt(1969, 12, 31).unwrap().and_hms_opt(23, 59, 45).unwrap();
777-
let span = TimeDelta::minutes(15);
778+
assert_eq!(dt.duration_round(span).unwrap().to_string(), "1970-01-01 00:00:00");
779+
}
780+
781+
#[test]
782+
fn test_duration_round_close_to_min_max() {
783+
let span = TimeDelta::nanoseconds(i64::MAX);
784+
785+
let dt = NaiveDateTime::from_timestamp_nanos(i64::MIN / 2 - 1).unwrap();
786+
assert_eq!(dt.duration_round(span).unwrap().to_string(), "1677-09-21 00:12:43.145224193");
787+
788+
let dt = NaiveDateTime::from_timestamp_nanos(i64::MIN / 2 + 1).unwrap();
789+
assert_eq!(dt.duration_round(span).unwrap().to_string(), "1970-01-01 00:00:00");
790+
791+
let dt = NaiveDateTime::from_timestamp_nanos(i64::MAX / 2 + 1).unwrap();
792+
assert_eq!(dt.duration_round(span).unwrap().to_string(), "2262-04-11 23:47:16.854775807");
793+
794+
let dt = NaiveDateTime::from_timestamp_nanos(i64::MAX / 2 - 1).unwrap();
778795
assert_eq!(dt.duration_round(span).unwrap().to_string(), "1970-01-01 00:00:00");
779796
}
780797
}

0 commit comments

Comments
 (0)