Skip to content

Commit

Permalink
Normative: Remove getISOFields methods
Browse files Browse the repository at this point in the history
  • Loading branch information
ptomato committed Aug 7, 2024
1 parent ff0c11c commit 48bcc47
Show file tree
Hide file tree
Showing 20 changed files with 14 additions and 385 deletions.
28 changes: 14 additions & 14 deletions docs/cookbook/makeExpandedTemporal.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ class ExpandedPlainDate extends Temporal.PlainDate {

static _convert(plainDate, expandedYear) {
if (plainDate instanceof ExpandedPlainDate) return plainDate;
const f = plainDate.getISOFields();
return new ExpandedPlainDate(expandedYear, f.isoMonth, f.isoDay);
const iso = plainDate.withCalendar('iso8601');
return new ExpandedPlainDate(expandedYear, iso.month, iso.day);
}

static from(item) {
Expand Down Expand Up @@ -92,9 +92,9 @@ class ExpandedPlainDate extends Temporal.PlainDate {

toString() {
const year = formatExpandedYear(this.year);
const { isoMonth, isoDay } = this.getISOFields();
const month = `${isoMonth}`.padStart(2, '0');
const day = `${isoDay}`.padStart(2, '0');
const iso = this.withCalendar('iso8601');
const month = `${iso.month}`.padStart(2, '0');
const day = `${iso.day}`.padStart(2, '0');
return `${year}-${month}-${day}`;
}
}
Expand All @@ -109,17 +109,17 @@ class ExpandedPlainDateTime extends Temporal.PlainDateTime {

static _convert(plainDateTime, expandedYear) {
if (plainDateTime instanceof ExpandedPlainDateTime) return plainDateTime;
const f = plainDateTime.getISOFields();
const iso = plainDateTime.withCalendar('iso8601');
return new ExpandedPlainDateTime(
expandedYear,
f.isoMonth,
f.isoDay,
f.isoHour,
f.isoMinute,
f.isoSecond,
f.isoMillisecond,
f.isoMicrosecond,
f.isoNanosecond
iso.month,
iso.day,
plainDateTime.hour,
plainDateTime.minute,
plainDateTime.second,
plainDateTime.millisecond,
plainDateTime.microsecond,
plainDateTime.nanosecond
);
}

Expand Down
26 changes: 0 additions & 26 deletions docs/plaindate.md
Original file line number Diff line number Diff line change
Expand Up @@ -811,29 +811,3 @@ date = Temporal.PlainDate.from('2006-08-24');
date.toPlainYearMonth(); // => 2006-08
date.toPlainMonthDay(); // => 08-24
```

### date.**getISOFields**(): { isoYear: number, isoMonth: number, isoDay: number, calendar: string | object }

**Returns:** a plain object with properties expressing `date` in the ISO 8601 calendar, as well as the calendar (usually a string, but may be an object) in which `date` is reckoned.

This method is mainly useful if you are implementing a custom calendar.
Most code will not need to use it.

Usage example:

```javascript
date = Temporal.PlainDate.from('2006-08-24');
f = date.getISOFields();
f.isoDay; // => 24
// Fields correspond exactly to constructor arguments:
date2 = new Temporal.PlainDate(f.isoYear, f.isoMonth, f.isoDay, f.calendar);
date.equals(date2); // => true

// Date in other calendar
date = date.withCalendar('hebrew');
date.day; // => 30
date.getISOFields().isoDay; // => 24

// Most likely what you need is this:
date.withCalendar('iso8601').day; // => 24
```
29 changes: 0 additions & 29 deletions docs/plaindatetime.md
Original file line number Diff line number Diff line change
Expand Up @@ -1003,32 +1003,3 @@ dt.toPlainTime(); // => 03:24:30.0000035
dt.toPlainDate().toPlainYearMonth(); // => 1995-12
dt.toPlainDate().toPlainMonthDay(); // => 12-07
```

### datetime.**getISOFields**(): { isoYear: number, isoMonth: number, isoDay: number, isoHour: number, isoMinute: number, isoSecond: number, isoMillisecond: number, isoMicrosecond: number, isoNanosecond: number, calendar: string | object }

**Returns:** a plain object with properties expressing `datetime` in the ISO 8601 calendar, as well as the calendar (usually a string, but may be an object) in which `datetime` is reckoned.

This method is mainly useful if you are implementing a custom calendar.
Most code will not need to use it.

Usage example:

<!-- prettier-ignore-start -->
```javascript
dt = Temporal.PlainDateTime.from('1995-12-07T03:24:30.000003500');
f = dt.getISOFields();
f.isoDay; // => 7
// Fields correspond exactly to constructor arguments:
dt2 = new Temporal.PlainDateTime(f.isoYear, f.isoMonth, f.isoDay, f.isoHour, f.isoMinute,
f.isoSecond, f.isoMillisecond, f.isoMicrosecond, f.isoNanosecond, f.calendar);
dt.equals(dt2); // => true

// Date in other calendar
dt = dt.withCalendar('hebrew');
dt.day; // => 14
dt.getISOFields().isoDay; // => 7

// Most likely what you need is this:
dt.withCalendar('iso8601').day; // => 7
```
<!-- prettier-ignore-end -->
16 changes: 0 additions & 16 deletions docs/plainmonthday.md
Original file line number Diff line number Diff line change
Expand Up @@ -388,19 +388,3 @@ md = Temporal.PlainMonthDay.from({

date = md.toPlainDate({ era: 'reiwa', eraYear: 2 }); // => 2020-01-01[u-ca=japanese]
```

### monthDay.**getISOFields**(): { isoYear: number, isoMonth: number, isoDay: number, calendar: string | object }

**Returns:** a plain object with properties expressing `monthDay` in the ISO 8601 calendar, as well as the calendar (usually a string, but may be an object) in which `monthDay` is reckoned.

This method is mainly useful if you are implementing a custom calendar.
Most code will not need to use it.

The value of the `isoYear` property will be equal to the `referenceISOYear` constructor argument passed when `monthDay` was constructed.

Usage example:

```javascript
md = Temporal.PlainMonthDay.from('08-24');
md.getISOFields().isoDay; // => 24
```
14 changes: 0 additions & 14 deletions docs/plaintime.md
Original file line number Diff line number Diff line change
Expand Up @@ -570,17 +570,3 @@ JSON.parse(str, reviver);
This method overrides `Object.prototype.valueOf()` and always throws an exception.
This is because it's not possible to compare `Temporal.PlainTime` objects with the relational operators `<`, `<=`, `>`, or `>=`.
Use `Temporal.PlainTime.compare()` for this, or `time.equals()` for equality.

### time.**getISOFields**(): { isoHour: number, isoMinute: number, isoSecond: number, isoMillisecond: number, isoMicrosecond: number, isoNanosecond: number }

**Returns:** a plain object with properties expressing `time` in the ISO 8601 calendar.

This method is present for forward compatibility with custom calendars.

Usage example:

```javascript
time = Temporal.PlainTime.from('03:20:00');
f = time.getISOFields();
f.isoHour; // => 3
```
16 changes: 0 additions & 16 deletions docs/plainyearmonth.md
Original file line number Diff line number Diff line change
Expand Up @@ -640,19 +640,3 @@ Usage example:
ym = Temporal.PlainYearMonth.from('2019-06');
ym.toPlainDate({ day: 24 }); // => 2019-06-24
```

### yearMonth.**getISOFields**(): { isoYear: number, isoMonth: number, isoDay: number, calendar: string | object }

**Returns:** a plain object with properties expressing `yearMonth` in the ISO 8601 calendar, as well as the calendar (usually a string, but may be an object) that `yearMonth` is reckoned in.

This method is mainly useful if you are implementing a custom calendar.
Most code will not need to use it.

The value of the `isoDay` property will be equal to the `referenceISODay` constructor argument passed when `yearMonth` was constructed.

Usage example:

```javascript
ym = Temporal.PlainYearMonth.from('2019-06');
ym.getISOFields().isoYear; // => 2019
```
21 changes: 0 additions & 21 deletions docs/zoneddatetime.md
Original file line number Diff line number Diff line change
Expand Up @@ -1487,24 +1487,3 @@ zdt.toPlainTime(); // => 03:24:30
zdt.toPlainDate().toPlainYearMonth(); // => 1995-12
zdt.toPlainDate().toPlainMonthDay(); // => 12-07
```

### zonedDateTime.**getISOFields**(): { isoYear: number, isoMonth: number, isoDay: number, hour: number, minute: number, second: number, millisecond: number, microsecond: number, nanosecond: number, offset: string, timeZone: string | object, calendar: string | object }

**Returns:** a plain object with properties expressing `zonedDateTime` in the ISO 8601 calendar, including all date/time fields as well as the `offset` property, and the calendar and time zone (which are usually strings, but may be objects) in which `zonedDateTime` is reckoned.

This is an advanced method that's mainly useful if you are implementing a custom calendar.
Most developers will not need to use it.

Usage example:

```javascript
// get a Temporal.ZonedDateTime in `hebrew` calendar system
zdt = Temporal.ZonedDateTime.from('2019-02-23T03:24:30.000003500[Europe/Rome]').withCalendar('hebrew');

// Month in Hebrew calendar is month 6 of leap year 5779
zdt.month; // => 6
zdt.getISOFields().isoMonth; // => 2

// Instead of calling getISOFields, the pattern below is recommended for most use cases
zdt.withCalendar('iso8601').month; // => 2
```
50 changes: 0 additions & 50 deletions polyfill/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -622,13 +622,6 @@ export namespace Temporal {
calendar?: CalendarLike;
};

type PlainDateISOFields = {
isoYear: number;
isoMonth: number;
isoDay: number;
calendar: string;
};

/**
* 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
Expand Down Expand Up @@ -685,7 +678,6 @@ export namespace Temporal {
): Temporal.ZonedDateTime;
toPlainYearMonth(): Temporal.PlainYearMonth;
toPlainMonthDay(): Temporal.PlainMonthDay;
getISOFields(): PlainDateISOFields;
toLocaleString(locales?: string | string[], options?: Intl.DateTimeFormatOptions): string;
toJSON(): string;
toString(options?: ShowCalendarOption): string;
Expand All @@ -709,19 +701,6 @@ export namespace Temporal {
calendar?: CalendarLike;
};

type PlainDateTimeISOFields = {
isoYear: number;
isoMonth: number;
isoDay: number;
isoHour: number;
isoMinute: number;
isoSecond: number;
isoMillisecond: number;
isoMicrosecond: number;
isoNanosecond: number;
calendar: string;
};

/**
* A `Temporal.PlainDateTime` represents a calendar date and wall-clock time, with
* a precision in nanoseconds, and without any time zone. Of the Temporal
Expand Down Expand Up @@ -802,7 +781,6 @@ export namespace Temporal {
toZonedDateTime(tzLike: TimeZoneLike, options?: ToInstantOptions): Temporal.ZonedDateTime;
toPlainDate(): Temporal.PlainDate;
toPlainTime(): Temporal.PlainTime;
getISOFields(): PlainDateTimeISOFields;
toLocaleString(locales?: string | string[], options?: Intl.DateTimeFormatOptions): string;
toJSON(): string;
toString(options?: CalendarTypeToStringOptions): string;
Expand Down Expand Up @@ -839,7 +817,6 @@ export namespace Temporal {
equals(other: Temporal.PlainMonthDay | PlainMonthDayLike | string): boolean;
with(monthDayLike: PlainMonthDayLike, options?: AssignmentOptions): Temporal.PlainMonthDay;
toPlainDate(year: { year: number }): Temporal.PlainDate;
getISOFields(): PlainDateISOFields;
toLocaleString(locales?: string | string[], options?: Intl.DateTimeFormatOptions): string;
toJSON(): string;
toString(options?: ShowCalendarOption): string;
Expand All @@ -856,15 +833,6 @@ export namespace Temporal {
nanosecond?: number;
};

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
Expand Down Expand Up @@ -915,7 +883,6 @@ export namespace Temporal {
round(
roundTo: RoundTo<'hour' | 'minute' | 'second' | 'millisecond' | 'microsecond' | 'nanosecond'>
): Temporal.PlainTime;
getISOFields(): PlainTimeISOFields;
toLocaleString(locales?: string | string[], options?: Intl.DateTimeFormatOptions): string;
toJSON(): string;
toString(options?: ToStringPrecisionOptions): string;
Expand Down Expand Up @@ -980,7 +947,6 @@ export namespace Temporal {
options?: DifferenceOptions<'year' | 'month'>
): Temporal.Duration;
toPlainDate(day: { day: number }): Temporal.PlainDate;
getISOFields(): PlainDateISOFields;
toLocaleString(locales?: string | string[], options?: Intl.DateTimeFormatOptions): string;
toJSON(): string;
toString(options?: ShowCalendarOption): string;
Expand All @@ -1006,21 +972,6 @@ export namespace Temporal {
calendar?: CalendarLike;
};

type ZonedDateTimeISOFields = {
isoYear: number;
isoMonth: number;
isoDay: number;
isoHour: number;
isoMinute: number;
isoSecond: number;
isoMillisecond: number;
isoMicrosecond: number;
isoNanosecond: number;
offset: string;
timeZone: string;
calendar: string;
};

export class ZonedDateTime {
static from(
item: Temporal.ZonedDateTime | ZonedDateTimeLike | string,
Expand Down Expand Up @@ -1090,7 +1041,6 @@ export namespace Temporal {
toPlainDateTime(): Temporal.PlainDateTime;
toPlainDate(): Temporal.PlainDate;
toPlainTime(): Temporal.PlainTime;
getISOFields(): ZonedDateTimeISOFields;
toLocaleString(locales?: string | string[], options?: Intl.DateTimeFormatOptions): string;
toJSON(): string;
toString(options?: ZonedDateTimeToStringOptions): string;
Expand Down
9 changes: 0 additions & 9 deletions polyfill/lib/plaindate.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -235,15 +235,6 @@ export class PlainDate {
const { year, month, day } = ES.CalendarMonthDayFromFields(calendar, fields);
return ES.CreateTemporalMonthDay(month, day, calendar, year);
}
getISOFields() {
if (!ES.IsTemporalDate(this)) throw new TypeError('invalid receiver');
return {
calendar: GetSlot(this, CALENDAR),
isoDay: GetSlot(this, ISO_DAY),
isoMonth: GetSlot(this, ISO_MONTH),
isoYear: GetSlot(this, ISO_YEAR)
};
}

static from(item, options = undefined) {
if (ES.IsTemporalDate(item)) {
Expand Down
15 changes: 0 additions & 15 deletions polyfill/lib/plaindatetime.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -397,21 +397,6 @@ export class PlainDateTime {
if (!ES.IsTemporalDateTime(this)) throw new TypeError('invalid receiver');
return ES.TemporalDateTimeToTime(this);
}
getISOFields() {
if (!ES.IsTemporalDateTime(this)) throw new TypeError('invalid receiver');
return {
calendar: GetSlot(this, CALENDAR),
isoDay: GetSlot(this, ISO_DAY),
isoHour: GetSlot(this, ISO_HOUR),
isoMicrosecond: GetSlot(this, ISO_MICROSECOND),
isoMillisecond: GetSlot(this, ISO_MILLISECOND),
isoMinute: GetSlot(this, ISO_MINUTE),
isoMonth: GetSlot(this, ISO_MONTH),
isoNanosecond: GetSlot(this, ISO_NANOSECOND),
isoSecond: GetSlot(this, ISO_SECOND),
isoYear: GetSlot(this, ISO_YEAR)
};
}

static from(item, options = undefined) {
if (ES.IsTemporalDateTime(item)) {
Expand Down
9 changes: 0 additions & 9 deletions polyfill/lib/plainmonthday.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -97,15 +97,6 @@ export class PlainMonthDay {
const { year, month, day } = ES.CalendarDateFromFields(calendar, mergedFields, 'constrain');
return ES.CreateTemporalDate(year, month, day, calendar);
}
getISOFields() {
if (!ES.IsTemporalMonthDay(this)) throw new TypeError('invalid receiver');
return {
calendar: GetSlot(this, CALENDAR),
isoDay: GetSlot(this, ISO_DAY),
isoMonth: GetSlot(this, ISO_MONTH),
isoYear: GetSlot(this, ISO_YEAR)
};
}

static from(item, options = undefined) {
if (ES.IsTemporalMonthDay(item)) {
Expand Down
12 changes: 0 additions & 12 deletions polyfill/lib/plaintime.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -214,18 +214,6 @@ export class PlainTime {
ES.ValueOfThrows('PlainTime');
}

getISOFields() {
if (!ES.IsTemporalTime(this)) throw new TypeError('invalid receiver');
return {
isoHour: GetSlot(this, ISO_HOUR),
isoMicrosecond: GetSlot(this, ISO_MICROSECOND),
isoMillisecond: GetSlot(this, ISO_MILLISECOND),
isoMinute: GetSlot(this, ISO_MINUTE),
isoNanosecond: GetSlot(this, ISO_NANOSECOND),
isoSecond: GetSlot(this, ISO_SECOND)
};
}

static from(item, options = undefined) {
if (ES.IsTemporalTime(item)) {
ES.GetTemporalOverflowOption(ES.GetOptionsObject(options));
Expand Down
Loading

0 comments on commit 48bcc47

Please sign in to comment.