BREAKING(temporal/unstable): Remove obsoleted Temporal APIs (#24836)

This commit is contained in:
Kenta Moriuchi 2024-08-02 17:56:14 +09:00 committed by GitHub
parent 930ccf928a
commit d2b66e50fd
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 78 additions and 129 deletions

View file

@ -2606,7 +2606,7 @@ declare namespace Temporal {
/** /**
* When the name of a unit is provided to a Temporal API as a string, it is * When the name of a unit is provided to a Temporal API as a string, it is
* usually singular, e.g. 'day' or 'hour'. But plural unit names like 'days' * usually singular, e.g. 'day' or 'hour'. But plural unit names like 'days'
* or 'hours' are aso accepted too. * or 'hours' are also accepted.
* *
* @category Temporal * @category Temporal
* @experimental * @experimental
@ -2925,8 +2925,8 @@ declare namespace Temporal {
* This value must be either a `Temporal.PlainDateTime`, a * This value must be either a `Temporal.PlainDateTime`, a
* `Temporal.ZonedDateTime`, or a string or object value that can be * `Temporal.ZonedDateTime`, or a string or object value that can be
* passed to `from()` of those types. Examples: * passed to `from()` of those types. Examples:
* - `'2020-01'01T00:00-08:00[America/Los_Angeles]'` * - `'2020-01-01T00:00-08:00[America/Los_Angeles]'`
* - `'2020-01'01'` * - `'2020-01-01'`
* - `Temporal.PlainDate.from('2020-01-01')` * - `Temporal.PlainDate.from('2020-01-01')`
* *
* `Temporal.ZonedDateTime` will be tried first because it's more * `Temporal.ZonedDateTime` will be tried first because it's more
@ -2971,8 +2971,8 @@ declare namespace Temporal {
* This value must be either a `Temporal.PlainDateTime`, a * This value must be either a `Temporal.PlainDateTime`, a
* `Temporal.ZonedDateTime`, or a string or object value that can be passed * `Temporal.ZonedDateTime`, or a string or object value that can be passed
* to `from()` of those types. Examples: * to `from()` of those types. Examples:
* - `'2020-01'01T00:00-08:00[America/Los_Angeles]'` * - `'2020-01-01T00:00-08:00[America/Los_Angeles]'`
* - `'2020-01'01'` * - `'2020-01-01'`
* - `Temporal.PlainDate.from('2020-01-01')` * - `Temporal.PlainDate.from('2020-01-01')`
* *
* `Temporal.ZonedDateTime` will be tried first because it's more * `Temporal.ZonedDateTime` will be tried first because it's more
@ -3007,8 +3007,8 @@ declare namespace Temporal {
* This value must be either a `Temporal.PlainDateTime`, a * This value must be either a `Temporal.PlainDateTime`, a
* `Temporal.ZonedDateTime`, or a string or object value that can be passed * `Temporal.ZonedDateTime`, or a string or object value that can be passed
* to `from()` of those types. Examples: * to `from()` of those types. Examples:
* - `'2020-01'01T00:00-08:00[America/Los_Angeles]'` * - `'2020-01-01T00:00-08:00[America/Los_Angeles]'`
* - `'2020-01'01'` * - `'2020-01-01'`
* - `Temporal.PlainDate.from('2020-01-01')` * - `Temporal.PlainDate.from('2020-01-01')`
* *
* `Temporal.ZonedDateTime` will be tried first because it's more * `Temporal.ZonedDateTime` will be tried first because it's more
@ -3027,6 +3027,16 @@ declare namespace Temporal {
| string; | string;
} }
/**
* Options to control behaviour of `ZonedDateTime.prototype.getTimeZoneTransition()`
*
* @category Temporal
* @experimental
*/
export type TransitionDirection = "next" | "previous" | {
direction: "next" | "previous";
};
/** /**
* @category Temporal * @category Temporal
* @experimental * @experimental
@ -3127,9 +3137,7 @@ declare namespace Temporal {
* @experimental * @experimental
*/ */
export class Instant { export class Instant {
static fromEpochSeconds(epochSeconds: number): Temporal.Instant;
static fromEpochMilliseconds(epochMilliseconds: number): Temporal.Instant; static fromEpochMilliseconds(epochMilliseconds: number): Temporal.Instant;
static fromEpochMicroseconds(epochMicroseconds: bigint): Temporal.Instant;
static fromEpochNanoseconds(epochNanoseconds: bigint): Temporal.Instant; static fromEpochNanoseconds(epochNanoseconds: bigint): Temporal.Instant;
static from(item: Temporal.Instant | string): Temporal.Instant; static from(item: Temporal.Instant | string): Temporal.Instant;
static compare( static compare(
@ -3137,9 +3145,7 @@ declare namespace Temporal {
two: Temporal.Instant | string, two: Temporal.Instant | string,
): ComparisonResult; ): ComparisonResult;
constructor(epochNanoseconds: bigint); constructor(epochNanoseconds: bigint);
readonly epochSeconds: number;
readonly epochMilliseconds: number; readonly epochMilliseconds: number;
readonly epochMicroseconds: bigint;
readonly epochNanoseconds: bigint; readonly epochNanoseconds: bigint;
equals(other: Temporal.Instant | string): boolean; equals(other: Temporal.Instant | string): boolean;
add( add(
@ -3300,14 +3306,14 @@ declare namespace Temporal {
| Temporal.PlainDateTime | Temporal.PlainDateTime
| PlainDateLike | PlainDateLike
| string, | string,
): number; ): number | undefined;
yearOfWeek( yearOfWeek(
date: date:
| Temporal.PlainDate | Temporal.PlainDate
| Temporal.PlainDateTime | Temporal.PlainDateTime
| PlainDateLike | PlainDateLike
| string, | string,
): number; ): number | undefined;
daysInWeek( daysInWeek(
date: date:
| Temporal.PlainDate | Temporal.PlainDate
@ -3476,14 +3482,14 @@ declare namespace Temporal {
| Temporal.PlainDateTime | Temporal.PlainDateTime
| PlainDateLike | PlainDateLike
| string, | string,
): number; ): number | undefined;
yearOfWeek( yearOfWeek(
date: date:
| Temporal.PlainDate | Temporal.PlainDate
| Temporal.PlainDateTime | Temporal.PlainDateTime
| PlainDateLike | PlainDateLike
| string, | string,
): number; ): number | undefined;
daysInWeek( daysInWeek(
date: date:
| Temporal.PlainDate | Temporal.PlainDate
@ -3614,11 +3620,10 @@ declare namespace Temporal {
readonly monthCode: string; readonly monthCode: string;
readonly day: number; readonly day: number;
readonly calendarId: string; readonly calendarId: string;
getCalendar(): CalendarProtocol;
readonly dayOfWeek: number; readonly dayOfWeek: number;
readonly dayOfYear: number; readonly dayOfYear: number;
readonly weekOfYear: number; readonly weekOfYear: number | undefined;
readonly yearOfWeek: number; readonly yearOfWeek: number | undefined;
readonly daysInWeek: number; readonly daysInWeek: number;
readonly daysInYear: number; readonly daysInYear: number;
readonly daysInMonth: number; readonly daysInMonth: number;
@ -3755,11 +3760,10 @@ declare namespace Temporal {
readonly microsecond: number; readonly microsecond: number;
readonly nanosecond: number; readonly nanosecond: number;
readonly calendarId: string; readonly calendarId: string;
getCalendar(): CalendarProtocol;
readonly dayOfWeek: number; readonly dayOfWeek: number;
readonly dayOfYear: number; readonly dayOfYear: number;
readonly weekOfYear: number; readonly weekOfYear: number | undefined;
readonly yearOfWeek: number; readonly yearOfWeek: number | undefined;
readonly daysInWeek: number; readonly daysInWeek: number;
readonly daysInYear: number; readonly daysInYear: number;
readonly daysInMonth: number; readonly daysInMonth: number;
@ -3773,9 +3777,6 @@ declare namespace Temporal {
withPlainTime( withPlainTime(
timeLike?: Temporal.PlainTime | PlainTimeLike | string, timeLike?: Temporal.PlainTime | PlainTimeLike | string,
): Temporal.PlainDateTime; ): Temporal.PlainDateTime;
withPlainDate(
dateLike: Temporal.PlainDate | PlainDateLike | string,
): Temporal.PlainDateTime;
withCalendar(calendar: CalendarLike): Temporal.PlainDateTime; withCalendar(calendar: CalendarLike): Temporal.PlainDateTime;
add( add(
durationLike: Temporal.Duration | DurationLike | string, durationLike: Temporal.Duration | DurationLike | string,
@ -3831,8 +3832,6 @@ declare namespace Temporal {
options?: ToInstantOptions, options?: ToInstantOptions,
): Temporal.ZonedDateTime; ): Temporal.ZonedDateTime;
toPlainDate(): Temporal.PlainDate; toPlainDate(): Temporal.PlainDate;
toPlainYearMonth(): Temporal.PlainYearMonth;
toPlainMonthDay(): Temporal.PlainMonthDay;
toPlainTime(): Temporal.PlainTime; toPlainTime(): Temporal.PlainTime;
getISOFields(): PlainDateTimeISOFields; getISOFields(): PlainDateTimeISOFields;
toLocaleString( toLocaleString(
@ -3883,7 +3882,6 @@ declare namespace Temporal {
readonly monthCode: string; readonly monthCode: string;
readonly day: number; readonly day: number;
readonly calendarId: string; readonly calendarId: string;
getCalendar(): CalendarProtocol;
equals(other: Temporal.PlainMonthDay | PlainMonthDayLike | string): boolean; equals(other: Temporal.PlainMonthDay | PlainMonthDayLike | string): boolean;
with( with(
monthDayLike: PlainMonthDayLike, monthDayLike: PlainMonthDayLike,
@ -4013,13 +4011,6 @@ declare namespace Temporal {
| "nanosecond" | "nanosecond"
>, >,
): Temporal.PlainTime; ): Temporal.PlainTime;
toPlainDateTime(
temporalDate: Temporal.PlainDate | PlainDateLike | string,
): Temporal.PlainDateTime;
toZonedDateTime(timeZoneAndDate: {
timeZone: TimeZoneLike;
plainDate: Temporal.PlainDate | PlainDateLike | string;
}): Temporal.ZonedDateTime;
getISOFields(): PlainTimeISOFields; getISOFields(): PlainTimeISOFields;
toLocaleString( toLocaleString(
locales?: string | string[], locales?: string | string[],
@ -4049,12 +4040,6 @@ declare namespace Temporal {
dateTime: Temporal.PlainDateTime | PlainDateTimeLike | string, dateTime: Temporal.PlainDateTime | PlainDateTimeLike | string,
options?: ToInstantOptions, options?: ToInstantOptions,
): Temporal.Instant; ): Temporal.Instant;
getNextTransition?(
startingPoint: Temporal.Instant | string,
): Temporal.Instant | null;
getPreviousTransition?(
startingPoint: Temporal.Instant | string,
): Temporal.Instant | null;
getPossibleInstantsFor( getPossibleInstantsFor(
dateTime: Temporal.PlainDateTime | PlainDateTimeLike | string, dateTime: Temporal.PlainDateTime | PlainDateTimeLike | string,
): Temporal.Instant[]; ): Temporal.Instant[];
@ -4091,7 +4076,6 @@ declare namespace Temporal {
static from(timeZone: TimeZoneLike): Temporal.TimeZone | TimeZoneProtocol; static from(timeZone: TimeZoneLike): Temporal.TimeZone | TimeZoneProtocol;
constructor(timeZoneIdentifier: string); constructor(timeZoneIdentifier: string);
readonly id: string; readonly id: string;
equals(timeZone: TimeZoneLike): boolean;
getOffsetNanosecondsFor(instant: Temporal.Instant | string): number; getOffsetNanosecondsFor(instant: Temporal.Instant | string): number;
getOffsetStringFor(instant: Temporal.Instant | string): string; getOffsetStringFor(instant: Temporal.Instant | string): string;
getPlainDateTimeFor( getPlainDateTimeFor(
@ -4102,12 +4086,6 @@ declare namespace Temporal {
dateTime: Temporal.PlainDateTime | PlainDateTimeLike | string, dateTime: Temporal.PlainDateTime | PlainDateTimeLike | string,
options?: ToInstantOptions, options?: ToInstantOptions,
): Temporal.Instant; ): Temporal.Instant;
getNextTransition(
startingPoint: Temporal.Instant | string,
): Temporal.Instant | null;
getPreviousTransition(
startingPoint: Temporal.Instant | string,
): Temporal.Instant | null;
getPossibleInstantsFor( getPossibleInstantsFor(
dateTime: Temporal.PlainDateTime | PlainDateTimeLike | string, dateTime: Temporal.PlainDateTime | PlainDateTimeLike | string,
): Temporal.Instant[]; ): Temporal.Instant[];
@ -4160,7 +4138,6 @@ declare namespace Temporal {
readonly month: number; readonly month: number;
readonly monthCode: string; readonly monthCode: string;
readonly calendarId: string; readonly calendarId: string;
getCalendar(): CalendarProtocol;
readonly daysInMonth: number; readonly daysInMonth: number;
readonly daysInYear: number; readonly daysInYear: number;
readonly monthsInYear: number; readonly monthsInYear: number;
@ -4272,13 +4249,11 @@ declare namespace Temporal {
readonly microsecond: number; readonly microsecond: number;
readonly nanosecond: number; readonly nanosecond: number;
readonly timeZoneId: string; readonly timeZoneId: string;
getTimeZone(): TimeZoneProtocol;
readonly calendarId: string; readonly calendarId: string;
getCalendar(): CalendarProtocol;
readonly dayOfWeek: number; readonly dayOfWeek: number;
readonly dayOfYear: number; readonly dayOfYear: number;
readonly weekOfYear: number; readonly weekOfYear: number | undefined;
readonly yearOfWeek: number; readonly yearOfWeek: number | undefined;
readonly hoursInDay: number; readonly hoursInDay: number;
readonly daysInWeek: number; readonly daysInWeek: number;
readonly daysInMonth: number; readonly daysInMonth: number;
@ -4299,9 +4274,6 @@ declare namespace Temporal {
withPlainTime( withPlainTime(
timeLike?: Temporal.PlainTime | PlainTimeLike | string, timeLike?: Temporal.PlainTime | PlainTimeLike | string,
): Temporal.ZonedDateTime; ): Temporal.ZonedDateTime;
withPlainDate(
dateLike: Temporal.PlainDate | PlainDateLike | string,
): Temporal.ZonedDateTime;
withCalendar(calendar: CalendarLike): Temporal.ZonedDateTime; withCalendar(calendar: CalendarLike): Temporal.ZonedDateTime;
withTimeZone(timeZone: TimeZoneLike): Temporal.ZonedDateTime; withTimeZone(timeZone: TimeZoneLike): Temporal.ZonedDateTime;
add( add(
@ -4354,11 +4326,12 @@ declare namespace Temporal {
>, >,
): Temporal.ZonedDateTime; ): Temporal.ZonedDateTime;
startOfDay(): Temporal.ZonedDateTime; startOfDay(): Temporal.ZonedDateTime;
getTimeZoneTransition(
direction: TransitionDirection,
): Temporal.ZonedDateTime | null;
toInstant(): Temporal.Instant; toInstant(): Temporal.Instant;
toPlainDateTime(): Temporal.PlainDateTime; toPlainDateTime(): Temporal.PlainDateTime;
toPlainDate(): Temporal.PlainDate; toPlainDate(): Temporal.PlainDate;
toPlainYearMonth(): Temporal.PlainYearMonth;
toPlainMonthDay(): Temporal.PlainMonthDay;
toPlainTime(): Temporal.PlainTime; toPlainTime(): Temporal.PlainTime;
getISOFields(): ZonedDateTimeISOFields; getISOFields(): ZonedDateTimeISOFields;
toLocaleString( toLocaleString(
@ -4395,29 +4368,6 @@ declare namespace Temporal {
*/ */
instant: () => Temporal.Instant; instant: () => Temporal.Instant;
/**
* Get the current calendar date and clock time in a specific calendar and
* time zone.
*
* The `calendar` parameter is required. When using the ISO 8601 calendar or
* if you don't understand the need for or implications of a calendar, then
* a more ergonomic alternative to this method is
* `Temporal.Now.zonedDateTimeISO()`.
*
* @param {CalendarLike} [calendar] - calendar identifier, or
* a `Temporal.Calendar` instance, or an object implementing the calendar
* protocol.
* @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
* current time zone will be used.
*/
zonedDateTime: (
calendar: CalendarLike,
tzLike?: TimeZoneLike,
) => Temporal.ZonedDateTime;
/** /**
* Get the current calendar date and clock time in a specific time zone, * Get the current calendar date and clock time in a specific time zone,
* using the ISO 8601 calendar. * using the ISO 8601 calendar.
@ -4430,34 +4380,6 @@ declare namespace Temporal {
*/ */
zonedDateTimeISO: (tzLike?: TimeZoneLike) => Temporal.ZonedDateTime; zonedDateTimeISO: (tzLike?: TimeZoneLike) => Temporal.ZonedDateTime;
/**
* Get the current calendar date and clock time in a specific calendar and
* time zone.
*
* The calendar is required. When using the ISO 8601 calendar or if you
* don't understand the need for or implications of a calendar, then a more
* ergonomic alternative to this method is `Temporal.Now.plainDateTimeISO`.
*
* Note that the `Temporal.PlainDateTime` type does not persist the time zone,
* but retaining the time zone is required for most time-zone-related use
* cases. Therefore, it's usually recommended to use
* `Temporal.Now.zonedDateTimeISO` or `Temporal.Now.zonedDateTime` instead
* of this function.
*
* @param {CalendarLike} [calendar] - calendar identifier, or
* a `Temporal.Calendar` instance, or an object implementing the calendar
* protocol.
* @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 current time zone will be used.
*/
plainDateTime: (
calendar: CalendarLike,
tzLike?: TimeZoneLike,
) => Temporal.PlainDateTime;
/** /**
* Get the current date and clock time in a specific time zone, using the * Get the current date and clock time in a specific time zone, using the
* ISO 8601 calendar. * ISO 8601 calendar.
@ -4475,27 +4397,6 @@ declare namespace Temporal {
*/ */
plainDateTimeISO: (tzLike?: TimeZoneLike) => Temporal.PlainDateTime; plainDateTimeISO: (tzLike?: TimeZoneLike) => Temporal.PlainDateTime;
/**
* Get the current calendar date in a specific calendar and time zone.
*
* The calendar is required. When using the ISO 8601 calendar or if you
* don't understand the need for or implications of a calendar, then a more
* ergonomic alternative to this method is `Temporal.Now.plainDateISO`.
*
* @param {CalendarLike} [calendar] - calendar identifier, or
* a `Temporal.Calendar` instance, or an object implementing the calendar
* protocol.
* @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 current time zone will be used.
*/
plainDate: (
calendar: CalendarLike,
tzLike?: TimeZoneLike,
) => Temporal.PlainDate;
/** /**
* Get the current date in a specific time zone, using the ISO 8601 * Get the current date in a specific time zone, using the ISO 8601
* calendar. * calendar.

View file

@ -849,6 +849,30 @@ function bootstrapMainRuntime(runtimeOptions, warmup = false) {
// Removes the `Temporal` API. // Removes the `Temporal` API.
delete globalThis.Temporal; delete globalThis.Temporal;
delete globalThis.Date.prototype.toTemporalInstant; delete globalThis.Date.prototype.toTemporalInstant;
} else {
// 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") {
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;
} }
// Setup `Deno` global - we're actually overriding already existing global // Setup `Deno` global - we're actually overriding already existing global
@ -1008,6 +1032,30 @@ function bootstrapWorkerRuntime(
// Removes the `Temporal` API. // Removes the `Temporal` API.
delete globalThis.Temporal; delete globalThis.Temporal;
delete globalThis.Date.prototype.toTemporalInstant; delete globalThis.Date.prototype.toTemporalInstant;
} else {
// 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") {
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;
} }
// Setup `Deno` global - we're actually overriding already existing global // Setup `Deno` global - we're actually overriding already existing global