Implement Temporal.Instant.toZonedDateTimeISO

Signed-off-by: Seonghyun Kim <sh8281.kim@samsung.com>
This commit is contained in:
Seonghyun Kim 2025-11-17 11:09:32 +09:00 committed by Patrick Kim
commit 5bbfa73dcd
5 changed files with 18 additions and 19 deletions

View file

@ -351,6 +351,12 @@ static Value builtinTemporalInstantSubtract(ExecutionState& state, Value thisVal
return instant->addDurationToInstant(state, TemporalInstantObject::AddDurationOperation::Subtract, argv[0]);
}
static Value builtinTemporalInstantToZonedDateTimeISO(ExecutionState& state, Value thisValue, size_t argc, Value* argv, Optional<Object*> newTarget)
{
RESOLVE_THIS_BINDING_TO_INSTANT(instant, ToZonedDateTimeISO);
return instant->toZonedDateTimeISO(state, argv[0]);
}
static Value builtinTemporalPlainTimeConstructor(ExecutionState& state, Value thisValue, size_t argc, Value* argv, Optional<Object*> newTarget)
{
// If NewTarget is undefined, throw a TypeError exception.
@ -1498,6 +1504,7 @@ void GlobalObject::installTemporal(ExecutionState& state)
m_temporalInstantPrototype->directDefineOwnProperty(state, ObjectPropertyName(strings->lazySince()), ObjectPropertyDescriptor(new NativeFunctionObject(state, NativeFunctionInfo(strings->lazySince(), builtinTemporalInstantSince, 1, NativeFunctionInfo::Strict)), (ObjectPropertyDescriptor::PresentAttribute)(ObjectPropertyDescriptor::WritablePresent | ObjectPropertyDescriptor::ConfigurablePresent)));
m_temporalInstantPrototype->directDefineOwnProperty(state, ObjectPropertyName(strings->add), ObjectPropertyDescriptor(new NativeFunctionObject(state, NativeFunctionInfo(strings->add, builtinTemporalInstantAdd, 1, NativeFunctionInfo::Strict)), (ObjectPropertyDescriptor::PresentAttribute)(ObjectPropertyDescriptor::WritablePresent | ObjectPropertyDescriptor::ConfigurablePresent)));
m_temporalInstantPrototype->directDefineOwnProperty(state, ObjectPropertyName(strings->lazySubtract()), ObjectPropertyDescriptor(new NativeFunctionObject(state, NativeFunctionInfo(strings->lazySubtract(), builtinTemporalInstantSubtract, 1, NativeFunctionInfo::Strict)), (ObjectPropertyDescriptor::PresentAttribute)(ObjectPropertyDescriptor::WritablePresent | ObjectPropertyDescriptor::ConfigurablePresent)));
m_temporalInstantPrototype->directDefineOwnProperty(state, ObjectPropertyName(strings->lazyToZonedDateTimeISO()), ObjectPropertyDescriptor(new NativeFunctionObject(state, NativeFunctionInfo(strings->lazyToZonedDateTimeISO(), builtinTemporalInstantToZonedDateTimeISO, 1, NativeFunctionInfo::Strict)), (ObjectPropertyDescriptor::PresentAttribute)(ObjectPropertyDescriptor::WritablePresent | ObjectPropertyDescriptor::ConfigurablePresent)));
{
auto getter = new NativeFunctionObject(state, NativeFunctionInfo(strings->lazyGetEpochMilliseconds(), builtinTemporalInstantGetEpochMilliseconds, 0, NativeFunctionInfo::Strict));

View file

@ -1032,6 +1032,7 @@ namespace Escargot {
F(ToPlainMonthDay, "toPlainMonthDay") \
F(ToPlainYearMonth, "toPlainYearMonth") \
F(ToZonedDateTime, "toZonedDateTime") \
F(ToZonedDateTimeISO, "toZonedDateTimeISO") \
F(TimeZoneId, "timeZoneId") \
F(Until, "until") \
F(WeekOfYear, "weekOfYear") \

View file

@ -21,6 +21,7 @@
#include "Escargot.h"
#include "TemporalInstantObject.h"
#include "TemporalDurationObject.h"
#include "TemporalZonedDateTimeObject.h"
#include "intl/Intl.h"
#include "util/ISO8601.h"
@ -217,6 +218,14 @@ TemporalInstantObject* TemporalInstantObject::round(ExecutionState& state, Value
return new TemporalInstantObject(state, state.context()->globalObject()->temporalInstantPrototype(), roundedInstant.epochNanoseconds());
}
TemporalZonedDateTimeObject* TemporalInstantObject::toZonedDateTimeISO(ExecutionState& state, Value timeZoneInput)
{
// Set timeZone to ? ToTemporalTimeZoneIdentifier(timeZone).
auto timeZone = Temporal::toTemporalTimezoneIdentifier(state, timeZoneInput);
// Return ! CreateTemporalZonedDateTime(instant.[[EpochNanoseconds]], timeZone, "iso8601").
return new TemporalZonedDateTimeObject(state, state.context()->globalObject()->temporalZonedDateTimePrototype(), epochNanoseconds(), timeZone, Calendar());
}
TemporalDurationObject* TemporalInstantObject::differenceTemporalInstant(ExecutionState& state, DifferenceTemporalInstantOperation operation, Value otherInput, Value options)
{
// Set other to ? ToTemporalInstant(other).

View file

@ -45,6 +45,7 @@ public:
String* toString(ExecutionState& state, Value options);
static String* toString(ExecutionState& state, Int128 epochNanoseconds, TimeZone timeZone, Value precision);
TemporalInstantObject* round(ExecutionState& state, Value roundTo);
TemporalZonedDateTimeObject* toZonedDateTimeISO(ExecutionState& state, Value timeZone);
// https://tc39.es/proposal-temporal/#sec-temporal-differencetemporalinstant
enum class DifferenceTemporalInstantOperation {

View file

@ -359,22 +359,6 @@
<test id="built-ins/Temporal/Duration/prototype/total/unit-wrong-type"><reason>TODO</reason></test>
<test id="built-ins/Temporal/Duration/prototype/total/year-zero"><reason>TODO</reason></test>
<test id="built-ins/Temporal/Instant/prototype/since/argument-zoneddatetime"><reason>TODO</reason></test>
<test id="built-ins/Temporal/Instant/prototype/toZonedDateTimeISO/branding"><reason>TODO</reason></test>
<test id="built-ins/Temporal/Instant/prototype/toZonedDateTimeISO/builtin"><reason>TODO</reason></test>
<test id="built-ins/Temporal/Instant/prototype/toZonedDateTimeISO/calendar-is-builtin"><reason>TODO</reason></test>
<test id="built-ins/Temporal/Instant/prototype/toZonedDateTimeISO/length"><reason>TODO</reason></test>
<test id="built-ins/Temporal/Instant/prototype/toZonedDateTimeISO/name"><reason>TODO</reason></test>
<test id="built-ins/Temporal/Instant/prototype/toZonedDateTimeISO/not-a-constructor"><reason>TODO</reason></test>
<test id="built-ins/Temporal/Instant/prototype/toZonedDateTimeISO/prop-desc"><reason>TODO</reason></test>
<test id="built-ins/Temporal/Instant/prototype/toZonedDateTimeISO/timezone-case-insensitive"><reason>TODO</reason></test>
<test id="built-ins/Temporal/Instant/prototype/toZonedDateTimeISO/timezone-string"><reason>TODO</reason></test>
<test id="built-ins/Temporal/Instant/prototype/toZonedDateTimeISO/timezone-string-datetime"><reason>TODO</reason></test>
<test id="built-ins/Temporal/Instant/prototype/toZonedDateTimeISO/timezone-string-leap-second"><reason>TODO</reason></test>
<test id="built-ins/Temporal/Instant/prototype/toZonedDateTimeISO/timezone-string-multiple-offsets"><reason>TODO</reason></test>
<test id="built-ins/Temporal/Instant/prototype/toZonedDateTimeISO/timezone-string-sub-minute-offset"><reason>TODO</reason></test>
<test id="built-ins/Temporal/Instant/prototype/toZonedDateTimeISO/timezone-string-year-zero"><reason>TODO</reason></test>
<test id="built-ins/Temporal/Instant/prototype/toZonedDateTimeISO/timezone-wrong-type"><reason>TODO</reason></test>
<test id="built-ins/Temporal/Instant/prototype/toZonedDateTimeISO/to-zoned-date-time-iso"><reason>TODO</reason></test>
<test id="built-ins/Temporal/Instant/prototype/until/argument-zoneddatetime"><reason>TODO</reason></test>
<test id="built-ins/Temporal/PlainDate/prototype/add/argument-duration-max"><reason>TODO</reason></test>
<test id="built-ins/Temporal/PlainDate/prototype/since/argument-plaindatetime"><reason>TODO</reason></test>
@ -491,7 +475,6 @@
<test id="intl402/Temporal/Instant/prototype/toLocaleString/options-conflict"><reason>TODO</reason></test>
<test id="intl402/Temporal/Instant/prototype/toLocaleString/options-undefined"><reason>TODO</reason></test>
<test id="intl402/Temporal/Instant/prototype/toString/timezone-offset"><reason>TODO</reason></test>
<test id="intl402/Temporal/Instant/prototype/toZonedDateTimeISO/timezone-string-datetime"><reason>TODO</reason></test>
<test id="intl402/Temporal/PlainDate/prototype/toLocaleString/calendar-mismatch"><reason>TODO</reason></test>
<test id="intl402/Temporal/PlainDate/prototype/toLocaleString/dateStyle"><reason>TODO</reason></test>
<test id="intl402/Temporal/PlainDate/prototype/toLocaleString/dateStyle-timeStyle-undefined"><reason>TODO</reason></test>
@ -594,7 +577,6 @@
<test id="intl402/Temporal/ZonedDateTime/prototype/hoursInDay/dst-midnight"><reason>TODO</reason></test>
<test id="intl402/Temporal/ZonedDateTime/prototype/hoursInDay/dst-skipped-cross-midnight"><reason>TODO</reason></test>
<test id="intl402/Temporal/ZonedDateTime/prototype/hoursInDay/same-date-starts-twice"><reason>TODO</reason></test>
<test id="intl402/Temporal/ZonedDateTime/prototype/offsetNanoseconds/nanoseconds-subtracted-or-added-at-dst-transition"><reason>TODO</reason></test>
<test id="intl402/Temporal/ZonedDateTime/prototype/round/dst-skipped-cross-midnight"><reason>TODO</reason></test>
<test id="intl402/Temporal/ZonedDateTime/prototype/since/canonicalize-iana-identifiers-before-comparing"><reason>TODO</reason></test>
<test id="intl402/Temporal/ZonedDateTime/prototype/since/dst-balancing-result"><reason>TODO</reason></test>
@ -1240,7 +1222,6 @@
<test id="staging/Temporal/Duration/old/balances-differently-depending-on-relativeto"><reason>TODO</reason></test>
<test id="staging/Temporal/Duration/old/balances-up-to-next-unit-after-rounding"><reason>TODO</reason></test>
<test id="staging/Temporal/Duration/old/relativeto-not-required-to-round-fixed-length-units-in-durations-without-variable-units"><reason>TODO</reason></test>
<test id="staging/Temporal/Regex/old/instant"><reason>TODO</reason></test>
<test id="staging/built-ins/Object/preventExtensions/preventExtensions-variable-length-typed-arrays"><reason>TODO</reason></test>
<test id="staging/built-ins/Object/seal/seal-variable-length-typed-arrays"><reason>TODO</reason></test>
<test id="staging/built-ins/Reflect/preventExtensions/preventExtensions-variable-length-typed-arrays"><reason>TODO</reason></test>