Commit graph

41 commits

Author SHA1 Message Date
Timothy Flynn
4b1ecbc9df LibJS+LibUnicode: Update icu4x's calendar module to 2.2.0
First: We now pin the icu4x version to an exact number. Minor version
upgrades can result in noisy deprecation warnings and API changes which
cause tests to fail. So let's pin the known-good version exactly.

This patch updates our Rust calendar module to use the new APIs. This
initially caused some test failures due to the new Date::try_new API
(which is the recommended replacement for Date::try_new_from_codes)
having quite a limited year range of +/-9999. So we must use other
APIs (Date::try_from_fields and calendrical_calculations::gregorian)
to avoid these limits.

http://github.com/unicode-org/icu4x/blob/main/CHANGELOG.md#icu4x-22
2026-04-14 18:12:31 -04:00
Timothy Flynn
d094de39fc LibJS: Format "islamic" and "islamic-rgsa" calendars as "islamic-tbla"
This was missed when implementing the Intl Era and Month Code proposal.
2026-03-13 14:43:45 -04:00
Timothy Flynn
101fee6cb2 LibJS+LibUnicode: Rename a LibUnicode FFI function for clarity
There will be an extremely similar function that accepts a calendar year
rather than ISO year in a subsequent commit. Rename the ISO year variant
so that they are more distinguishable.
2026-03-12 17:29:59 -05:00
Timothy Flynn
397be77866 LibJS+LibUnicode: Migrate MonthCode and its utilities to LibUnicode
Will be used in a Chinese/Dangi calendar implementation.
2026-03-12 17:29:59 -05:00
Timothy Flynn
86c8a57794 LibJS+LibUnicode: Use icu4x for Temporal calendar operations
Replace the icu4c-based calendar implementation with one built on the
icu4x Rust crate (icu_calendar).

The icu4c API does not expose the píngqì month-assignment algorithm
used by the Chinese and Dangi lunisolar calendars. Our old code had to
approximate this by walking months via epoch millisecond arithmetic and
manually tracking leap month positions, which produced incorrect month
codes and ordinal month numbers for certain years. The icu4x calendar
crate handles píngqì natively.

With this patch, which is almost a 1-to-1 mapping of ICU invocations, we
pass 100% of all Temporal test262 tests.

The end goal might be to use icu4x for all of our ICU needs. But it does
not yet provide the APIs needed for all ECMA-402 prototypes.
2026-03-11 07:09:57 -04:00
Timothy Flynn
b800c97ab8 LibJS+LibUnicode: Add support for non-ISO-8601 Temporal calendars
This adds international calendar support to our Temporal implementation,
using the Intl Era and Month Code Proposal as a guide. See:

https://tc39.es/proposal-intl-era-monthcode/
2026-03-09 11:40:59 +01:00
Timothy Flynn
b322d0fe84 LibJS: Add an infallible override of ParseMonthCode
This will be useful to avoid needing to pass around a VM in a bunch of
AOs in a future commit.
2026-03-09 11:40:59 +01:00
Timothy Flynn
2e74b91ca1 LibJS: Pass calendar strings around as String more regularly
Same as commit f9fa548d43.

