Skip to content

Commit 9780fdf

Browse files
ManishearthChromium LUCI CQ
authored andcommitted
[temporal] Uplift float64-representable integer patch
Uplifts boa-dev/temporal#621 Bug: 401065166 Change-Id: Iad750a4e3c93dd65c7b2b10ab7e3789f5cc877de Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/7142574 Commit-Queue: Manish Goregaokar <manishearth@google.com> Reviewed-by: Łukasz Anforowicz <lukasza@chromium.org> Cr-Commit-Position: refs/heads/main@{#1543294}
1 parent 8fadad8 commit 9780fdf

3 files changed

Lines changed: 133 additions & 16 deletions

File tree

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
From c5132c3281040b4c7b91a53701d2925ca0c89169 Mon Sep 17 00:00:00 2001
2+
From: Manish Goregaokar <manishearth@google.com>
3+
Date: Tue, 11 Nov 2025 17:06:35 +0000
4+
Subject: [PATCH] [temporal] Uplift float64-representable integer patch
5+
6+
Uplifts https://github.com/boa-dev/temporal/pull/621
7+
8+
Change-Id: Iad750a4e3c93dd65c7b2b10ab7e3789f5cc877de
9+
---
10+
.../vendor/temporal_rs-v0_1/Cargo.toml.orig | 190 +++++++++---------
11+
.../src/builtins/core/duration.rs | 10 +-
12+
.../src/builtins/core/duration/tests.rs | 43 ++--
13+
3 files changed, 136 insertions(+), 107 deletions(-)
14+
15+
diff --git a/third_party/rust/chromium_crates_io/vendor/temporal_rs-v0_1/src/builtins/core/duration.rs b/third_party/rust/chromium_crates_io/vendor/temporal_rs-v0_1/src/builtins/core/duration.rs
16+
index f687cee32795b..59682fccb7be9 100644
17+
--- a/third_party/rust/chromium_crates_io/vendor/temporal_rs-v0_1/src/builtins/core/duration.rs
18+
+++ b/third_party/rust/chromium_crates_io/vendor/temporal_rs-v0_1/src/builtins/core/duration.rs
19+
@@ -389,9 +389,13 @@ impl Duration {
20+
hours,
21+
minutes,
22+
seconds,
23+
- milliseconds,
24+
- microseconds,
25+
- nanoseconds,
26+
+
27+
+ // https://github.com/boa-dev/temporal/issues/613
28+
+ // With float64_representable_durations enabled, force all smaller units
29+
+ // to be in the float64-representable range.
30+
+ milliseconds: milliseconds as f64 as u64,
31+
+ microseconds: microseconds as f64 as u128,
32+
+ nanoseconds: nanoseconds as f64 as u128,
33+
}
34+
}
35+
36+
diff --git a/third_party/rust/chromium_crates_io/vendor/temporal_rs-v0_1/src/builtins/core/duration/tests.rs b/third_party/rust/chromium_crates_io/vendor/temporal_rs-v0_1/src/builtins/core/duration/tests.rs
37+
index 5eae2888ba21f..688968433ffc6 100644
38+
--- a/third_party/rust/chromium_crates_io/vendor/temporal_rs-v0_1/src/builtins/core/duration/tests.rs
39+
+++ b/third_party/rust/chromium_crates_io/vendor/temporal_rs-v0_1/src/builtins/core/duration/tests.rs
40+
@@ -404,23 +404,40 @@ fn test_duration_compare() {
41+
)
42+
}
43+
}
44+
-/*
45+
-TODO: Uncomment
46+
47+
-The below test should fail, but currently doesn't. This has to do with weird
48+
-floating point math in IsValidDuration Step 6-8 that defers to C++ std::remquo
49+
-
50+
-Needs further clarification.
51+
+const MAX_SAFE_INT: i64 = 9_007_199_254_740_991;
52+
53+
#[test]
54+
fn duration_round_out_of_range_norm_conversion() {
55+
- const MAX_SAFE_INT: i64 = 9_007_199_254_740_991;
56+
let duration = Duration::new(0, 0, 0, 0, 0, 0, MAX_SAFE_INT, 0, 0, 999_999_999).unwrap();
57+
- let err = duration.round_with_provider( RoundingOptions {
58+
- largest_unit: Some(Unit::Nanosecond),
59+
- increment: Some(RoundingIncrement::ONE),
60+
- ..Default::default()
61+
- }, None, &NeverProvider::default());
62+
+ let err = duration.round_with_provider(
63+
+ RoundingOptions {
64+
+ largest_unit: Some(Unit::Nanosecond),
65+
+ increment: Some(RoundingIncrement::ONE),
66+
+ ..Default::default()
67+
+ },
68+
+ None,
69+
+ &NeverProvider::default(),
70+
+ );
71+
assert!(err.is_err())
72+
}
73+
-*/
74+
+
75+
+#[test]
76+
+#[cfg_attr(not(feature = "float64_representable_durations"), should_panic)]
77+
+fn duration_float64_representable() {
78+
+ // built-ins/Temporal/Duration/prototype/add/float64-representable-integer
79+
+ let duration = Duration::new(0, 0, 0, 0, 0, 0, 0, 0, MAX_SAFE_INT as i128, 0).unwrap();
80+
+ let duration2 = Duration::new(0, 0, 0, 0, 0, 0, 0, 0, MAX_SAFE_INT as i128 - 1, 0).unwrap();
81+
+ let added = duration.add(&duration2).unwrap();
82+
+ assert_eq!(added.microseconds, 18014398509481980);
83+
+ assert_eq!(
84+
+ added.as_temporal_string(Default::default()).unwrap(),
85+
+ "PT18014398509.48198S"
86+
+ );
87+
+ let one_ms = Duration::new(0, 0, 0, 0, 0, 0, 0, 0, 1, 0).unwrap();
88+
+ let added_plus_one = added.add(&one_ms).unwrap();
89+
+ assert_eq!(
90+
+ added, added_plus_one,
91+
+ "Should not internally use a more accurate representation when adding"
92+
+ );
93+
+}
94+
--
95+
2.51.2.1041.gc1ab5b90ca-goog
96+

