Skip to content

Commit

Permalink
Specify ZonedDateTime.toPlain{YearMonth,MonthDay}()
Browse files Browse the repository at this point in the history
And make a small adjustment to the polyfill to match.

See: #569
  • Loading branch information
ptomato authored and Ms2ger committed Nov 10, 2020
1 parent db24ae7 commit 5d5ca83
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
8 changes: 4 additions & 4 deletions polyfill/lib/zoneddatetime.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -657,16 +657,16 @@ export class ZonedDateTime {
if (!ES.IsTemporalZonedDateTime(this)) throw new TypeError('invalid receiver');
const YearMonth = GetIntrinsic('%Temporal.PlainYearMonth%');
const calendar = GetSlot(this, CALENDAR);
const fieldNames = ES.CalendarFields(calendar, ['day', 'month', 'year']);
const fields = ES.ToTemporalDateFields(this, fieldNames);
const fieldNames = ES.CalendarFields(calendar, ['month', 'year']);
const fields = ES.ToTemporalYearMonthFields(this, fieldNames);
return calendar.yearMonthFromFields(fields, {}, YearMonth);
}
toPlainMonthDay() {
if (!ES.IsTemporalZonedDateTime(this)) throw new TypeError('invalid receiver');
const MonthDay = GetIntrinsic('%Temporal.PlainMonthDay%');
const calendar = GetSlot(this, CALENDAR);
const fieldNames = ES.CalendarFields(calendar, ['day', 'month', 'year']);
const fields = ES.ToTemporalDateFields(this, fieldNames);
const fieldNames = ES.CalendarFields(calendar, ['day', 'month']);
const fields = ES.ToTemporalMonthDayFields(this, fieldNames);
return calendar.monthDayFromFields(fields, {}, MonthDay);
}
getFields() {
Expand Down
14 changes: 12 additions & 2 deletions spec/zoneddatetime.html
Original file line number Diff line number Diff line change
Expand Up @@ -908,7 +908,12 @@ <h1>Temporal.ZonedDateTime.prototype.toPlainYearMonth ( )</h1>
1. Let _timeZone_ be _zonedDateTime_.[[TimeZone]].
1. Let _instant_ be ? CreateTemporalInstant(_zonedDateTime_.[[Nanoseconds]]).
1. Let _temporalDateTime_ be ? GetTemporalDateTimeFor(_timeZone_, _instant_).
1. Return ? <mark>create via `calendar.yearMonthFromFields()`</mark>.
1. Let _calendar_ be _zonedDateTime_.[[Calendar]].
1. Let _fieldNames_ be ? CalendarFields(_calendar_, « *"month"*, *"year"* »).
1. Let _fields_ be ? ToTemporalYearMonthFields(_temporalDateTime_, _fieldNames_).
1. Let _yearMonthFromFields_ be ? Get(_calendar_, *"yearMonthFromFields"*).
1. Let _options_ be ? OrdinaryObjectCreate(%Object.prototype%).
1. Return ? Call(_yearMonthFromFields_, _calendar_, « _fields_, _options_, %Temporal.PlainMonthDay% »).
</emu-alg>
</emu-clause>

Expand All @@ -923,7 +928,12 @@ <h1>Temporal.ZonedDateTime.prototype.toPlainMonthDay ( )</h1>
1. Let _timeZone_ be _zonedDateTime_.[[TimeZone]].
1. Let _instant_ be ? CreateTemporalInstant(_zonedDateTime_.[[Nanoseconds]]).
1. Let _temporalDateTime_ be ? GetTemporalDateTimeFor(_timeZone_, _instant_).
1. Return ? <mark>create via `calendar.monthDayFromFields()`</mark>.
1. Let _calendar_ be _zonedDateTime_.[[Calendar]].
1. Let _fieldNames_ be ? CalendarFields(_calendar_, « *"day"*, *"month"* »).
1. Let _fields_ be ? ToTemporalMonthDayFields(_temporalDateTime_, _fieldNames_).
1. Let _monthDayFromFields_ be ? Get(_calendar_, *"monthDayFromFields"*).
1. Let _options_ be ? OrdinaryObjectCreate(%Object.prototype%).
1. Return ? Call(_monthDayFromFields_, _calendar_, « _fields_, _options_, %Temporal.PlainMonthDay% »).
</emu-alg>
</emu-clause>

Expand Down

0 comments on commit 5d5ca83

Please sign in to comment.