Skip to content

Commit

Permalink
Normative: Remove Plain/ZonedDateTime to PlainYearMonth/MonthDay APIs
Browse files Browse the repository at this point in the history
Closes: #2848
  • Loading branch information
ptomato committed Jun 13, 2024
1 parent a6cffb2 commit efebfa2
Show file tree
Hide file tree
Showing 7 changed files with 10 additions and 118 deletions.
16 changes: 5 additions & 11 deletions docs/plaindatetime.md
Original file line number Diff line number Diff line change
Expand Up @@ -986,29 +986,23 @@ If the result is earlier or later than the range that `Temporal.ZonedDateTime` c

**Returns:** a `Temporal.PlainDate` object that is the same as the date portion of `datetime`.

### datetime.**toPlainYearMonth**() : Temporal.PlainYearMonth

**Returns:** a `Temporal.PlainYearMonth` object that is the same as the year and month of `datetime`.

### datetime.**toPlainMonthDay**() : Temporal.PlainMonthDay

**Returns:** a `Temporal.PlainMonthDay` object that is the same as the month and day of `datetime`.

### datetime.**toPlainTime**() : Temporal.PlainTime

**Returns:** a `Temporal.PlainTime` object that is the same as the wall-clock time portion of `datetime`.

The above four methods can be used to convert `Temporal.PlainDateTime` into a `Temporal.PlainDate`, `Temporal.PlainYearMonth`, `Temporal.PlainMonthDay`, or `Temporal.PlainTime` respectively.
The above two methods can be used to convert `Temporal.PlainDateTime` into a `Temporal.PlainDate` or `Temporal.PlainTime` respectively.
The converted object carries a copy of all the relevant fields of `datetime` (for example, in `toPlainDate()`, the `year`, `month`, and `day` properties are copied.)

To convert to `Temporal.PlainYearMonth` or `Temporal.PlainMonthDay`, first use `toPlainDate()` and go from there.

Usage example:

```javascript
dt = Temporal.PlainDateTime.from('1995-12-07T03:24:30.000003500');
dt.toPlainDate(); // => 1995-12-07
dt.toPlainYearMonth(); // => 1995-12
dt.toPlainMonthDay(); // => 12-07
dt.toPlainTime(); // => 03:24:30.0000035
dt.toPlainDate().toPlainYearMonth(); // => 1995-12
dt.toPlainDate().toPlainMonthDay(); // => 12-07
```

### datetime.**getCalendar**(): object
Expand Down
16 changes: 5 additions & 11 deletions docs/zoneddatetime.md
Original file line number Diff line number Diff line change
Expand Up @@ -1355,27 +1355,21 @@ Use `Temporal.ZonedDateTime.compare()` for this, or `zonedDateTime.equals()` for
> However, unless you perform those operations across a time zone offset transition, it's impossible to notice the difference.
> Therefore, be very careful when performing this conversion because subsequent results may look correct most of the time while failing around time zone transitions like when DST starts or ends.
### zonedDateTime.**toPlainYearMonth**() : Temporal.PlainYearMonth

**Returns:** a `Temporal.PlainYearMonth` object that is the same as the year and month of `zonedDateTime`.

### zonedDateTime.**toPlainMonthDay**() : Temporal.PlainMonthDay

**Returns:** a `Temporal.PlainMonthDay` object that is the same as the month and day of `zonedDateTime`.

The above six methods can be used to convert `Temporal.ZonedDateTime` into a `Temporal.Instant`, `Temporal.PlainDate`, `Temporal.PlainTime`, `Temporal.PlainDateTime`, `Temporal.PlainYearMonth`, or `Temporal.PlainMonthDay` respectively.
The above four methods can be used to convert `Temporal.ZonedDateTime` into a `Temporal.Instant`, `Temporal.PlainDate`, `Temporal.PlainTime`, or `Temporal.PlainDateTime`, respectively.
The converted object carries a copy of all the relevant data of `zonedDateTime` (for example, in `toPlainDate()`, the `year`, `month`, and `day` properties are the same.)

To convert to `Temporal.PlainYearMonth` or `Temporal.PlainMonthDay`, first use `toPlainDate()` and go from there.

Usage example:

```javascript
zdt = Temporal.ZonedDateTime.from('1995-12-07T03:24:30+02:00[Africa/Johannesburg]');
zdt.toInstant(); // => 1995-12-07T01:24:30Z
zdt.toPlainDateTime(); // => 1995-12-07T03:24:30
zdt.toPlainDate(); // => 1995-12-07
zdt.toPlainYearMonth(); // => 1995-12
zdt.toPlainMonthDay(); // => 12-07
zdt.toPlainTime(); // => 03:24:30
zdt.toPlainDate().toPlainYearMonth(); // => 1995-12
zdt.toPlainDate().toPlainMonthDay(); // => 12-07
```

