Skip to content

Commit e654d11

Browse files
authored
Implement Intl.DateTimeFormat (#4378)
<!--- Thank you for contributing to Boa! Please fill out the template below, and remove or add any information as you feel necessary. ---> Closes #4438 This pull request aims to implement `Intl.DateTimeFormat`. Posting as a draft early as I lost my initial work when my laptop died a few weeks back 🙃 So better safe then sorry currently. There's still plenty of work to be done, but feel free to take a look early 😄
1 parent 290974a commit e654d11

File tree

14 files changed

+1450
-323
lines changed

14 files changed

+1450
-323
lines changed

Cargo.lock

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ icu_provider = { version = "~2.1.1", default-features = false }
146146
icu_locale = { version = "~2.1.1", default-features = false }
147147
icu_locale_core = { version = "~2.1.1", default-features = false }
148148
icu_datetime = { version = "~2.1.1", default-features = false }
149+
icu_time = { version = "~2.1.1", default-features = false }
149150
icu_calendar = { version = "~2.1.1", default-features = false }
150151
icu_collator = { version = "~2.1.1", default-features = false }
151152
icu_plurals = { version = "~2.1.1", default-features = false }

core/engine/Cargo.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ intl = [
4040
"icu_normalizer/serde",
4141
"dep:icu_locale",
4242
"dep:icu_datetime",
43+
"dep:icu_time",
4344
"dep:icu_plurals",
4445
"dep:icu_provider",
4546
"dep:icu_calendar",
@@ -54,6 +55,8 @@ intl = [
5455
"dep:zerofrom",
5556
"dep:fixed_decimal",
5657
"dep:tinystr",
58+
"dep:timezone_provider",
59+
"timezone_provider/tzif",
5760
]
5861

5962
fuzz = ["boa_ast/arbitrary", "boa_interner/arbitrary"]
@@ -144,6 +147,9 @@ icu_locale = { workspace = true, default-features = false, features = [
144147
icu_datetime = { workspace = true, default-features = false, features = [
145148
"serde",
146149
], optional = true }
150+
icu_time = { workspace = true, default-features = false, features = [
151+
"serde",
152+
], optional = true }
147153
icu_calendar = { workspace = true, default-features = false, optional = true }
148154
icu_collator = { workspace = true, default-features = false, features = [
149155
"serde",

core/engine/src/builtins/date/utils.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ fn time_from_year(y: f64) -> f64 {
130130
/// - [ECMAScript reference][spec]
131131
///
132132
/// [spec]: https://tc39.es/ecma262/#sec-yearfromtime
133-
pub(super) fn year_from_time(t: f64) -> i32 {
133+
pub(crate) fn year_from_time(t: f64) -> i32 {
134134
const MS_PER_AVERAGE_YEAR: f64 = 12.0 * 30.436_875 * MS_PER_DAY;
135135

136136
// 1. Return the largest integral Number y (closest to +∞) such that TimeFromYear(y) ≤ t.
@@ -169,7 +169,7 @@ fn in_leap_year(t: f64) -> u16 {
169169
/// - [ECMAScript reference][spec]
170170
///
171171
/// [spec]: https://tc39.es/ecma262/#sec-monthfromtime
172-
pub(super) fn month_from_time(t: f64) -> u8 {
172+
pub(crate) fn month_from_time(t: f64) -> u8 {
173173
// 1. Let inLeapYear be InLeapYear(t).
174174
let in_leap_year = in_leap_year(t);
175175

@@ -211,7 +211,7 @@ pub(super) fn month_from_time(t: f64) -> u8 {
211211
/// - [ECMAScript reference][spec]
212212
///
213213
/// [spec]: https://tc39.es/ecma262/#sec-datefromtime
214-
pub(super) fn date_from_time(t: f64) -> u8 {
214+
pub(crate) fn date_from_time(t: f64) -> u8 {
215215
// 1. Let inLeapYear be InLeapYear(t).
216216
let in_leap_year = in_leap_year(t);
217217

@@ -268,7 +268,7 @@ pub(super) fn week_day(t: f64) -> u8 {
268268
/// - [ECMAScript reference][spec]
269269
///
270270
/// [spec]: https://tc39.es/ecma262/#sec-hourfromtime
271-
pub(super) fn hour_from_time(t: f64) -> u8 {
271+
pub(crate) fn hour_from_time(t: f64) -> u8 {
272272
// 1. Return 𝔽(floor(ℝ(t / msPerHour)) modulo HoursPerDay).
273273
((t / MS_PER_HOUR).floor()).rem_euclid(HOURS_PER_DAY) as u8
274274
}
@@ -279,7 +279,7 @@ pub(super) fn hour_from_time(t: f64) -> u8 {
279279
/// - [ECMAScript reference][spec]
280280
///
281281
/// [spec]: https://tc39.es/ecma262/#sec-minfromtime
282-
pub(super) fn min_from_time(t: f64) -> u8 {
282+
pub(crate) fn min_from_time(t: f64) -> u8 {
283283
// 1. Return 𝔽(floor(ℝ(t / msPerMinute)) modulo MinutesPerHour).
284284
((t / MS_PER_MINUTE).floor()).rem_euclid(MINUTES_PER_HOUR) as u8
285285
}
@@ -290,7 +290,7 @@ pub(super) fn min_from_time(t: f64) -> u8 {
290290
/// - [ECMAScript reference][spec]
291291
///
292292
/// [spec]: https://tc39.es/ecma262/#sec-secfromtime
293-
pub(super) fn sec_from_time(t: f64) -> u8 {
293+
pub(crate) fn sec_from_time(t: f64) -> u8 {
294294
// 1. Return 𝔽(floor(ℝ(t / msPerSecond)) modulo SecondsPerMinute).
295295
((t / MS_PER_SECOND).floor()).rem_euclid(SECONDS_PER_MINUTE) as u8
296296
}
@@ -301,7 +301,7 @@ pub(super) fn sec_from_time(t: f64) -> u8 {
301301
/// - [ECMAScript reference][spec]
302302
///
303303
/// [spec]: https://tc39.es/ecma262/#sec-msfromtime
304-
pub(super) fn ms_from_time(t: f64) -> u16 {
304+
pub(crate) fn ms_from_time(t: f64) -> u16 {
305305
// 1. Return 𝔽(ℝ(t) modulo ℝ(msPerSecond)).
306306
t.rem_euclid(MS_PER_SECOND) as u16
307307
}

0 commit comments

Comments
 (0)