Skip to content
This repository was archived by the owner on Jul 9, 2025. It is now read-only.

Commit 3571f1a

Browse files
committed
Bug 1847182 - Part 8: Synchronise time zone offset handling. r=dminor
Implements the changes from: - tc39/proposal-temporal#2621 - tc39/proposal-temporal#2622 - tc39/proposal-temporal#2632 - tc39/proposal-temporal#2607 Differential Revision: https://phabricator.services.mozilla.com/D185412
1 parent de3a804 commit 3571f1a

File tree

11 files changed

+543
-314
lines changed

11 files changed

+543
-314
lines changed

js/public/friend/ErrorNumbers.msg

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -829,7 +829,7 @@ MSG_DEF(JSMSG_TEMPORAL_INVALID_UNIT_RANGE, 0, JSEXN_RANGEERR, "smallest
829829
MSG_DEF(JSMSG_TEMPORAL_INVALID_UNIT_OPTION, 2, JSEXN_RANGEERR, "{0} is not a valid {1} option in this context")
830830
MSG_DEF(JSMSG_TEMPORAL_INVALID_NUMBER, 1, JSEXN_RANGEERR, "{0} must be larger than zero")
831831
MSG_DEF(JSMSG_TEMPORAL_INVALID_INTEGER, 1, JSEXN_RANGEERR, "{0} must be an integer")
832-
MSG_DEF(JSMSG_TEMPORAL_INVALID_OBJECT, 2, JSEXN_TYPEERR, "{0} mustn't be a {1} object")
832+
MSG_DEF(JSMSG_TEMPORAL_INVALID_OBJECT, 2, JSEXN_TYPEERR, "{0} must not be a {1} object")
833833
MSG_DEF(JSMSG_TEMPORAL_MISSING_OPTION, 1, JSEXN_RANGEERR, "undefined {0} option")
834834
MSG_DEF(JSMSG_TEMPORAL_MISSING_PROPERTY, 1, JSEXN_TYPEERR, "{0} property is undefined")
835835
MSG_DEF(JSMSG_TEMPORAL_UNEXPECTED_PROPERTY, 1, JSEXN_TYPEERR, "{0} property is not undefined")
@@ -906,5 +906,6 @@ MSG_DEF(JSMSG_TEMPORAL_PARSER_INVALID_UTC_DESIGNATOR, 0, JSEXN_RANGEERR, "unex
906906
MSG_DEF(JSMSG_TEMPORAL_PARSER_INVALID_UTC_DESIGNATOR_WITHOUT_NAME, 0, JSEXN_RANGEERR, "unexpected UTC designator 'Z' without a bracketed time zone")
907907
MSG_DEF(JSMSG_TEMPORAL_PARSER_MONTH_DAY_CALENDAR_NOT_ISO8601, 0, JSEXN_RANGEERR, "Month-Day formats only support the \"iso8601\" calendar")
908908
MSG_DEF(JSMSG_TEMPORAL_PARSER_YEAR_MONTH_CALENDAR_NOT_ISO8601, 0, JSEXN_RANGEERR, "Year-Month formats only support the \"iso8601\" calendar")
909+
MSG_DEF(JSMSG_TEMPORAL_PARSER_INVALID_SUBMINUTE_TIMEZONE, 0, JSEXN_RANGEERR, "time zone offset must not contain seconds precision")
909910

910911
//clang-format on

js/src/builtin/temporal/Duration.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4085,7 +4085,7 @@ static bool ToRelativeTemporalObject(JSContext* cx, Handle<JSObject*> options,
40854085
}
40864086

40874087
// Step 8.b.
4088-
if (!ParseTimeZoneOffsetString(cx, offsetString, &offsetNs)) {
4088+
if (!ParseDateTimeUTCOffset(cx, offsetString, &offsetNs)) {
40894089
return false;
40904090
}
40914091
} else {
@@ -4106,7 +4106,7 @@ static bool ToRelativeTemporalObject(JSContext* cx, Handle<JSObject*> options,
41064106
bool isUTC;
41074107
bool hasOffset;
41084108
int64_t timeZoneOffset;
4109-
Rooted<JSString*> timeZoneName(cx);
4109+
Rooted<ParsedTimeZone> timeZoneName(cx);
41104110
Rooted<JSString*> calendarString(cx);
41114111
if (!ParseTemporalRelativeToString(cx, string, &dateTime, &isUTC,
41124112
&hasOffset, &timeZoneOffset,
@@ -4150,7 +4150,7 @@ static bool ToRelativeTemporalObject(JSContext* cx, Handle<JSObject*> options,
41504150
if (offsetBehaviour == OffsetBehaviour::Option) {
41514151
MOZ_ASSERT(hasOffset);
41524152

4153-
// Steps 8.a-b.
4153+
// Step 8.a.
41544154
offsetNs = timeZoneOffset;
41554155
} else {
41564156
// Step 9.

js/src/builtin/temporal/Instant.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -578,7 +578,7 @@ static bool ParseTemporalInstant(JSContext* cx, Handle<JSString*> isoString,
578578

579579
// Step 4. (Not applicable in our implementation.)
580580

581-
// Step 6. (Reordered)
581+
// Step 8. (Reordered)
582582
if (!ISODateTimeWithinLimits(dateTime)) {
583583
JS_ReportErrorNumberASCII(cx, GetErrorMessage, nullptr,
584584
JSMSG_TEMPORAL_INSTANT_INVALID);
@@ -588,6 +588,9 @@ static bool ParseTemporalInstant(JSContext* cx, Handle<JSString*> isoString,
588588
// Step 5.
589589
auto utc = GetUTCEpochNanoseconds(dateTime);
590590

591+
// FIXME: spec bug - ParseDateTimeUTCOffset is infallible
592+
// https://github.com/tc39/proposal-temporal/issues/2637
593+
591594
// Step 6.
592595
auto offsetNanoseconds = InstantSpan::fromNanoseconds(offset);
593596

js/src/builtin/temporal/TemporalNow.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include "builtin/temporal/PlainDate.h"
3030
#include "builtin/temporal/PlainDateTime.h"
3131
#include "builtin/temporal/PlainTime.h"
32+
#include "builtin/temporal/TemporalParser.h"
3233
#include "builtin/temporal/TemporalTypes.h"
3334
#include "builtin/temporal/TimeZone.h"
3435
#include "builtin/temporal/ZonedDateTime.h"

0 commit comments

Comments
 (0)