1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-16 18:55:07 +00:00
Commit graph

687 commits

Author SHA1 Message Date
Linus Groh
27304017e3 LibJS: Don't assume calendar was parsed in to_temporal_zoned_date_time()
The first step of to_temporal_calendar_with_iso_default() is checking
whether the given value is undefined, so we should actually pass that
instead of unconditionally dereferencing the Optional<String>.
2021-11-20 23:10:09 +00:00
Linus Groh
9628452550 LibJS: Fix fallback of hour, minute, second in parse_iso_date_time()
It's not the `to_uint<u8>()` call that would fail, if we have a value
for these productions they will always be valid numbers. We do need to
provide a fallback for when that's not the case and any of them is
undefined, i.e. an empty Optional.
2021-11-20 23:10:09 +00:00
Linus Groh
de23f0b68c LibJS: Start fleshing out an ISO 8601 parser for Temporal
This is the start of a parser for the ISO 8601 grammar used in the
Temporal spec:
https://tc39.es/proposal-temporal/#sec-temporal-iso8601grammar

We will, on purpose, not use a generic ISO 8601 parser from AK or
similar for two reasons:

- Many AOs make specific assumptions about which productions exist and
  access them directly, even when they're part of a larger production.
- The spec says "The grammar deviates from the standard given in ISO
  8601 in the following ways:" and then lists 17 of such deviations.
  Making that work with a general purpose parser is not worth it.

The public API is not being used anywhere yet, but will be in the next
couple of commits. Likewise, the Production enum will be populated with
all the productions accessed directly (e.g. TemporalDateString).

Many thanks to Ali for showing me how to improve my initial approach
full of macros with a nice RAII helper - it's much nicer :^)

Co-Authored-By: Ali Mohammad Pur <mpfard@serenityos.org>
2021-11-20 23:10:09 +00:00
Linus Groh
8d6d39e07c LibJS: Treat relativeTo parameters as PlainDate or ZonedDateTime
This is a normative change in the Temporal spec.

See: c822e14
2021-11-19 19:59:13 +00:00
Linus Groh
2ecb47c985 LibJS: Update spec comments in format_time_zone_offset_string()
This is an editorial change in the Temporal spec.

See: 60c753a
2021-11-19 19:29:18 +00:00
Linus Groh
d0c29c9735 LibJS: Allow string as parameter in Temporal's round() / total()
This is a normative change in the Temporal spec.

See: 1f0c586
2021-11-19 11:06:53 +00:00
Linus Groh
eaa3329573 LibJS: Fix incorrect use of "modulo" in get_iso_parts_from_epoch()
This would return incorrect results for negative inputs. It still does
to some extent, remainder() in step 2 might need to be replaced with
modulo (I opened an issue in tc39/proposal-temporal about that).
2021-11-17 22:31:28 +00:00
Linus Groh
ec1e1f4f12 LibJS: Disallow Temporal.Duration input values to be non-integers
This is a normative change in the Temporal spec.

See: 8c85450
2021-11-17 22:20:59 +00:00
Luke Wilde
3666d2132b LibJS: Remove fallback value for get_offset_nanoseconds_for
This is a normative change in the Temporal spec.

See: 664f02d

Note that the tests are not comprehensive.
2021-11-17 11:30:13 +00:00
Luke Wilde
014840eeca LibJS: Use else-if's in Temporal.Duration.prototype.until
This is an editorial change in the Temporal spec.

See: 3dd2397
2021-11-16 09:10:41 +00:00
Luke Wilde
ac65fb40d9 LibJS: Implement Temporal.PlainDate.prototype.since 2021-11-16 01:06:07 +00:00
Luke Wilde
ddec3bc888 LibJS: Implement Temporal.PlainDate.prototype.until 2021-11-16 01:06:07 +00:00
Nico Weber
a164e6ecbb LibJS: Unbreak to_iso_day_of_week
481f7d6afa tried to use `modulo()` here, but missed that the
code used `<=` instead of `<`.

