Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial implementation of Duration.prototype.total #241

Merged
merged 21 commits into from
Mar 12, 2025
Merged
Changes from 1 commit
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
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
Prev Previous commit
Next Next commit
remove now redundant dbg! macros from tests
lockels committed Mar 8, 2025
commit 7dd200ec24ac43c81a3ca97506b61df8e809a18c
40 changes: 19 additions & 21 deletions src/builtins/compiled/duration/tests.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::{dbg, string::ToString};
use std::string::ToString;

use crate::{
options::{
@@ -694,15 +694,14 @@ fn test_duration_total() {
..Default::default()
})
.unwrap();
let d1_actual = d1.total(TemporalUnit::Second, None).unwrap();
dbg!(d1_actual);
assert_eq!(d1_actual, 469200.0);
assert_eq!(d1.total(TemporalUnit::Second, None).unwrap(), 469200.0);

// How many 24-hour days is 123456789 seconds?
let d2 = Duration::from_str("PT123456789S").unwrap();
let d2_actual = d2.total(TemporalUnit::Day, None).unwrap();
dbg!(d2_actual);
assert_eq!(d2_actual, 1428.8980208333332);
assert_eq!(
d2.total(TemporalUnit::Day, None).unwrap(),
1428.8980208333332
);

// Find totals in months, with and without taking DST into account
let d3 = Duration::from_partial_duration(PartialDuration {
@@ -716,23 +715,22 @@ fn test_duration_total() {
OffsetDisambiguation::Reject,
)
.unwrap();
let d3_zoned_actual = d3
.total(
assert_eq!(
d3.total(
TemporalUnit::Month,
Some(RelativeTo::ZonedDateTime(relative_to)),
Some(RelativeTo::ZonedDateTime(relative_to))
)
.unwrap();
dbg!(d3_zoned_actual);
assert_eq!(d3_zoned_actual, 3.7958333333333334);

let d3_plain_actual = d3
.total(
.unwrap(),
3.7958333333333334
);
assert_eq!(
d3.total(
TemporalUnit::Month,
Some(RelativeTo::PlainDate(
PlainDate::new(2020, 1, 1, Calendar::default()).unwrap(),
)),
PlainDate::new(2020, 1, 1, Calendar::default()).unwrap()
))
)
.unwrap();
dbg!(d3_plain_actual);
assert_eq!(d3_plain_actual, 3.7944444444444443);
.unwrap(),
3.7944444444444443
);
}