third_party/rust/chromium_crates_io/vendor/temporal_rs-v0_1/src/builtins/core/duration.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -389,9 +389,13 @@ impl Duration {
389389
hours,
390390
minutes,
391391
seconds,
392-
milliseconds,
393-
microseconds,
394-
nanoseconds,
392+
393+
// https://github.com/boa-dev/temporal/issues/613
394+
// With float64_representable_durations enabled, force all smaller units
395+
// to be in the float64-representable range.
396+
milliseconds: milliseconds as f64 as u64,
397+
microseconds: microseconds as f64 as u128,
398+
nanoseconds: nanoseconds as f64 as u128,
395399
}
396400
}
397401

third_party/rust/chromium_crates_io/vendor/temporal_rs-v0_1/src/builtins/core/duration/tests.rs

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -404,23 +404,40 @@ fn test_duration_compare() {
404404
)
405405
}
406406
}
407-
/*
408-
TODO: Uncomment
409407

410-
The below test should fail, but currently doesn't. This has to do with weird
411-
floating point math in IsValidDuration Step 6-8 that defers to C++ std::remquo
412-
413-
Needs further clarification.
408+
const MAX_SAFE_INT: i64 = 9_007_199_254_740_991;
414409

415410
#[test]
416411
fn duration_round_out_of_range_norm_conversion() {
417-
const MAX_SAFE_INT: i64 = 9_007_199_254_740_991;
418412
let duration = Duration::new(0, 0, 0, 0, 0, 0, MAX_SAFE_INT, 0, 0, 999_999_999).unwrap();
419-
let err = duration.round_with_provider( RoundingOptions {
420-
largest_unit: Some(Unit::Nanosecond),
421-
increment: Some(RoundingIncrement::ONE),
422-
..Default::default()
423-
}, None, &NeverProvider::default());
413+
let err = duration.round_with_provider(
414+
RoundingOptions {
415+
largest_unit: Some(Unit::Nanosecond),
416+
increment: Some(RoundingIncrement::ONE),
417+
..Default::default()
418+
},
419+
None,
420+
&NeverProvider::default(),
421+
);
424422
assert!(err.is_err())
425423
}
426-
*/
424+
425+
#[test]
426+
#[cfg_attr(not(feature = "float64_representable_durations"), should_panic)]
427+
fn duration_float64_representable() {
428+
// built-ins/Temporal/Duration/prototype/add/float64-representable-integer
429+
let duration = Duration::new(0, 0, 0, 0, 0, 0, 0, 0, MAX_SAFE_INT as i128, 0).unwrap();
430+
let duration2 = Duration::new(0, 0, 0, 0, 0, 0, 0, 0, MAX_SAFE_INT as i128 - 1, 0).unwrap();
431+
let added = duration.add(&duration2).unwrap();
432+
assert_eq!(added.microseconds, 18014398509481980);
433+
assert_eq!(
434+
added.as_temporal_string(Default::default()).unwrap(),
435+
"PT18014398509.48198S"
436+
);
437+
let one_ms = Duration::new(0, 0, 0, 0, 0, 0, 0, 0, 1, 0).unwrap();
438+
let added_plus_one = added.add(&one_ms).unwrap();
439+
assert_eq!(
440+
added, added_plus_one,
441+
"Should not internally use a more accurate representation when adding"
442+
);
443+
}

0 commit comments

Comments
 (0)