These are String from the outset, so this patch is almost entirely just
changing function parameter types. This will allow us to cache calendar
objects in ICU without invoking any extra allocations.
2026-03-09 11:40:59 +01:00
Timothy Flynn
cadba4c0e7 LibJS: Make more use of Value::is and Value::as_if in Temporal 2026-02-27 17:19:33 +01:00
Timothy Flynn
206a18acd4 LibJS: Use single-line if/else steps in Temporal operations
This is an editorial change in the Temporal proposal. See:
978311d
2026-02-14 19:47:29 +01:00
Timothy Flynn
78ff593cc8 LibJS: Use "either" / "one of" when comparing multiple items in Temporal
This is an editorial change in the Temporal proposal. See:
5b02980
2026-02-14 19:47:29 +01:00
Timothy Flynn
d9ce90978c LibJS: Use = for Temporal mathematical value and BigInt comparisons
This is an editorial change in the Temporal proposal. See:
67ca9de
2026-02-14 19:47:29 +01:00
Timothy Flynn
f3f8311462 LibJS: Prefer "a new empty List" instead of "an empty List" in Temporal
This is an editorial change in the Temporal proposal. See:
c538d83
2026-02-14 19:47:29 +01:00
Timothy Flynn
e73b54532f LibJS: Refactor CalendarResolveFields parallel to NonISOResolveFields
This is an editorial change in the Temporal proposal. See:
b2e8299
2026-02-14 19:47:29 +01:00
Timothy Flynn
74048336df LibJS: Remove else clauses after early returns in Temporal operations
This is an editorial change in the Temporal proposal. See:
e6e031f
2026-02-14 19:47:29 +01:00
Timothy Flynn
3fb0e69c20 LibJS: Flip validity check to an assertion in CalendarMonthDayFromFields
This is an editorial change in the Temporal proposal. See:
163d589
2026-01-16 14:31:31 +01:00
Timothy Flynn
076bbd4c33 LibJS: Hoist early return in CalendarDateUntil to the top
This is an editorial change in the Temporal proposal. See:
264e4b8
2026-01-16 14:31:31 +01:00
Timothy Flynn
3eabdcf460 LibJS: Replace Temporal's BalanceISODate with AddDaysToISODate
This is an editorial change in the Temporal proposal. See:
b28ef08
2026-01-13 13:02:22 -05:00
Timothy Flynn
5c0fdd371a LibJS: Mark invocation to ParseMonthCode as infallible
This is an editorial change in the Temporal proposal. See:
c1f7bd5

Note the related assertion here was a bit silly. It was effectively:

    if (!cond) { return; }
    VERIFY(cond);
2025-11-12 16:20:04 -05:00
Timothy Flynn
041c4f4c79 LibJS: Remove unnecessary Temporal month code check
This is an editorial change in the Temporal proposal. See:
9110854

This change actually exposed a bug in our validator for month codes
(which is only used by this same function). We would previously allow
"M00" as a month code, which is invalid (it must be "M00L").
2025-11-12 16:20:04 -05:00
Timothy Flynn
aff642053a LibJS: Set day field in CalendarYearMonthFromFields before resolution
This is an editorial change in the Temporal proposal. See:
a8d38c6
2025-11-06 13:47:11 -05:00
Timothy Flynn
e314ca5e9d LibJS: Introduce ParseMonthCode and CreateMonthCode Temporal AOs
This is an editorial change in the Temporal proposal. See:
28357ea
32f4b02
f860ac6
e6f565d
2025-08-14 11:35:28 -04:00
Timothy Flynn
3920194bca LibJS: Move regulating and balancing logic into ISODateSurpasses
This is an editorial change in the Temporal proposal. See:
eddb77f
2025-08-05 11:18:08 -04:00
Timothy Flynn
a95d3e2a5e LibJS: Split ISO and non-ISO Temporal calendar operations
This is an editorial change in the Temporal proposal. See:
47042f2
2025-08-05 11:18:08 -04:00
Timothy Flynn
0efa98a57a LibJS+LibWeb+WebContent: Port JS::PropertyKey to UTF-16
This has quite a lot of fall out. But the majority of it is just type or
UDL substitution, where the changes just fall through to other function
calls.

By changing property key storage to UTF-16, the main affected areas are:
* NativeFunction names must now be UTF-16
* Bytecode identifiers must now be UTF-16
* Module/binding names must now be UTF-16
2025-08-05 07:07:15 -04:00
Timothy Flynn
fe4995b69a LibJS: Replace invalid reference to an [[Offset]] internal slot
This is an editorial change in the Temporal proposal. See:
f1569ef