Keep using `modulo()` and add an explicit conditional, which is
arguably clearer.
2021-11-16 00:41:45 +00:00
Nico Weber
481f7d6afa LibJS: Use modulo() function in to_iso_day_of_week
No behavior change.
2021-11-15 23:54:41 +00:00
Linus Groh
a757f3f421 LibJS: Fix leap year check in to_iso_week_of_year() for week < 1
When the resulting week is in the previous year, we need to check if the
previous year is a leap year and can potentially have 53 weeks, instead
of the given year.
Also added a comment to briefly explain what's going on, as it took me a
while to figure out.
2021-11-15 21:33:26 +00:00
Linus Groh
42071f69cf LibJS: Fix balance_time() for times with negative offset day outcome
...and change the parameter types from i64 to double, as predicted by
a FIXME. The issue here is that integer division with a negative
dividend doesn't yield the same result as floating point division
wrapped in floor().
Additionally, the `days` variable needs to be signed.
2021-11-14 23:10:00 +00:00
Linus Groh
32c52e3511 LibJS: Add missing spaces in balance_iso_date() spec comments 2021-11-14 23:08:49 +00:00
Linus Groh
a3de9dcf95 LibJS: Fix incorrect use of "modulo" in balance_iso_year_month() 2021-11-14 23:08:40 +00:00
Luke Wilde
f6ab63993a LibJS: Implement Temporal.ZonedDateTime.prototype.round 2021-11-13 19:48:54 +00:00
Linus Groh
dbe70e7c55 LibJS: Implement Temporal.Duration.prototype.total() 2021-11-13 18:50:54 +00:00
Linus Groh
656efe5d6c LibJS: Fix days calculation in round_duration() for "year" - "day" units
This relies on floating point division, which is not possible with
LibCrypto bigints at the moment. So, instead of completely ignoring the
remainder we now first do a bigint division, then convert the remainder
to a double, and do another native floating point division to get the
final result.
2021-11-13 18:50:54 +00:00
Linus Groh
f11277b50d LibJS: Fix missing handling of "week" largest_unit in balance_duration()
It would crash because of VERIFY(largest_unit == "nanosecond"sv) in the
final else branch when passing "week", because it's not handled in any
of the previous branches.
2021-11-13 14:21:08 +00:00
Linus Groh
8c73d85a65 LibJS: Fix logic typo in round_duration() remainder calculation
For unit == "hour", the remainder would not return the difference
between fractional_hours and hours, but fractional_hours and days.
2021-11-13 13:33:00 +00:00
Linus Groh
f0cd727d74 LibJS: Fix logic typo in balance_duration() hours calculation
By using milliseconds_division_result instead of seconds_division_result
here, the result for hours was off by a factor of 60.
2021-11-13 13:32:35 +00:00
Linus Groh
7f8dc395c1 LibJS: Implement Temporal.ZonedDateTime.prototype.with() 2021-11-13 00:25:40 +00:00
Linus Groh
0d9defdad8 LibJS: Rename MatchBehavior members back to their old names
I changed this in 6ef1a27 to "match the spec", but the spec calls it
`match exactly` and `match minutes` - so what we had before was correct
and the change made no sense whatsoever.
2021-11-13 00:25:40 +00:00
Luke Wilde
f65d25682c LibJS: Implement Temporal.ZonedDateTime.prototype.subtract 2021-11-12 09:24:36 +00:00
Luke Wilde
9b8524b463 LibJS: Implement Temporal.ZonedDateTime.prototype.add 2021-11-12 09:24:36 +00:00
Luke Wilde
5e3fe52fc4 LibJS: Implement Temporal.Duration.compare 2021-11-11 21:06:54 +00:00
Luke Wilde
29072f4b09 LibJS: Implement the required AOs for Temporal.Duration.compare 2021-11-11 21:06:54 +00:00
Linus Groh
4eaa95769d LibJS: Add missing (void) to handle [[nodiscard]] TRY() result 2021-11-11 00:03:07 +00:00
Linus Groh
fdffdc43fa LibJS: Implement the rest of to_temporal_month_day()
Always throws at the moment, because parse_temporal_month_day_string()
is basically a stub, and parse_iso_date_time() isn't functional either.

