Skip to content

Commit

Permalink
Bug 1847182 - Part 8: Synchronise time zone offset handling. r=dminor
Browse files Browse the repository at this point in the history
  • Loading branch information
anba committed Sep 13, 2023
1 parent de3a804 commit 3571f1a
Show file tree
Hide file tree
Showing 11 changed files with 543 additions and 314 deletions.
3 changes: 2 additions & 1 deletion js/public/friend/ErrorNumbers.msg
Original file line number Diff line number Diff line change
Expand Up @@ -829,7 +829,7 @@ MSG_DEF(JSMSG_TEMPORAL_INVALID_UNIT_RANGE, 0, JSEXN_RANGEERR, "smallest
MSG_DEF(JSMSG_TEMPORAL_INVALID_UNIT_OPTION, 2, JSEXN_RANGEERR, "{0} is not a valid {1} option in this context")
MSG_DEF(JSMSG_TEMPORAL_INVALID_NUMBER, 1, JSEXN_RANGEERR, "{0} must be larger than zero")
MSG_DEF(JSMSG_TEMPORAL_INVALID_INTEGER, 1, JSEXN_RANGEERR, "{0} must be an integer")
MSG_DEF(JSMSG_TEMPORAL_INVALID_OBJECT, 2, JSEXN_TYPEERR, "{0} mustn't be a {1} object")
MSG_DEF(JSMSG_TEMPORAL_INVALID_OBJECT, 2, JSEXN_TYPEERR, "{0} must not be a {1} object")
MSG_DEF(JSMSG_TEMPORAL_MISSING_OPTION, 1, JSEXN_RANGEERR, "undefined {0} option")
MSG_DEF(JSMSG_TEMPORAL_MISSING_PROPERTY, 1, JSEXN_TYPEERR, "{0} property is undefined")
MSG_DEF(JSMSG_TEMPORAL_UNEXPECTED_PROPERTY, 1, JSEXN_TYPEERR, "{0} property is not undefined")
Expand Down Expand Up @@ -906,5 +906,6 @@ MSG_DEF(JSMSG_TEMPORAL_PARSER_INVALID_UTC_DESIGNATOR, 0, JSEXN_RANGEERR, "unex
MSG_DEF(JSMSG_TEMPORAL_PARSER_INVALID_UTC_DESIGNATOR_WITHOUT_NAME, 0, JSEXN_RANGEERR, "unexpected UTC designator 'Z' without a bracketed time zone")
MSG_DEF(JSMSG_TEMPORAL_PARSER_MONTH_DAY_CALENDAR_NOT_ISO8601, 0, JSEXN_RANGEERR, "Month-Day formats only support the \"iso8601\" calendar")
MSG_DEF(JSMSG_TEMPORAL_PARSER_YEAR_MONTH_CALENDAR_NOT_ISO8601, 0, JSEXN_RANGEERR, "Year-Month formats only support the \"iso8601\" calendar")
MSG_DEF(JSMSG_TEMPORAL_PARSER_INVALID_SUBMINUTE_TIMEZONE, 0, JSEXN_RANGEERR, "time zone offset must not contain seconds precision")

//clang-format on
6 changes: 3 additions & 3 deletions js/src/builtin/temporal/Duration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4085,7 +4085,7 @@ static bool ToRelativeTemporalObject(JSContext* cx, Handle<JSObject*> options,
}

// Step 8.b.
if (!ParseTimeZoneOffsetString(cx, offsetString, &offsetNs)) {
if (!ParseDateTimeUTCOffset(cx, offsetString, &offsetNs)) {
return false;
}
} else {
Expand All @@ -4106,7 +4106,7 @@ static bool ToRelativeTemporalObject(JSContext* cx, Handle<JSObject*> options,
bool isUTC;
bool hasOffset;
int64_t timeZoneOffset;
Rooted<JSString*> timeZoneName(cx);
Rooted<ParsedTimeZone> timeZoneName(cx);
Rooted<JSString*> calendarString(cx);
if (!ParseTemporalRelativeToString(cx, string, &dateTime, &isUTC,
&hasOffset, &timeZoneOffset,
Expand Down Expand Up @@ -4150,7 +4150,7 @@ static bool ToRelativeTemporalObject(JSContext* cx, Handle<JSObject*> options,
if (offsetBehaviour == OffsetBehaviour::Option) {
MOZ_ASSERT(hasOffset);

// Steps 8.a-b.
// Step 8.a.
offsetNs = timeZoneOffset;
} else {
// Step 9.
Expand Down
5 changes: 4 additions & 1 deletion js/src/builtin/temporal/Instant.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -578,7 +578,7 @@ static bool ParseTemporalInstant(JSContext* cx, Handle<JSString*> isoString,

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

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

// FIXME: spec bug - ParseDateTimeUTCOffset is infallible
// https://github.com/tc39/proposal-temporal/issues/2637

// Step 6.
auto offsetNanoseconds = InstantSpan::fromNanoseconds(offset);

Expand Down
1 change: 1 addition & 0 deletions js/src/builtin/temporal/TemporalNow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include "builtin/temporal/PlainDate.h"
#include "builtin/temporal/PlainDateTime.h"
#include "builtin/temporal/PlainTime.h"
#include "builtin/temporal/TemporalParser.h"
#include "builtin/temporal/TemporalTypes.h"
#include "builtin/temporal/TimeZone.h"
#include "builtin/temporal/ZonedDateTime.h"
Expand Down
Loading

0 comments on commit 3571f1a

Please sign in to comment.