Here, we also update the struct member name to match the correct slot
name.
2024-12-05 15:29:08 -05:00
Timothy Flynn
ade510fe17 LibJS: Pass ISO types by value vs. const-reference more correctly
We were passing types like ISODate by reference so that they could be
used as forward-declarations. But after commit 021a5f4ded, we now have
their full definitions anywhere they're needed. So let's pass ISODate by
value everywhere consistently - it is only 8 bytes.
2024-11-26 11:35:15 -05:00
Timothy Flynn
8c73cae2b8 LibJS: Implement the Temporal.ZonedDateTime constructor
And the simple Temporal.ZonedDateTime.prototype getters, so that the
constructed Temporal.ZonedDateTime may actually be validated.
2024-11-26 11:00:56 +01:00
Timothy Flynn
8ab765a3eb LibJS: Invoke CalendarDateToISO recursively correctly
Copy-paste mistake that becomes apparent in Temporal.ZonedDateTime
tests.
2024-11-26 11:00:56 +01:00
Timothy Flynn
029b6ad1a8 LibJS: Implement the Temporal.PlainDateTime constructor
And the simple Temporal.PlainDateTime.prototype getters, so that the
constructed Temporal.PlainDateTime may actually be validated.
2024-11-24 11:43:59 +01:00
Timothy Flynn
c83a3db542 LibJS: Handle Temporal.PlainDate in dynamic calendar operations 2024-11-23 19:35:36 -05:00
Timothy Flynn
521638642f LibJS: Capture CalendarFields by reference in Calendar*FromFields AOs
These fields are modified by an invocation to CalendarResolveFields. All
callers currently don't care about these modifications, so they move the
CalendarFields struct into the AO. But it turns out that at least one AO
will care (InterpretTemporalDateTimeFields), thus we will need to take
by reference here.
2024-11-23 14:46:00 +01:00
Timothy Flynn
b319d45566 LibJS: Optimize the CalendarDateUntil AO for large year differences
For example, consider the following operation:

    const instance = new Temporal.PlainDate(2000, 5, 2);
    instance.until("-271821-04-19");

The spec would have us enter a loop to compute the difference between
these dates by incrementing an intermediate date one day at a time.
Instead, we can do some math to skip ahead much closer to the desired
date.
2024-11-23 14:46:00 +01:00
Timothy Flynn
cb5d1b5086 LibJS: Implement Temporal.PlainYearMonth.prototype.until/since 2024-11-22 19:55:24 +01:00
Timothy Flynn
b68d67693e LibJS: Implement the Temporal.PlainYearMonth constructor
And the simple Temporal.PlainYearMonth.prototype getters, so that the
constructed Temporal.PlainYearMonth may actually be validated.
2024-11-22 19:55:24 +01:00
Timothy Flynn
5389acc231 LibJS: Implement Temporal.PlainMonthDay.prototype.with/equals 2024-11-21 19:24:25 -05:00
Timothy Flynn
5bccb36a6f LibJS: Implement stringification Temporal.PlainMonthDay prototypes 2024-11-21 19:24:25 -05:00
Timothy Flynn
1a386e78c3 LibJS: Implement the Temporal.PlainMonthDay constructor
And the simple Temporal.PlainMonthDay.prototype getters, so that the
constructed Temporal.PlainMonthDay may actually be validated.
2024-11-21 19:24:25 -05:00
Timothy Flynn
f7517c5b8d LibJS: Remove our existing Temporal implementation
Our Temporal implementation is woefully out of date. The spec has been
so vastly rewritten that it is unfortunately not practical to update our
implementation in-place. Even just removing Temporal objects that were
removed from the spec, or updating any of the simpler remaining objects,
has proven to be a mess in previous attempts.

So, this removes our Temporal implementation. AOs used by other specs
are left intact.
2024-11-20 19:04:30 -05:00
Shannon Booth
f87041bf3a LibGC+Everywhere: Factor out a LibGC from LibJS
Resulting in a massive rename across almost everywhere! Alongside the
namespace change, we now have the following names:

 * JS::NonnullGCPtr -> GC::Ref
 * JS::GCPtr -> GC::Ptr
 * JS::HeapFunction -> GC::Function
 * JS::CellImpl -> GC::Cell
 * JS::Handle -> GC::Root
2024-11-15 14:49:20 +01:00
Timothy Flynn
93712b24bf Everywhere: Hoist the Libraries folder to the top-level 2024-11-10 12:50:45 +01:00
Renamed from Userland/Libraries/LibJS/Runtime/Temporal/Calendar.cpp (Browse further)