The spec issue has been resolved though, so I figured we might as well
get one small step further :^)
2021-11-10 22:28:27 +00:00
Linus Groh
6ef1a2793f LibJS: Rename ZonedDateTime's MatchBehavior enum members to match spec 2021-11-10 21:27:25 +00:00
Luke Wilde
5594a492f0 LibJS: Implement Temporal.ZonedDateTime.prototype.toJSON 2021-11-10 12:56:56 +00:00
Luke Wilde
6856b6168a LibJS: Implement Temporal.ZonedDateTime.prototype.toLocaleString 2021-11-10 12:56:56 +00:00
Luke Wilde
a9ad993e78 LibJS: Implement Temporal.ZonedDateTime.prototype.toString 2021-11-10 12:56:56 +00:00
Luke Wilde
dc72d416b2 LibJS: Implement the required AOs for ZonedDateTime stringifiers 2021-11-10 12:56:56 +00:00
Luke Wilde
05c3320da3 LibJS: Mark RoundTemporalInstant as infallible
This is an editorial change in the Temporal spec.

See: 0b4141c

This also allows us to get rid of two old exception checks.
2021-11-09 23:42:34 +02:00
Linus Groh
e9f66d1c2a LibJS: Mark DaysUntil as infallible
This is an editorial change in the Temporal spec.

See: 30a8939
2021-11-09 20:37:17 +00:00
Linus Groh
1e3e0477cb LibJS: Implement Temporal.PlainMonthDay.prototype.with() 2021-11-08 22:19:45 +00:00
Linus Groh
fa1d5feec0 LibJS: Implement Temporal.PlainYearMonth.prototype.with() 2021-11-08 22:19:45 +00:00
Linus Groh
aca2ef9e1c LibJS: Implement Temporal.PlainDateTime.prototype.with() 2021-11-08 22:19:45 +00:00
Linus Groh
c3c9ac93d0 LibJS: Implement Temporal.PlainDate.prototype.with()
With one caveat: in the PreparePartialTemporalFields AO I made a change
to fix a spec issue that would require the input object to always have a
month or monthCode property.
This is tracked in https://github.com/tc39/proposal-temporal/issues/1910
and may get accepted as-is, in which case we simply need to remove the
NOTE comment.
2021-11-08 22:19:45 +00:00
Linus Groh
46d7c34028 LibJS: Use StringView literals in prepare_temporal_fields() 2021-11-08 19:12:47 +00:00
Linus Groh
a3b8303f3c LibJS: Fix modulo() template argument deduction on i686
Userland/Libraries/LibJS/Runtime/Temporal/PlainTime.cpp:283:24:
    note: deduced conflicting types for parameter 'T' ('long long int'
    and 'long int')
      283 |     nanosecond = modulo(nanosecond, 1000l);
          |                  ~~~~~~^~~~~~~~~~~~~~~~~~~

Worked fine on x86_84 :yakshrug:
2021-11-07 21:33:56 +00:00
Linus Groh
b3ea7332b2 LibJS: Fix use of "modulo" for negative values in balance_time() 2021-11-07 21:11:31 +00:00
Linus Groh
e93ce1ff69 LibJS: Fix nanoseconds formatting in format_time_zone_offset_string()
Two issues:

- The format string said "{:9}", which left-pads with spaces and not
  zeros as required
- Even when correcting that, we were not accounting for step 11 b:
  "Set fraction to the longest possible substring of fraction starting
  at position 0 and not ending with the code unit 0x0030 (DIGIT ZERO)."
  We can safely use trim() for that as the formatted string is known to
  not contain only zeros (which would leave the left-most in place).

Also adds tests for "UTC" and various numeric offsets.
2021-11-07 20:06:28 +00:00
Linus Groh
68d80d239b LibJS: Fix fraction substring in parse_time_zone_offset_string()
We're supposed to get the substring from `fraction`, which is guaranteed
to have the required length. `fraction_part` is the user-supplied value
and trying to get a substring view from 0-9 might crash.
2021-11-07 20:01:31 +00:00
Linus Groh
df2ccb3d38 LibJS: Implement Temporal.Duration.prototype.toLocaleString() 2021-11-07 15:31:28 +01:00
Linus Groh
90fa356b93 LibJS: Implement Temporal.Duration.prototype.toJSON() 2021-11-07 15:31:28 +01:00