Skip to content

Commit

Permalink
Remove options argument from MonthDay.toPlainDate.
Browse files Browse the repository at this point in the history
See #889.
  • Loading branch information
Ms2ger authored and ryzokuken committed Nov 6, 2020
1 parent 5f0ee24 commit f93f37f
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 18 deletions.
8 changes: 1 addition & 7 deletions docs/monthday.md
Original file line number Diff line number Diff line change
Expand Up @@ -296,16 +296,11 @@ This method overrides `Object.prototype.valueOf()` and always throws an exceptio
This is because it's not possible to compare `Temporal.PlainMonthDay` objects with the relational operators `<`, `<=`, `>`, or `>=`.
Instead, use `monthDay.equals()` to check for equality.

### monthDay.**toPlainDate**(_year_: object, _options_?: object) : Temporal.PlainDate
### monthDay.**toPlainDate**(_year_: object) : Temporal.PlainDate

**Parameters:**

- `year` (object): An object with a `'year'` property, which must have a day corresponding to `monthDay`.
- `options` (optional object): An object with properties representing options for the operation.
The following options are recognized:
- `overflow` (string): How to deal with out-of-range values.
Allowed values are `constrain` and `reject`.
The default is `constrain`.

**Returns:** a `Temporal.PlainDate` object that represents the calendar date of `monthDay` in `year`.

Expand All @@ -321,7 +316,6 @@ md.toPlainDate({ year: 2017 }); // => 2017-08-24
md = Temporal.PlainMonthDay.from('02-29');
md.toPlainDate({ year: 2020 }); // => 2020-02-29
md.toPlainDate({ year: 2017 }); // => 2017-02-28
md.toPlainDate({ year: 2017 }, { overflow: 'reject' }); // throws
```

In calendars where more information than just the year is needed to convert a `Temporal.PlainMonthDay` to a `Temporal.PlainDate`, you can pass the necessary properties in the _year_ object.
Expand Down
2 changes: 1 addition & 1 deletion polyfill/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1028,7 +1028,7 @@ export namespace Temporal {
readonly calendar: CalendarProtocol;
equals(other: Temporal.PlainMonthDay | MonthDayLike | string): boolean;
with(monthDayLike: MonthDayLike, options?: AssignmentOptions): Temporal.PlainMonthDay;
toPlainDate(year: { year: number }, options?: AssignmentOptions): Temporal.PlainDate;
toPlainDate(year: { year: number }): Temporal.PlainDate;
getFields(): MonthDayFields;
getISOFields(): DateISOFields;
toLocaleString(locales?: string | string[], options?: Intl.DateTimeFormatOptions): string;
Expand Down
4 changes: 2 additions & 2 deletions polyfill/lib/plainmonthday.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ export class PlainMonthDay {
valueOf() {
throw new TypeError('use equals() to compare Temporal.PlainMonthDay');
}
toPlainDate(item, options = undefined) {
toPlainDate(item) {
if (!ES.IsTemporalMonthDay(this)) throw new TypeError('invalid receiver');
const calendar = GetSlot(this, CALENDAR);

Expand All @@ -134,7 +134,7 @@ export class PlainMonthDay {
ObjectAssign(fields, ES.ToRecord(item, entries));

const Date = GetIntrinsic('%Temporal.PlainDate%');
return calendar.dateFromFields(fields, options, Date);
return calendar.dateFromFields(fields, { overflow: 'constrain' }, Date);
}
getFields() {
if (!ES.IsTemporalMonthDay(this)) throw new TypeError('invalid receiver');
Expand Down
4 changes: 0 additions & 4 deletions polyfill/test/plainmonthday.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -208,10 +208,6 @@ describe('MonthDay', () => {
equal(`${leapDay.toPlainDate({ year: 2019 })}`, '2019-02-28');
equal(`${leapDay.toPlainDate({ year: 2019 }, { overflow: 'constrain' })}`, '2019-02-28');
});
it("can also reject if the MonthDay doesn't exist in the year", () => {
const leapDay = PlainMonthDay.from('02-29');
throws(() => leapDay.toPlainDate({ year: 2019 }, { overflow: 'reject' }));
});
});
describe('MonthDay.toString()', () => {
const md1 = PlainMonthDay.from('11-18');
Expand Down
6 changes: 2 additions & 4 deletions spec/plainmonthday.html
Original file line number Diff line number Diff line change
Expand Up @@ -223,16 +223,14 @@ <h1>Temporal.PlainMonthDay.prototype.valueOf ( )</h1>
</emu-clause>

<emu-clause id="sec-temporal.monthday.prototype.toplaindate">
<h1>Temporal.PlainMonthDay.prototype.toPlainDate ( _item_ [ , _options_ ] )</h1>
<h1>Temporal.PlainMonthDay.prototype.toPlainDate ( _item_ )</h1>
<p>
The `toPlainDate` method takes two arguments, _item_ and _options_.
The `toPlainDate` method takes one argument _item_.
The following steps are taken:
</p>
<emu-alg>
1. Let _monthDay_ be the *this* value.
1. Perform ? RequireInternalSlot(_monthDay_, [[InitializedTemporalMonthDay]]).
1. Set _options_ to ? NormalizeOptionsObject(_options_).
1. Let _overflow_ be ? ToTemporalOverflow(_options_).
1. Let _calendar_ be _monthDay_.[[Calendar]].
1. Let _receiverFieldNames_ be ? CalendarFields(_calendar_, « *"day"*, *"month"* »).
1. Let _fields_ be ? ToTemporalMonthDayFields(_monthDay_, _receiverFieldNames_).
Expand Down

0 comments on commit f93f37f

Please sign in to comment.