Skip to content

Commit

Permalink
Add test
Browse files Browse the repository at this point in the history
  • Loading branch information
pitdicker committed Jun 1, 2023
1 parent 8145aca commit 9f18129
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/datetime/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,20 @@ fn test_datetime_offset() {
assert!(*edt.with_ymd_and_hms(2014, 5, 6, 7, 8, 9).unwrap().offset() != est);
}

#[test]
fn signed_duration_since_autoref() {
let dt1 = Utc.with_ymd_and_hms(2014, 5, 6, 7, 8, 9).unwrap();
let dt2 = Utc.with_ymd_and_hms(2014, 3, 4, 5, 6, 7).unwrap();
let diff1 = dt1.signed_duration_since(dt2);
// dt2 would no longer be available if `signed_duration_since` didn't use `Borrow`
let diff2 = dt2.signed_duration_since(dt1);
assert_eq!(diff1, -diff2);

let diff1 = dt1 - &dt2; // We can choose to substract rhs by reference
let diff2 = dt2 - dt1; // Or consume rhs
assert_eq!(diff1, -diff2);
}

#[test]
fn test_datetime_date_and_time() {
let tz = FixedOffset::east_opt(5 * 60 * 60).unwrap();
Expand Down

0 comments on commit 9f18129

Please sign in to comment.