1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-23 07:44:48 -05:00

BREAKING(temporal/unstable): Remove obsoleted Temporal APIs part 2 (#25505)

Mainly I removed `Temporal.Calendar` and `Temporal.TimeZone` and
replaced them to APIs that handle calendar and timezone as strings.
https://github.com/tc39/proposal-temporal/pull/2925

Related #24836
This commit is contained in:
Kenta Moriuchi 2024-09-11 06:36:43 +09:00 committed by GitHub
parent a69b1e699e
commit e522f4b65a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
18 changed files with 426 additions and 748 deletions

View file

@ -2067,8 +2067,7 @@ declare namespace Temporal {
};
/**
* Options to control behavior of `Duration.compare()`, `Duration.add()`, and
* `Duration.subtract()`
* Options to control behavior of `Duration.compare()`
*
* @category Temporal
* @experimental
@ -2271,9 +2270,6 @@ declare namespace Temporal {
| "nanosecond"
>,
): Temporal.Instant;
toZonedDateTime(
calendarAndTimeZone: { timeZone: TimeZoneLike; calendar: CalendarLike },
): Temporal.ZonedDateTime;
toZonedDateTimeISO(tzLike: TimeZoneLike): Temporal.ZonedDateTime;
toLocaleString(
locales?: string | string[],
@ -2286,356 +2282,19 @@ declare namespace Temporal {
}
/**
* @category Temporal
* @experimental
*/
export type YearOrEraAndEraYear = { era: string; eraYear: number } | {
year: number;
};
/**
* @category Temporal
* @experimental
*/
export type MonthCodeOrMonthAndYear =
| (YearOrEraAndEraYear & { month: number })
| {
monthCode: string;
};
/**
* @category Temporal
* @experimental
*/
export type MonthOrMonthCode = { month: number } | { monthCode: string };
/**
* @category Temporal
* @experimental
*/
export interface CalendarProtocol {
id: string;
year(
date:
| Temporal.PlainDate
| Temporal.PlainDateTime
| Temporal.PlainYearMonth
| PlainDateLike
| string,
): number;
month(
date:
| Temporal.PlainDate
| Temporal.PlainDateTime
| Temporal.PlainYearMonth
| Temporal.PlainMonthDay
| PlainDateLike
| string,
): number;
monthCode(
date:
| Temporal.PlainDate
| Temporal.PlainDateTime
| Temporal.PlainYearMonth
| Temporal.PlainMonthDay
| PlainDateLike
| string,
): string;
day(
date:
| Temporal.PlainDate
| Temporal.PlainDateTime
| Temporal.PlainMonthDay
| PlainDateLike
| string,
): number;
era(
date:
| Temporal.PlainDate
| Temporal.PlainDateTime
| PlainDateLike
| string,
): string | undefined;
eraYear(
date:
| Temporal.PlainDate
| Temporal.PlainDateTime
| PlainDateLike
| string,
): number | undefined;
dayOfWeek(
date:
| Temporal.PlainDate
| Temporal.PlainDateTime
| PlainDateLike
| string,
): number;
dayOfYear(
date:
| Temporal.PlainDate
| Temporal.PlainDateTime
| PlainDateLike
| string,
): number;
weekOfYear(
date:
| Temporal.PlainDate
| Temporal.PlainDateTime
| PlainDateLike
| string,
): number | undefined;
yearOfWeek(
date:
| Temporal.PlainDate
| Temporal.PlainDateTime
| PlainDateLike
| string,
): number | undefined;
daysInWeek(
date:
| Temporal.PlainDate
| Temporal.PlainDateTime
| PlainDateLike
| string,
): number;
daysInMonth(
date:
| Temporal.PlainDate
| Temporal.PlainDateTime
| Temporal.PlainYearMonth
| PlainDateLike
| string,
): number;
daysInYear(
date:
| Temporal.PlainDate
| Temporal.PlainDateTime
| Temporal.PlainYearMonth
| PlainDateLike
| string,
): number;
monthsInYear(
date:
| Temporal.PlainDate
| Temporal.PlainDateTime
| Temporal.PlainYearMonth
| PlainDateLike
| string,
): number;
inLeapYear(
date:
| Temporal.PlainDate
| Temporal.PlainDateTime
| Temporal.PlainYearMonth
| PlainDateLike
| string,
): boolean;
dateFromFields(
fields: YearOrEraAndEraYear & MonthOrMonthCode & { day: number },
options?: AssignmentOptions,
): Temporal.PlainDate;
yearMonthFromFields(
fields: YearOrEraAndEraYear & MonthOrMonthCode,
options?: AssignmentOptions,
): Temporal.PlainYearMonth;
monthDayFromFields(
fields: MonthCodeOrMonthAndYear & { day: number },
options?: AssignmentOptions,
): Temporal.PlainMonthDay;
dateAdd(
date: Temporal.PlainDate | PlainDateLike | string,
duration: Temporal.Duration | DurationLike | string,
options?: ArithmeticOptions,
): Temporal.PlainDate;
dateUntil(
one: Temporal.PlainDate | PlainDateLike | string,
two: Temporal.PlainDate | PlainDateLike | string,
options?: DifferenceOptions<"year" | "month" | "week" | "day">,
): Temporal.Duration;
fields(fields: Iterable<string>): Iterable<string>;
mergeFields(
fields: Record<string, unknown>,
additionalFields: Record<string, unknown>,
): Record<string, unknown>;
toString?(): string;
toJSON?(): string;
}
/**
* Any of these types can be passed to Temporal methods instead of a Temporal.Calendar.
* Any of these types can be passed to Temporal methods instead of a calendar ID.
*
* @category Temporal
* @experimental
*/
export type CalendarLike =
| string
| CalendarProtocol
| ZonedDateTime
| PlainDateTime
| PlainDate
| PlainYearMonth
| PlainMonthDay;
/**
* A `Temporal.Calendar` is a representation of a calendar system. It includes
* information about how many days are in each year, how many months are in
* each year, how many days are in each month, and how to do arithmetic in
* that calendar system.
*
* See https://tc39.es/proposal-temporal/docs/calendar.html for more details.
*
* @category Temporal
* @experimental
*/
export class Calendar implements CalendarProtocol {
static from(item: CalendarLike): Temporal.Calendar | CalendarProtocol;
constructor(calendarIdentifier: string);
readonly id: string;
year(
date:
| Temporal.PlainDate
| Temporal.PlainDateTime
| Temporal.PlainYearMonth
| PlainDateLike
| string,
): number;
month(
date:
| Temporal.PlainDate
| Temporal.PlainDateTime
| Temporal.PlainYearMonth
| Temporal.PlainMonthDay
| PlainDateLike
| string,
): number;
monthCode(
date:
| Temporal.PlainDate
| Temporal.PlainDateTime
| Temporal.PlainYearMonth
| Temporal.PlainMonthDay
| PlainDateLike
| string,
): string;
day(
date:
| Temporal.PlainDate
| Temporal.PlainDateTime
| Temporal.PlainMonthDay
| PlainDateLike
| string,
): number;
era(
date:
| Temporal.PlainDate
| Temporal.PlainDateTime
| PlainDateLike
| string,
): string | undefined;
eraYear(
date:
| Temporal.PlainDate
| Temporal.PlainDateTime
| PlainDateLike
| string,
): number | undefined;
dayOfWeek(
date:
| Temporal.PlainDate
| Temporal.PlainDateTime
| PlainDateLike
| string,
): number;
dayOfYear(
date:
| Temporal.PlainDate
| Temporal.PlainDateTime
| PlainDateLike
| string,
): number;
weekOfYear(
date:
| Temporal.PlainDate
| Temporal.PlainDateTime
| PlainDateLike
| string,
): number | undefined;
yearOfWeek(
date:
| Temporal.PlainDate
| Temporal.PlainDateTime
| PlainDateLike
| string,
): number | undefined;
daysInWeek(
date:
| Temporal.PlainDate
| Temporal.PlainDateTime
| PlainDateLike
| string,
): number;
daysInMonth(
date:
| Temporal.PlainDate
| Temporal.PlainDateTime
| Temporal.PlainYearMonth
| PlainDateLike
| string,
): number;
daysInYear(
date:
| Temporal.PlainDate
| Temporal.PlainDateTime
| Temporal.PlainYearMonth
| PlainDateLike
| string,
): number;
monthsInYear(
date:
| Temporal.PlainDate
| Temporal.PlainDateTime
| Temporal.PlainYearMonth
| PlainDateLike
| string,
): number;
inLeapYear(
date:
| Temporal.PlainDate
| Temporal.PlainDateTime
| Temporal.PlainYearMonth
| PlainDateLike
| string,
): boolean;
dateFromFields(
fields: YearOrEraAndEraYear & MonthOrMonthCode & { day: number },
options?: AssignmentOptions,
): Temporal.PlainDate;
yearMonthFromFields(
fields: YearOrEraAndEraYear & MonthOrMonthCode,
options?: AssignmentOptions,
): Temporal.PlainYearMonth;
monthDayFromFields(
fields: MonthCodeOrMonthAndYear & { day: number },
options?: AssignmentOptions,
): Temporal.PlainMonthDay;
dateAdd(
date: Temporal.PlainDate | PlainDateLike | string,
duration: Temporal.Duration | DurationLike | string,
options?: ArithmeticOptions,
): Temporal.PlainDate;
dateUntil(
one: Temporal.PlainDate | PlainDateLike | string,
two: Temporal.PlainDate | PlainDateLike | string,
options?: DifferenceOptions<"year" | "month" | "week" | "day">,
): Temporal.Duration;
fields(fields: Iterable<string>): string[];
mergeFields(
fields: Record<string, unknown>,
additionalFields: Record<string, unknown>,
): Record<string, unknown>;
toString(): string;
toJSON(): string;
readonly [Symbol.toStringTag]: "Temporal.Calendar";
}
/**
* @category Temporal
* @experimental
@ -2650,17 +2309,6 @@ declare namespace Temporal {
calendar?: CalendarLike;
};
/**
* @category Temporal
* @experimental
*/
export type PlainDateISOFields = {
isoYear: number;
isoMonth: number;
isoDay: number;
calendar: string | CalendarProtocol;
};
/**
* A `Temporal.PlainDate` represents a calendar date. "Calendar date" refers to the
* concept of a date as expressed in everyday usage, independent of any time
@ -2686,7 +2334,7 @@ declare namespace Temporal {
isoYear: number,
isoMonth: number,
isoDay: number,
calendar?: CalendarLike,
calendar?: string,
);
readonly era: string | undefined;
readonly eraYear: number | undefined;
@ -2731,7 +2379,6 @@ declare namespace Temporal {
): Temporal.PlainDateTime;
toZonedDateTime(
timeZoneAndTime:
| TimeZoneProtocol
| string
| {
timeZone: TimeZoneLike;
@ -2740,7 +2387,6 @@ declare namespace Temporal {
): Temporal.ZonedDateTime;
toPlainYearMonth(): Temporal.PlainYearMonth;
toPlainMonthDay(): Temporal.PlainMonthDay;
getISOFields(): PlainDateISOFields;
toLocaleString(
locales?: string | string[],
options?: Intl.DateTimeFormatOptions,
@ -2771,23 +2417,6 @@ declare namespace Temporal {
calendar?: CalendarLike;
};
/**
* @category Temporal
* @experimental
*/
export type PlainDateTimeISOFields = {
isoYear: number;
isoMonth: number;
isoDay: number;
isoHour: number;
isoMinute: number;
isoSecond: number;
isoMillisecond: number;
isoMicrosecond: number;
isoNanosecond: number;
calendar: string | CalendarProtocol;
};
/**
* A `Temporal.PlainDateTime` represents a calendar date and wall-clock time, with
* a precision in nanoseconds, and without any time zone. Of the Temporal
@ -2820,7 +2449,7 @@ declare namespace Temporal {
millisecond?: number,
microsecond?: number,
nanosecond?: number,
calendar?: CalendarLike,
calendar?: string,
);
readonly era: string | undefined;
readonly eraYear: number | undefined;
@ -2908,7 +2537,6 @@ declare namespace Temporal {
): Temporal.ZonedDateTime;
toPlainDate(): Temporal.PlainDate;
toPlainTime(): Temporal.PlainTime;
getISOFields(): PlainDateTimeISOFields;
toLocaleString(
locales?: string | string[],
options?: Intl.DateTimeFormatOptions,
@ -2951,7 +2579,7 @@ declare namespace Temporal {
constructor(
isoMonth: number,
isoDay: number,
calendar?: CalendarLike,
calendar?: string,
referenceISOYear?: number,
);
readonly monthCode: string;
@ -2963,7 +2591,6 @@ declare namespace Temporal {
options?: AssignmentOptions,
): Temporal.PlainMonthDay;
toPlainDate(year: { year: number }): Temporal.PlainDate;
getISOFields(): PlainDateISOFields;
toLocaleString(
locales?: string | string[],
options?: Intl.DateTimeFormatOptions,
@ -2987,19 +2614,6 @@ declare namespace Temporal {
nanosecond?: number;
};
/**
* @category Temporal
* @experimental
*/
export type PlainTimeISOFields = {
isoHour: number;
isoMinute: number;
isoSecond: number;
isoMillisecond: number;
isoMicrosecond: number;
isoNanosecond: number;
};
/**
* A `Temporal.PlainTime` represents a wall-clock time, with a precision in
* nanoseconds, and without any time zone. "Wall-clock time" refers to the
@ -3086,7 +2700,6 @@ declare namespace Temporal {
| "nanosecond"
>,
): Temporal.PlainTime;
getISOFields(): PlainTimeISOFields;
toLocaleString(
locales?: string | string[],
options?: Intl.DateTimeFormatOptions,
@ -3098,76 +2711,12 @@ declare namespace Temporal {
}
/**
* A plain object implementing the protocol for a custom time zone.
* Any of these types can be passed to Temporal methods instead of a time zone ID.
*
* @category Temporal
* @experimental
*/
export interface TimeZoneProtocol {
id: string;
getOffsetNanosecondsFor(instant: Temporal.Instant | string): number;
getOffsetStringFor?(instant: Temporal.Instant | string): string;
getPlainDateTimeFor?(
instant: Temporal.Instant | string,
calendar?: CalendarLike,
): Temporal.PlainDateTime;
getInstantFor?(
dateTime: Temporal.PlainDateTime | PlainDateTimeLike | string,
options?: ToInstantOptions,
): Temporal.Instant;
getPossibleInstantsFor(
dateTime: Temporal.PlainDateTime | PlainDateTimeLike | string,
): Temporal.Instant[];
toString?(): string;
toJSON?(): string;
}
/**
* Any of these types can be passed to Temporal methods instead of a Temporal.TimeZone.
*
* @category Temporal
* @experimental
*/
export type TimeZoneLike = string | TimeZoneProtocol | ZonedDateTime;
/**
* A `Temporal.TimeZone` is a representation of a time zone: either an
* {@link https://www.iana.org/time-zones|IANA time zone}, including
* information about the time zone such as the offset between the local time
* and UTC at a particular time, and daylight saving time (DST) changes; or
* simply a particular UTC offset with no DST.
*
* `Temporal.ZonedDateTime` is the only Temporal type to contain a time zone.
* Other types, like `Temporal.Instant` and `Temporal.PlainDateTime`, do not
* contain any time zone information, and a `Temporal.TimeZone` object is
* required to convert between them.
*
* See https://tc39.es/proposal-temporal/docs/timezone.html for more details.
*
* @category Temporal
* @experimental
*/
export class TimeZone implements TimeZoneProtocol {
static from(timeZone: TimeZoneLike): Temporal.TimeZone | TimeZoneProtocol;
constructor(timeZoneIdentifier: string);
readonly id: string;
getOffsetNanosecondsFor(instant: Temporal.Instant | string): number;
getOffsetStringFor(instant: Temporal.Instant | string): string;
getPlainDateTimeFor(
instant: Temporal.Instant | string,
calendar?: CalendarLike,
): Temporal.PlainDateTime;
getInstantFor(
dateTime: Temporal.PlainDateTime | PlainDateTimeLike | string,
options?: ToInstantOptions,
): Temporal.Instant;
getPossibleInstantsFor(
dateTime: Temporal.PlainDateTime | PlainDateTimeLike | string,
): Temporal.Instant[];
toString(): string;
toJSON(): string;
readonly [Symbol.toStringTag]: "Temporal.TimeZone";
}
export type TimeZoneLike = string | ZonedDateTime;
/**
* @category Temporal
@ -3204,7 +2753,7 @@ declare namespace Temporal {
constructor(
isoYear: number,
isoMonth: number,
calendar?: CalendarLike,
calendar?: string,
referenceISODay?: number,
);
readonly era: string | undefined;
@ -3241,7 +2790,6 @@ declare namespace Temporal {
options?: DifferenceOptions<"year" | "month">,
): Temporal.Duration;
toPlainDate(day: { day: number }): Temporal.PlainDate;
getISOFields(): PlainDateISOFields;
toLocaleString(
locales?: string | string[],
options?: Intl.DateTimeFormatOptions,
@ -3274,25 +2822,6 @@ declare namespace Temporal {
calendar?: CalendarLike;
};
/**
* @category Temporal
* @experimental
*/
export type ZonedDateTimeISOFields = {
isoYear: number;
isoMonth: number;
isoDay: number;
isoHour: number;
isoMinute: number;
isoSecond: number;
isoMillisecond: number;
isoMicrosecond: number;
isoNanosecond: number;
offset: string;
timeZone: string | TimeZoneProtocol;
calendar: string | CalendarProtocol;
};
/**
* @category Temporal
* @experimental
@ -3306,11 +2835,7 @@ declare namespace Temporal {
one: Temporal.ZonedDateTime | ZonedDateTimeLike | string,
two: Temporal.ZonedDateTime | ZonedDateTimeLike | string,
): ComparisonResult;
constructor(
epochNanoseconds: bigint,
timeZone: TimeZoneLike,
calendar?: CalendarLike,
);
constructor(epochNanoseconds: bigint, timeZone: string, calendar?: string);
readonly era: string | undefined;
readonly eraYear: number | undefined;
readonly year: number;
@ -3337,9 +2862,7 @@ declare namespace Temporal {
readonly inLeapYear: boolean;
readonly offsetNanoseconds: number;
readonly offset: string;
readonly epochSeconds: number;
readonly epochMilliseconds: number;
readonly epochMicroseconds: bigint;
readonly epochNanoseconds: bigint;
equals(other: Temporal.ZonedDateTime | ZonedDateTimeLike | string): boolean;
with(
@ -3408,7 +2931,6 @@ declare namespace Temporal {
toPlainDateTime(): Temporal.PlainDateTime;
toPlainDate(): Temporal.PlainDate;
toPlainTime(): Temporal.PlainTime;
getISOFields(): ZonedDateTimeISOFields;
toLocaleString(
locales?: string | string[],
options?: Intl.DateTimeFormatOptions,
@ -3449,8 +2971,7 @@ declare namespace Temporal {
*
* @param {TimeZoneLike} [tzLike] -
* {@link https://en.wikipedia.org/wiki/List_of_tz_database_time_zones|IANA time zone identifier}
* string (e.g. `'Europe/London'`), `Temporal.TimeZone` instance, or an
* object implementing the time zone protocol. If omitted, the environment's
* string (e.g. `'Europe/London'`). If omitted, the environment's
* current time zone will be used.
*/
zonedDateTimeISO: (tzLike?: TimeZoneLike) => Temporal.ZonedDateTime;
@ -3466,8 +2987,7 @@ declare namespace Temporal {
*
* @param {TimeZoneLike} [tzLike] -
* {@link https://en.wikipedia.org/wiki/List_of_tz_database_time_zones|IANA time zone identifier}
* string (e.g. `'Europe/London'`), `Temporal.TimeZone` instance, or an
* object implementing the time zone protocol. If omitted, the environment's
* string (e.g. `'Europe/London'`). If omitted, the environment's
* current time zone will be used.
*/
plainDateTimeISO: (tzLike?: TimeZoneLike) => Temporal.PlainDateTime;
@ -3478,8 +2998,7 @@ declare namespace Temporal {
*
* @param {TimeZoneLike} [tzLike] -
* {@link https://en.wikipedia.org/wiki/List_of_tz_database_time_zones|IANA time zone identifier}
* string (e.g. `'Europe/London'`), `Temporal.TimeZone` instance, or an
* object implementing the time zone protocol. If omitted, the environment's
* string (e.g. `'Europe/London'`). If omitted, the environment's
* current time zone will be used.
*/
plainDateISO: (tzLike?: TimeZoneLike) => Temporal.PlainDate;
@ -3489,8 +3008,7 @@ declare namespace Temporal {
*
* @param {TimeZoneLike} [tzLike] -
* {@link https://en.wikipedia.org/wiki/List_of_tz_database_time_zones|IANA time zone identifier}
* string (e.g. `'Europe/London'`), `Temporal.TimeZone` instance, or an
* object implementing the time zone protocol. If omitted, the environment's
* string (e.g. `'Europe/London'`). If omitted, the environment's
* current time zone will be used.
*/
plainTimeISO: (tzLike?: TimeZoneLike) => Temporal.PlainTime;

View file

@ -844,14 +844,6 @@ function formatRaw(ctx, value, recurseTimes, typedArray, proxyDetails) {
ObjectPrototypeIsPrototypeOf(
globalThis.Temporal.Duration.prototype,
value,
) ||
ObjectPrototypeIsPrototypeOf(
globalThis.Temporal.TimeZone.prototype,
value,
) ||
ObjectPrototypeIsPrototypeOf(
globalThis.Temporal.Calendar.prototype,
value,
)
)
) {

View file

@ -23,6 +23,7 @@ import {
} from "ext:core/ops";
const {
ArrayPrototypeFilter,
ArrayPrototypeForEach,
ArrayPrototypeIncludes,
ArrayPrototypeMap,
DateNow,
@ -35,6 +36,7 @@ const {
ObjectDefineProperty,
ObjectHasOwn,
ObjectKeys,
ObjectGetOwnPropertyDescriptor,
ObjectPrototypeIsPrototypeOf,
ObjectSetPrototypeOf,
PromisePrototypeThen,
@ -747,26 +749,93 @@ function bootstrapMainRuntime(runtimeOptions, warmup = false) {
// Removes the obsoleted `Temporal` API.
// https://github.com/tc39/proposal-temporal/pull/2895
// https://github.com/tc39/proposal-temporal/pull/2914
if (typeof Temporal.Instant.fromEpochSeconds === "undefined") {
// https://github.com/tc39/proposal-temporal/pull/2925
if (typeof globalThis.Temporal.Instant.fromEpochSeconds === "undefined") {
throw "V8 removes obsoleted Temporal API now, no need to delete them!";
}
delete Temporal.Instant.fromEpochSeconds;
delete Temporal.Instant.fromEpochMicroseconds;
delete Temporal.Instant.prototype.epochSeconds;
delete Temporal.Instant.prototype.epochMicroseconds;
delete Temporal.PlainDateTime.prototype.withPlainDate;
delete Temporal.PlainDateTime.prototype.toPlainYearMonth;
delete Temporal.PlainDateTime.prototype.toPlainMonthDay;
delete Temporal.PlainTime.prototype.toPlainDateTime;
delete Temporal.PlainTime.prototype.toZonedDateTime;
delete Temporal.TimeZone.prototype.getNextTransition;
delete Temporal.TimeZone.prototype.getPreviousTransition;
delete Temporal.ZonedDateTime.prototype.withPlainDate;
delete Temporal.ZonedDateTime.prototype.toPlainYearMonth;
delete Temporal.ZonedDateTime.prototype.toPlainMonthDay;
delete Temporal.Now.zonedDateTime;
delete Temporal.Now.plainDateTime;
delete Temporal.Now.plainDate;
delete globalThis.Temporal.Instant.fromEpochSeconds;
delete globalThis.Temporal.Instant.fromEpochMicroseconds;
delete globalThis.Temporal.Instant.prototype.epochSeconds;
delete globalThis.Temporal.Instant.prototype.epochMicroseconds;
delete globalThis.Temporal.Instant.prototype.toZonedDateTime;
delete globalThis.Temporal.PlainDate.prototype.getISOFiels; // weird
delete globalThis.Temporal.PlainDate.prototype.getISOFields;
delete globalThis.Temporal.PlainDateTime.prototype.withPlainDate;
delete globalThis.Temporal.PlainDateTime.prototype.toPlainYearMonth;
delete globalThis.Temporal.PlainDateTime.prototype.toPlainMonthDay;
delete globalThis.Temporal.PlainDateTime.prototype.getISOFields;
delete globalThis.Temporal.PlainMonthDay.prototype.getISOFields;
delete globalThis.Temporal.PlainTime.prototype.calendar;
delete globalThis.Temporal.PlainTime.prototype.toPlainDateTime;
delete globalThis.Temporal.PlainTime.prototype.toZonedDateTime;
delete globalThis.Temporal.PlainTime.prototype.getISOFields;
delete globalThis.Temporal.PlainYearMonth.prototype.getISOFields;
delete globalThis.Temporal.ZonedDateTime.prototype.epochSeconds;
delete globalThis.Temporal.ZonedDateTime.prototype.epochMicroseconds;
delete globalThis.Temporal.ZonedDateTime.prototype.withPlainDate;
delete globalThis.Temporal.ZonedDateTime.prototype.toPlainYearMonth;
delete globalThis.Temporal.ZonedDateTime.prototype.toPlainMonthDay;
delete globalThis.Temporal.ZonedDateTime.prototype.getISOFields;
delete globalThis.Temporal.Now.zonedDateTime;
delete globalThis.Temporal.Now.plainDateTime;
delete globalThis.Temporal.Now.plainDate;
delete globalThis.Temporal.Calendar;
delete globalThis.Temporal.TimeZone;
// Modify `Temporal.Calendar` to calendarId string
ArrayPrototypeForEach([
globalThis.Temporal.PlainDate,
globalThis.Temporal.PlainDateTime,
globalThis.Temporal.PlainMonthDay,
globalThis.Temporal.PlainYearMonth,
globalThis.Temporal.ZonedDateTime,
], (target) => {
const getCalendar =
ObjectGetOwnPropertyDescriptor(target.prototype, "calendar").get;
ObjectDefineProperty(target.prototype, "calendarId", {
__proto__: null,
get: function calendarId() {
return FunctionPrototypeCall(getCalendar, this).id;
},
enumerable: false,
configurable: true,
});
delete target.prototype.calendar;
});
// Modify `Temporal.TimeZone` to timeZoneId string
{
const getTimeZone = ObjectGetOwnPropertyDescriptor(
globalThis.Temporal.ZonedDateTime.prototype,
"timeZone",
).get;
ObjectDefineProperty(
globalThis.Temporal.ZonedDateTime.prototype,
"timeZoneId",
{
__proto__: null,
get: function timeZoneId() {
return FunctionPrototypeCall(getTimeZone, this).id;
},
enumerable: false,
configurable: true,
},
);
delete globalThis.Temporal.ZonedDateTime.prototype.timeZone;
}
{
const nowTimeZone = globalThis.Temporal.Now.timeZone;
ObjectDefineProperty(globalThis.Temporal.Now, "timeZoneId", {
__proto__: null,
value: function timeZoneId() {
return nowTimeZone().id;
},
writable: true,
enumerable: false,
configurable: true,
});
delete globalThis.Temporal.Now.timeZone;
}
}
// Setup `Deno` global - we're actually overriding already existing global
@ -889,26 +958,93 @@ function bootstrapWorkerRuntime(
// Removes the obsoleted `Temporal` API.
// https://github.com/tc39/proposal-temporal/pull/2895
// https://github.com/tc39/proposal-temporal/pull/2914
if (typeof Temporal.Instant.fromEpochSeconds === "undefined") {
// https://github.com/tc39/proposal-temporal/pull/2925
if (typeof globalThis.Temporal.Instant.fromEpochSeconds === "undefined") {
throw "V8 removes obsoleted Temporal API now, no need to delete them!";
}
delete Temporal.Instant.fromEpochSeconds;
delete Temporal.Instant.fromEpochMicroseconds;
delete Temporal.Instant.prototype.epochSeconds;
delete Temporal.Instant.prototype.epochMicroseconds;
delete Temporal.PlainDateTime.prototype.withPlainDate;
delete Temporal.PlainDateTime.prototype.toPlainYearMonth;
delete Temporal.PlainDateTime.prototype.toPlainMonthDay;
delete Temporal.PlainTime.prototype.toPlainDateTime;
delete Temporal.PlainTime.prototype.toZonedDateTime;
delete Temporal.TimeZone.prototype.getNextTransition;
delete Temporal.TimeZone.prototype.getPreviousTransition;
delete Temporal.ZonedDateTime.prototype.withPlainDate;
delete Temporal.ZonedDateTime.prototype.toPlainYearMonth;
delete Temporal.ZonedDateTime.prototype.toPlainMonthDay;
delete Temporal.Now.zonedDateTime;
delete Temporal.Now.plainDateTime;
delete Temporal.Now.plainDate;
delete globalThis.Temporal.Instant.fromEpochSeconds;
delete globalThis.Temporal.Instant.fromEpochMicroseconds;
delete globalThis.Temporal.Instant.prototype.epochSeconds;
delete globalThis.Temporal.Instant.prototype.epochMicroseconds;
delete globalThis.Temporal.Instant.prototype.toZonedDateTime;
delete globalThis.Temporal.PlainDate.prototype.getISOFiels; // weird
delete globalThis.Temporal.PlainDate.prototype.getISOFields;
delete globalThis.Temporal.PlainDateTime.prototype.withPlainDate;
delete globalThis.Temporal.PlainDateTime.prototype.toPlainYearMonth;
delete globalThis.Temporal.PlainDateTime.prototype.toPlainMonthDay;
delete globalThis.Temporal.PlainDateTime.prototype.getISOFields;
delete globalThis.Temporal.PlainMonthDay.prototype.getISOFields;
delete globalThis.Temporal.PlainTime.prototype.calendar;
delete globalThis.Temporal.PlainTime.prototype.toPlainDateTime;
delete globalThis.Temporal.PlainTime.prototype.toZonedDateTime;
delete globalThis.Temporal.PlainTime.prototype.getISOFields;
delete globalThis.Temporal.PlainYearMonth.prototype.getISOFields;
delete globalThis.Temporal.ZonedDateTime.prototype.epochSeconds;
delete globalThis.Temporal.ZonedDateTime.prototype.epochMicroseconds;
delete globalThis.Temporal.ZonedDateTime.prototype.withPlainDate;
delete globalThis.Temporal.ZonedDateTime.prototype.toPlainYearMonth;
delete globalThis.Temporal.ZonedDateTime.prototype.toPlainMonthDay;
delete globalThis.Temporal.ZonedDateTime.prototype.getISOFields;
delete globalThis.Temporal.Now.zonedDateTime;
delete globalThis.Temporal.Now.plainDateTime;
delete globalThis.Temporal.Now.plainDate;
delete globalThis.Temporal.Calendar;
delete globalThis.Temporal.TimeZone;
// Modify `Temporal.Calendar` to calendarId string
ArrayPrototypeForEach([
globalThis.Temporal.PlainDate,
globalThis.Temporal.PlainDateTime,
globalThis.Temporal.PlainMonthDay,
globalThis.Temporal.PlainYearMonth,
globalThis.Temporal.ZonedDateTime,
], (target) => {
const getCalendar =
ObjectGetOwnPropertyDescriptor(target.prototype, "calendar").get;
ObjectDefineProperty(target.prototype, "calendarId", {
__proto__: null,
get: function calendarId() {
return FunctionPrototypeCall(getCalendar, this).id;
},
enumerable: false,
configurable: true,
});
delete target.prototype.calendar;
});
// Modify `Temporal.TimeZone` to timeZoneId string
{
const getTimeZone = ObjectGetOwnPropertyDescriptor(
globalThis.Temporal.ZonedDateTime.prototype,
"timeZone",
).get;
ObjectDefineProperty(
globalThis.Temporal.ZonedDateTime.prototype,
"timeZoneId",
{
__proto__: null,
get: function timeZoneId() {
return FunctionPrototypeCall(getTimeZone, this).id;
},
enumerable: false,
configurable: true,
},
);
delete globalThis.Temporal.ZonedDateTime.prototype.timeZone;
}
{
const nowTimeZone = globalThis.Temporal.Now.timeZone;
ObjectDefineProperty(globalThis.Temporal.Now, "timeZoneId", {
__proto__: null,
value: function timeZoneId() {
return nowTimeZone().id;
},
writable: true,
enumerable: false,
configurable: true,
});
delete globalThis.Temporal.Now.timeZone;
}
}
// Setup `Deno` global - we're actually overriding already existing global

View file

@ -11111,24 +11111,6 @@ fn lsp_workspace_symbol() {
},
"containerName": "B"
},
{
"name": "fields",
"kind": 6,
"location": {
"uri": "deno:/asset/lib.deno.unstable.d.ts",
"range": null,
},
"containerName": "CalendarProtocol"
},
{
"name": "fields",
"kind": 6,
"location": {
"uri": "deno:/asset/lib.deno.unstable.d.ts",
"range": null,
},
"containerName": "Calendar"
},
{
"name": "ClassFieldDecoratorContext",
"kind": 11,
@ -11138,168 +11120,6 @@ fn lsp_workspace_symbol() {
},
"containerName": ""
},
{
"name": "dateFromFields",
"kind": 6,
"location": {
"uri": "deno:/asset/lib.deno.unstable.d.ts",
"range": null,
},
"containerName": "CalendarProtocol"
},
{
"name": "dateFromFields",
"kind": 6,
"location": {
"uri": "deno:/asset/lib.deno.unstable.d.ts",
"range": null,
},
"containerName": "Calendar"
},
{
"name": "getISOFields",
"kind": 6,
"location": {
"uri": "deno:/asset/lib.deno.unstable.d.ts",
"range": null,
},
"containerName": "PlainDate"
},
{
"name": "getISOFields",
"kind": 6,
"location": {
"uri": "deno:/asset/lib.deno.unstable.d.ts",
"range": null,
},
"containerName": "PlainDateTime"
},
{
"name": "getISOFields",
"kind": 6,
"location": {
"uri": "deno:/asset/lib.deno.unstable.d.ts",
"range": null,
},
"containerName": "PlainMonthDay"
},
{
"name": "getISOFields",
"kind": 6,
"location": {
"uri": "deno:/asset/lib.deno.unstable.d.ts",
"range": null,
},
"containerName": "PlainTime"
},
{
"name": "getISOFields",
"kind": 6,
"location": {
"uri": "deno:/asset/lib.deno.unstable.d.ts",
"range": null,
},
"containerName": "PlainYearMonth"
},
{
"name": "getISOFields",
"kind": 6,
"location": {
"uri": "deno:/asset/lib.deno.unstable.d.ts",
"range": null,
},
"containerName": "ZonedDateTime"
},
{
"name": "mergeFields",
"kind": 6,
"location": {
"uri": "deno:/asset/lib.deno.unstable.d.ts",
"range": null,
},
"containerName": "CalendarProtocol"
},
{
"name": "mergeFields",
"kind": 6,
"location": {
"uri": "deno:/asset/lib.deno.unstable.d.ts",
"range": null,
},
"containerName": "Calendar"
},
{
"name": "monthDayFromFields",
"kind": 6,
"location": {
"uri": "deno:/asset/lib.deno.unstable.d.ts",
"range": null,
},
"containerName": "CalendarProtocol"
},
{
"name": "monthDayFromFields",
"kind": 6,
"location": {
"uri": "deno:/asset/lib.deno.unstable.d.ts",
"range": null,
},
"containerName": "Calendar"
},
{
"name": "PlainDateISOFields",
"kind": 5,
"location": {
"uri": "deno:/asset/lib.deno.unstable.d.ts",
"range": null,
},
"containerName": "Temporal"
},
{
"name": "PlainDateTimeISOFields",
"kind": 5,
"location": {
"uri": "deno:/asset/lib.deno.unstable.d.ts",
"range": null,
},
"containerName": "Temporal"
},
{
"name": "PlainTimeISOFields",
"kind": 5,
"location": {
"uri": "deno:/asset/lib.deno.unstable.d.ts",
"range": null,
},
"containerName": "Temporal"
},
{
"name": "yearMonthFromFields",
"kind": 6,
"location": {
"uri": "deno:/asset/lib.deno.unstable.d.ts",
"range": null,
},
"containerName": "CalendarProtocol"
},
{
"name": "yearMonthFromFields",
"kind": 6,
"location": {
"uri": "deno:/asset/lib.deno.unstable.d.ts",
"range": null,
},
"containerName": "Calendar"
},
{
"name": "ZonedDateTimeISOFields",
"kind": 5,
"location": {
"uri": "deno:/asset/lib.deno.unstable.d.ts",
"range": null,
},
"containerName": "Temporal"
}
])
);
client.shutdown();

View file

@ -4731,20 +4731,6 @@ itest!(unsafe_proto_flag {
exit_code: 0,
});
itest!(unstable_temporal_api {
args: "run --no-config --unstable-temporal --check run/unstable_temporal_api/main.ts",
output: "run/unstable_temporal_api/main.out",
http_server: false,
exit_code: 0,
});
itest!(unstable_temporal_api_config_file {
args: "run --check run/unstable_temporal_api/main.ts",
output: "run/unstable_temporal_api/main.out",
http_server: false,
exit_code: 0,
});
// TODO(bartlomieju): temporary disabled
// itest!(warn_on_deprecated_api {
// args: "run -A run/warn_on_deprecated_api/main.js",

View file

@ -0,0 +1,19 @@
{
"tests": {
"basic": {
"args": "run --no-config --unstable-temporal --check main.ts",
"output": "main.out",
"exitCode": 0
},
"config": {
"args": "run --unstable-temporal --check main.ts",
"output": "main.out",
"exitCode": 0
},
"missing_flag": {
"args": "run --no-config missing_flag.js",
"output": "missing_flag.out",
"exitCode": 1
}
}
}

View file

@ -8,5 +8,3 @@ Temporal.PlainDateTime 1995-12-07T15:00:00
Temporal.PlainYearMonth 2020-10
Temporal.PlainMonthDay 07-14
Temporal.Duration PT130H20M
Temporal.TimeZone Africa/Cairo
Temporal.Calendar 1999-12-31

View file

@ -57,15 +57,3 @@ console.log(
minutes: 20,
}),
);
console.log(
"Temporal.TimeZone",
Temporal.TimeZone.from("Africa/Cairo"),
);
console.log(
"Temporal.Calendar",
Temporal.Calendar.from("iso8601").dateFromFields({
year: 1999,
month: 12,
day: 31,
}, {}),
);

View file

@ -0,0 +1 @@
Temporal.Now.instant();

View file

@ -0,0 +1,7 @@
error: Uncaught (in promise) ReferenceError: Temporal is not defined
Temporal.Now.instant();
^
at [WILDCARD]missing_flag.js:1:1
info: Temporal is an unstable API.
hint: Run again with `--unstable-temporal` flag to enable this API.

View file

@ -0,0 +1,5 @@
{
"args": "run --no-config --unstable-temporal --check main.ts",
"output": "main.out",
"exitCode": 0
}

View file

@ -0,0 +1,148 @@
Check [WILDCARD]
Temporal
[
"Duration",
"Instant",
"Now",
"PlainDate",
"PlainDateTime",
"PlainMonthDay",
"PlainTime",
"PlainYearMonth",
"ZonedDateTime"
]
Temporal.Now
[
"instant",
"plainDateISO",
"plainDateTimeISO",
"plainTimeISO",
"timeZoneId",
"zonedDateTimeISO"
]
Temporal.Instant.prototype
[
"add",
"constructor",
"epochMilliseconds",
"epochNanoseconds",
"equals",
"round",
"since",
"subtract",
"toJSON",
"toLocaleString",
"toString",
"toZonedDateTimeISO",
"until",
"valueOf"
]
Temporal.ZonedDateTime.prototype
[
"add", "calendarId", "constructor",
"day", "dayOfWeek", "dayOfYear",
"daysInMonth", "daysInWeek", "daysInYear",
"epochMilliseconds", "epochNanoseconds", "equals",
"era", "eraYear", "hour",
"hoursInDay", "inLeapYear", "microsecond",
"millisecond", "minute", "month",
"monthCode", "monthsInYear", "nanosecond",
"offset", "offsetNanoseconds", "round",
"second", "since", "startOfDay",
"subtract", "timeZoneId", "toInstant",
"toJSON", "toLocaleString", "toPlainDate",
"toPlainDateTime", "toPlainTime", "toString",
"until", "valueOf", "weekOfYear",
"with", "withCalendar", "withPlainTime",
"withTimeZone", "year"
]
Temporal.PlainDate.prototype
[
"add", "calendarId",
"constructor", "day",
"dayOfWeek", "dayOfYear",
"daysInMonth", "daysInWeek",
"daysInYear", "equals",
"era", "eraYear",
"inLeapYear", "month",
"monthCode", "monthsInYear",
"since", "subtract",
"toJSON", "toLocaleString",
"toPlainDateTime", "toPlainMonthDay",
"toPlainYearMonth", "toString",
"toZonedDateTime", "until",
"valueOf", "weekOfYear",
"with", "withCalendar",
"year"
]
Temporal.PlainTime.prototype
[
"add", "constructor",
"equals", "hour",
"microsecond", "millisecond",
"minute", "nanosecond",
"round", "second",
"since", "subtract",
"toJSON", "toLocaleString",
"toString", "until",
"valueOf", "with"
]
Temporal.PlainDateTime.prototype
[
"add", "calendarId", "constructor",
"day", "dayOfWeek", "dayOfYear",
"daysInMonth", "daysInWeek", "daysInYear",
"equals", "era", "eraYear",
"hour", "inLeapYear", "microsecond",
"millisecond", "minute", "month",
"monthCode", "monthsInYear", "nanosecond",
"round", "second", "since",
"subtract", "toJSON", "toLocaleString",
"toPlainDate", "toPlainTime", "toString",
"toZonedDateTime", "until", "valueOf",
"weekOfYear", "with", "withCalendar",
"withPlainTime", "year"
]
Temporal.PlainYearMonth.prototype
[
"add", "calendarId",
"constructor", "daysInMonth",
"daysInYear", "equals",
"era", "eraYear",
"inLeapYear", "month",
"monthCode", "monthsInYear",
"since", "subtract",
"toJSON", "toLocaleString",
"toPlainDate", "toString",
"until", "valueOf",
"with", "year"
]
Temporal.PlainMonthDay.prototype
[
"calendarId",
"constructor",
"day",
"equals",
"monthCode",
"toJSON",
"toLocaleString",
"toPlainDate",
"toString",
"valueOf",
"with"
]
Temporal.Duration.prototype
[
"abs", "add",
"blank", "constructor",
"days", "hours",
"microseconds", "milliseconds",
"minutes", "months",
"nanoseconds", "negated",
"round", "seconds",
"sign", "subtract",
"toJSON", "toLocaleString",
"toString", "total",
"valueOf", "weeks",
"with", "years"
]

View file

@ -0,0 +1,37 @@
console.log("Temporal");
console.log(Object.getOwnPropertyNames(Temporal).sort());
console.log("Temporal.Now");
console.log(Object.getOwnPropertyNames(Temporal.Now).sort());
console.log("Temporal.Instant.prototype");
console.log(Object.getOwnPropertyNames(Temporal.Instant.prototype).sort());
console.log("Temporal.ZonedDateTime.prototype");
console.log(
Object.getOwnPropertyNames(Temporal.ZonedDateTime.prototype).sort(),
);
console.log("Temporal.PlainDate.prototype");
console.log(Object.getOwnPropertyNames(Temporal.PlainDate.prototype).sort());
console.log("Temporal.PlainTime.prototype");
console.log(Object.getOwnPropertyNames(Temporal.PlainTime.prototype).sort());
console.log("Temporal.PlainDateTime.prototype");
console.log(
Object.getOwnPropertyNames(Temporal.PlainDateTime.prototype).sort(),
);
console.log("Temporal.PlainYearMonth.prototype");
console.log(
Object.getOwnPropertyNames(Temporal.PlainYearMonth.prototype).sort(),
);
console.log("Temporal.PlainMonthDay.prototype");
console.log(
Object.getOwnPropertyNames(Temporal.PlainMonthDay.prototype).sort(),
);
console.log("Temporal.Duration.prototype");
console.log(Object.getOwnPropertyNames(Temporal.Duration.prototype).sort());

View file

@ -0,0 +1,5 @@
{
"args": "run --no-config --unstable-temporal --check main.ts",
"output": "main.out",
"exitCode": 0
}

View file

@ -0,0 +1,7 @@
Check [WILDCARD]
[WILDCARD]
undefined
iso8601
UTC
undefined
undefined

View file

@ -0,0 +1,11 @@
console.log(Temporal.Now.timeZoneId());
// @ts-expect-error: undefined check
console.log(Temporal.Now.timeZone);
const zoned = new Temporal.ZonedDateTime(0n, "UTC");
console.log(zoned.calendarId);
console.log(zoned.timeZoneId);
// @ts-expect-error: undefined check
console.log(zoned.calendar);
// @ts-expect-error: undefined check
console.log(zoned.timeZone);

View file

@ -220,7 +220,7 @@ async function ensureNoNewITests() {
"pm_tests.rs": 0,
"publish_tests.rs": 0,
"repl_tests.rs": 0,
"run_tests.rs": 340,
"run_tests.rs": 338,
"shared_library_tests.rs": 0,
"task_tests.rs": 30,
"test_tests.rs": 74,