### zonedDateTime.**getCalendar**(): object
Expand Down
4 changes: 0 additions & 4 deletions polyfill/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -960,8 +960,6 @@ export namespace Temporal {
): Temporal.PlainDateTime;
toZonedDateTime(tzLike: TimeZoneLike, options?: ToInstantOptions): Temporal.ZonedDateTime;
toPlainDate(): Temporal.PlainDate;
toPlainYearMonth(): Temporal.PlainYearMonth;
toPlainMonthDay(): Temporal.PlainMonthDay;
toPlainTime(): Temporal.PlainTime;
getISOFields(): PlainDateTimeISOFields;
toLocaleString(locales?: string | string[], options?: Intl.DateTimeFormatOptions): string;
Expand Down Expand Up @@ -1306,8 +1304,6 @@ export namespace Temporal {
toInstant(): Temporal.Instant;
toPlainDateTime(): Temporal.PlainDateTime;
toPlainDate(): Temporal.PlainDate;
toPlainYearMonth(): Temporal.PlainYearMonth;
toPlainMonthDay(): Temporal.PlainMonthDay;
toPlainTime(): Temporal.PlainTime;
getISOFields(): ZonedDateTimeISOFields;
toLocaleString(locales?: string | string[], options?: Intl.DateTimeFormatOptions): string;
Expand Down
12 changes: 0 additions & 12 deletions polyfill/lib/plaindatetime.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -379,18 +379,6 @@ export class PlainDateTime {
if (!ES.IsTemporalDateTime(this)) throw new TypeError('invalid receiver');
return ES.TemporalDateTimeToDate(this);
}
toPlainYearMonth() {
if (!ES.IsTemporalDateTime(this)) throw new TypeError('invalid receiver');
const calendarRec = new CalendarMethodRecord(GetSlot(this, CALENDAR), ['fields', 'yearMonthFromFields']);
const fields = ES.PrepareCalendarFields(calendarRec, this, ['monthCode', 'year'], [], []);
return ES.CalendarYearMonthFromFields(calendarRec, fields);
}
toPlainMonthDay() {
if (!ES.IsTemporalDateTime(this)) throw new TypeError('invalid receiver');
const calendarRec = new CalendarMethodRecord(GetSlot(this, CALENDAR), ['fields', 'monthDayFromFields']);
const fields = ES.PrepareCalendarFields(calendarRec, this, ['day', 'monthCode'], [], []);
return ES.CalendarMonthDayFromFields(calendarRec, fields);
}
toPlainTime() {
if (!ES.IsTemporalDateTime(this)) throw new TypeError('invalid receiver');
return ES.TemporalDateTimeToTime(this);
Expand Down
14 changes: 0 additions & 14 deletions polyfill/lib/zoneddatetime.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -557,20 +557,6 @@ export class ZonedDateTime {
if (!ES.IsTemporalZonedDateTime(this)) throw new TypeError('invalid receiver');
return dateTime(this);
}
toPlainYearMonth() {
if (!ES.IsTemporalZonedDateTime(this)) throw new TypeError('invalid receiver');
const calendarRec = new CalendarMethodRecord(GetSlot(this, CALENDAR), ['fields', 'yearMonthFromFields']);
const dt = dateTime(this);
const fields = ES.PrepareCalendarFields(calendarRec, dt, ['monthCode', 'year'], [], []);
return ES.CalendarYearMonthFromFields(calendarRec, fields);
}
toPlainMonthDay() {
if (!ES.IsTemporalZonedDateTime(this)) throw new TypeError('invalid receiver');
const calendarRec = new CalendarMethodRecord(GetSlot(this, CALENDAR), ['fields', 'monthDayFromFields']);
const dt = dateTime(this);
const fields = ES.PrepareCalendarFields(calendarRec, dt, ['day', 'monthCode'], [], []);
return ES.CalendarMonthDayFromFields(calendarRec, fields);
}
getISOFields() {
if (!ES.IsTemporalZonedDateTime(this)) throw new TypeError('invalid receiver');
const timeZoneRec = new TimeZoneMethodRecord(GetSlot(this, TIME_ZONE), ['getOffsetNanosecondsFor']);
Expand Down
30 changes: 0 additions & 30 deletions spec/plaindatetime.html
Original file line number Diff line number Diff line change
Expand Up @@ -672,36 +672,6 @@ <h1>Temporal.PlainDateTime.prototype.toPlainDate ( )</h1>
</emu-alg>
</emu-clause>

<emu-clause id="sec-temporal.plaindatetime.prototype.toplainyearmonth">
<h1>Temporal.PlainDateTime.prototype.toPlainYearMonth ( )</h1>
<p>
This method performs the following steps when called:
</p>
<emu-alg>
1. Let _dateTime_ be the *this* value.
1. Perform ? RequireInternalSlot(_dateTime_, [[InitializedTemporalDateTime]]).
1. Let _calendarRec_ be ? CreateCalendarMethodsRecord(_dateTime_.[[Calendar]], « ~fields~, ~year-month-from-fields~ »).
1. Let _fields_ be ? PrepareCalendarFields(_calendarRec_, _dateTime_, « *"monthCode"*, *"year"* », «», «»).
1. Return ? CalendarYearMonthFromFields(_calendarRec_, _fields_).
1. NOTE: The call to CalendarYearMonthFromFields is necessary in order to create a PlainYearMonth object with the [[ISOYear]], [[ISOMonth]], and [[ISODay]] internal slots set correctly.
</emu-alg>
</emu-clause>

<emu-clause id="sec-temporal.plaindatetime.prototype.toplainmonthday">
<h1>Temporal.PlainDateTime.prototype.toPlainMonthDay ( )</h1>
<p>
This method performs the following steps when called:
</p>
<emu-alg>
1. Let _dateTime_ be the *this* value.
1. Perform ? RequireInternalSlot(_dateTime_, [[InitializedTemporalDateTime]]).
1. Let _calendarRec_ be ? CreateCalendarMethodsRecord(_dateTime_.[[Calendar]], « ~fields~, ~month-day-from-fields~ »).
1. Let _fields_ be ? PrepareCalendarFields(_calendarRec_, _dateTime_, « *"day"*, *"monthCode"* », «», «»).
1. Return ? CalendarMonthDayFromFields(_calendarRec_, _fields_).
1. NOTE: The call to CalendarMonthDayFromFields is necessary in order to create a PlainMonthDay object with the [[ISOYear]], [[ISOMonth]], and [[ISODay]] internal slots set correctly.
</emu-alg>
</emu-clause>

<emu-clause id="sec-temporal.plaindatetime.prototype.toplaintime">
<h1>Temporal.PlainDateTime.prototype.toPlainTime ( )</h1>
<p>
Expand Down
36 changes: 0 additions & 36 deletions spec/zoneddatetime.html
Original file line number Diff line number Diff line change
Expand Up @@ -934,42 +934,6 @@ <h1>Temporal.ZonedDateTime.prototype.toPlainDateTime ( )</h1>
</emu-alg>
</emu-clause>

<emu-clause id="sec-temporal.zoneddatetime.prototype.toplainyearmonth">
<h1>Temporal.ZonedDateTime.prototype.toPlainYearMonth ( )</h1>
<p>
This method performs the following steps when called:
</p>
<emu-alg>
1. Let _zonedDateTime_ be the *this* value.
1. Perform ? RequireInternalSlot(_zonedDateTime_, [[InitializedTemporalZonedDateTime]]).
1. Let _calendarRec_ be ? CreateCalendarMethodsRecord(_zonedDateTime_.[[Calendar]], « ~fields~, ~year-month-from-fields~ »).
1. Let _timeZoneRec_ be ? CreateTimeZoneMethodsRecord(_zonedDateTime_.[[TimeZone]], « ~get-offset-nanoseconds-for~ »).
1. Let _instant_ be ! CreateTemporalInstant(_zonedDateTime_.[[Nanoseconds]]).
1. Let _temporalDateTime_ be ? GetPlainDateTimeFor(_timeZoneRec_, _instant_, _calendarRec_.[[Receiver]]).
1. Let _fields_ be ? PrepareCalendarFields(_calendarRec_, _temporalDateTime_, « *"monthCode"*, *"year"* », «», «»).
1. Return ? CalendarYearMonthFromFields(_calendarRec_, _fields_).
1. NOTE: The call to CalendarYearMonthFromFields is necessary in order to create a PlainYearMonth object with the [[ISOYear]], [[ISOMonth]], and [[ISODay]] internal slots set correctly.
</emu-alg>
</emu-clause>

<emu-clause id="sec-temporal.zoneddatetime.prototype.toplainmonthday">
<h1>Temporal.ZonedDateTime.prototype.toPlainMonthDay ( )</h1>
<p>
This method performs the following steps when called:
</p>
<emu-alg>
1. Let _zonedDateTime_ be the *this* value.
1. Perform ? RequireInternalSlot(_zonedDateTime_, [[InitializedTemporalZonedDateTime]]).
1. Let _calendarRec_ be ? CreateCalendarMethodsRecord(_zonedDateTime_.[[Calendar]], « ~fields~, ~month-day-from-fields~ »).
1. Let _timeZoneRec_ be ? CreateTimeZoneMethodsRecord(_zonedDateTime_.[[TimeZone]], « ~get-offset-nanoseconds-for~ »).
1. Let _instant_ be ! CreateTemporalInstant(_zonedDateTime_.[[Nanoseconds]]).
1. Let _temporalDateTime_ be ? GetPlainDateTimeFor(_timeZoneRec_, _instant_, _calendarRec_.[[Receiver]]).
1. Let _fields_ be ? PrepareCalendarFields(_calendarRec_, _temporalDateTime_, « *"day"*, *"monthCode"* », «», «»).
1. Return ? CalendarMonthDayFromFields(_calendarRec_, _fields_).
1. NOTE: The call to CalendarMonthDayFromFields is necessary in order to create a PlainMonthDay object with the [[ISOYear]], [[ISOMonth]], and [[ISODay]] internal slots set correctly.
</emu-alg>
</emu-clause>

<emu-clause id="sec-temporal.zoneddatetime.prototype.getisofields">
<h1>Temporal.ZonedDateTime.prototype.getISOFields ( )</h1>
<p>
Expand Down

0 comments on commit efebfa2

Please sign in to comment.