Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Partial spec for ZonedDateTime #1044

Merged
merged 4 commits into from
Oct 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions docs/zoneddatetime.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ The `Temporal.ZonedDateTime` API is a superset of `Temporal.DateTime`, which mak

## Constructor

### **new Temporal.ZonedDateTime**(_epochNanoseconds_: bigint, _timeZone_: string | object, _calendar_: string | object) : Temporal.ZonedDateTime
### **new Temporal.ZonedDateTime**(_epochNanoseconds_: bigint, _timeZone_: string | object, _calendar_?: string | object) : Temporal.ZonedDateTime

**Parameters:**

Expand Down Expand Up @@ -1218,9 +1218,9 @@ zdt.toMonthDay(); // => 12-07
zdt.toTime(); // => 03:24:30
```

### zonedDateTime.**getFields**() : { year: number, month: number, day: number, hour: number, minute: number, second: number, millisecond: number, microsecond: number, nanosecond: number, calendar: object, [propName: string]: unknown }
### zonedDateTime.**getFields**() : { year: number, month: number, day: number, hour: number, minute: number, second: number, millisecond: number, microsecond: number, nanosecond: number, offset: string, timeZone: object, calendar: object, [propName: string]: unknown }

**Returns:** a plain object with properties equal to the fields of `zonedDateTime`, including all date/time fields (expressed in the current calendar) as well as the `calendar`, `timeZone`, and `offsetNanoseconds` properties.
**Returns:** a plain object with properties equal to the fields of `zonedDateTime`, including all date/time fields (expressed in the current calendar) as well as the `calendar`, `timeZone`, and `offset` properties.

This method can be used to convert a `Temporal.ZonedDateTime` into a record-like data structure.
It returns a new plain JavaScript object, with all the fields as enumerable, writable, own data properties.
Expand Down Expand Up @@ -1263,9 +1263,9 @@ JSON.stringify(thisWillWork, undefined, 2);
// }"
```

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

**Returns:** a plain object with properties expressing `zonedDateTime` in the ISO 8601 calendar, including all date/time fields as well as the `calendar`, `timeZone`, and `offsetNanoseconds` properties.
**Returns:** a plain object with properties expressing `zonedDateTime` in the ISO 8601 calendar, including all date/time fields as well as the `calendar`, `timeZone`, and `offset` properties.
Note that date/time properties have different names with an `iso` prefix to better differentiate from "normal" `getFields` results.

This is an advanced method that's mainly useful if you are implementing a custom calendar.
Expand Down
6 changes: 6 additions & 0 deletions polyfill/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,7 @@ export namespace Temporal {
toLocaleString(locales?: string | string[], options?: Intl.DateTimeFormatOptions): string;
toJSON(): string;
toString(tzLike?: TimeZoneProtocol | string, options?: ToStringOptions): string;
valueOf(): never;
}

export interface CalendarProtocol {
Expand Down Expand Up @@ -656,6 +657,7 @@ export namespace Temporal {
toLocaleString(locales?: string | string[], options?: Intl.DateTimeFormatOptions): string;
toJSON(): string;
toString(): string;
valueOf(): never;
}

export type DateTimeLike = {
Expand Down Expand Up @@ -824,6 +826,7 @@ export namespace Temporal {
toLocaleString(locales?: string | string[], options?: Intl.DateTimeFormatOptions): string;
toJSON(): string;
toString(options?: ToStringOptions): string;
valueOf(): never;
}

export type MonthDayLike = {
Expand Down Expand Up @@ -859,6 +862,7 @@ export namespace Temporal {
toLocaleString(locales?: string | string[], options?: Intl.DateTimeFormatOptions): string;
toJSON(): string;
toString(): string;
valueOf(): never;
}

export type TimeLike = {
Expand Down Expand Up @@ -976,6 +980,7 @@ export namespace Temporal {
toLocaleString(locales?: string | string[], options?: Intl.DateTimeFormatOptions): string;
toJSON(): string;
toString(options?: ToStringOptions): string;
valueOf(): never;
}

/**
Expand Down Expand Up @@ -1074,6 +1079,7 @@ export namespace Temporal {
toLocaleString(locales?: string | string[], options?: Intl.DateTimeFormatOptions): string;
toJSON(): string;
toString(): string;
valueOf(): never;
}

/**
Expand Down
1 change: 1 addition & 0 deletions spec.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ <h1>Introduction</h1>
<emu-import href="spec/date.html"></emu-import>
<emu-import href="spec/time.html"></emu-import>
<emu-import href="spec/datetime.html"></emu-import>
<emu-import href="spec/zoneddatetime.html"></emu-import>
<emu-import href="spec/duration.html"></emu-import>
<emu-import href="spec/instant.html"></emu-import>
<emu-import href="spec/yearmonth.html"></emu-import>
Expand Down
11 changes: 11 additions & 0 deletions spec/abstractops.html
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,17 @@ <h1>NegateTemporalRoundingMode ( _roundingMode_ )</h1>
</emu-alg>
</emu-clause>

<emu-clause id="sec-temporal-totemporaloffset" aoid="ToTemporalOffset">
<h1>ToTemporalOffset ( _normalizedOptions_, _fallback_ )</h1>
<p>
The abstract operation ToTemporalOffset extracts the value of the property named *"offset"* from _normalizedOptions_ and makes sure it is a valid value for the option.
The value _fallback_ is returned if the property is not present.
</p>
<emu-alg>
1. Return ? GetOption(_normalizedOptions_, *"offset"*, *"string"*, « *"prefer"*, *"use"*, *"ignore"*, *"reject"* », _fallback_).
</emu-alg>
</emu-clause>

<emu-clause id="sec-temporal-totemporalroundingincrement" aoid="ToTemporalRoundingIncrement">
<h1>ToTemporalRoundingIncrement ( _normalizedOptions_, _dividend_, _inclusive_ )</h1>
<emu-alg>
Expand Down
11 changes: 11 additions & 0 deletions spec/intl.html
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,11 @@ <h1>InitializeDateTimeFormat ( _dateTimeFormat_, _locales_, _options_ )</h1>
<td>[[weekday]], [[era]], [[year]], [[month]], [[day]], [[hour]], [[minute]], [[second]], [[dayPeriod]], [[fractionalSecondDigits]]</td>
<td>[[year]], [[month]], [[day]], [[hour]], [[minute]], [[second]]</td>
</tr>
<tr>
<th>[[TemporalZonedDateTimePattern]]</th>
<td>[[weekday]], [[era]], [[year]], [[month]], [[day]], [[hour]], [[minute]], [[second]], [[dayPeriod]], [[fractionalSecondDigits]], [[timeZoneName]]</td>
<td>[[year]], [[month]], [[day]], [[hour]], [[minute]], [[second]], [[timeZoneName]]</td>
</tr>
</tbody>
</table>
</emu-table>
Expand Down Expand Up @@ -309,6 +314,12 @@ <h1>PartitionDateTimePattern ( _dateTimeFormat_, _x_ )</h1>
1. <ins>If _calendar_ is not *"iso8601"* and not equal to _dateTimeFormat_.[[Calendar]], throw a *RangeError* exception.</ins>
1. <ins>Let _pattern_ be _dateTimeFormat_.[[TemporalDateTimePattern]].</ins>
1. <ins>Let _tm_ be { [[weekday]]: ToDayOfWeek(_x_.[[ISOYear]], _x_.[[ISOMonth]], _x_.[[ISODay]]), [[year]]: _x_.[[ISOYear]], [[month]]: _x_.[[ISOMonth]], [[day]]: _x_.[[ISODay]], [[hour]]: _x_.[[Hour]], [[minute]]: _x_.[[Minute]], [[second]]: _x_.[[Second]] }.</ins>
1. <ins>If _date_ has an [[InitializedTemporalZonedDateTime]] internal slot, then</ins>
1. <ins>Let _calendar_ be ? CalendarToString(_x_).</ins>
1. <ins>If _calendar_ is not *"iso8601"* and not equal to _dateTimeFormat_.[[Calendar]], then</ins>
1. <ins>Throw a *RangeError* exception.</ins>
1. <ins>Let _pattern_ be _dateTimeFormat_.[[TemporalZonedDateTimePattern]].</ins>
1. <ins>Let _tm_ be { [[weekday]]: <mark>TODO</mark>, [[year]]: <mark>TODO</mark>, [[month]]: <mark>TODO</mark>, [[day]]: <mark>TODO</mark>, [[hour]]: <mark>TODO</mark>, [[minute]]: <mark>TODO</mark>, [[second]]: <mark>TODO</mark>, [[timeZoneName]]: ? TimeZoneToString(_date_) }.
1. <ins>If _pattern_ is *null*, throw a *TypeError* exception.</ins>
1. <ins>Else,</ins>
1. <ins>Let _pattern_ be _dateTimeFormat_.[[Pattern]].</ins>
Expand Down
31 changes: 31 additions & 0 deletions spec/timezone.html
Original file line number Diff line number Diff line change
Expand Up @@ -489,5 +489,36 @@ <h1>ParseOffsetNanoseconds ( _identifier_ )</h1>
1. Return _sign_ × (_hours_ × 60 + _minutes_) × 60 × 1,000,000,000.
</emu-alg>
</emu-clause>

<emu-clause id="sec-temporal-comparetimezone" aoid="CompareTimeZone">
<p>
The abstract operation CompareTimeZone lexicographically compares the
results of calling `toString()` on its arguments.
</p>
<h1>CompareTimeZone ( _one_, _two_ )</h1>
<emu-alg>
1. Let _calendarOne_ be ? TimeZoneToString(_one_).
1. Let _calendarTwo_ be ? TimeZoneToString(_two_).
1. Let _r_ be the result of performing Abstract Relational Comparison _timeZoneOne_ &lt; _timeZoneTwo_.
1. If _r_ is *true*, return −1.
1. Let _r_ be the result of performing Abstract Relational Comparison _timeZoneTwo_ &lt; _timeZoneOne_.
1. If _r_ is *true*, return 1.
1. Return 0.
</emu-alg>
</emu-clause>

<emu-clause id="sec-temporal-timezoneequals" aoid="TimeZoneEquals">
<h1>TimeZoneEquals ( _one_, _two_ )</h1>
<p>
The abstract operation TimeZoneEquals returns *true* if the results of
calling `toString()` on its arguments are equal.
</p>
<emu-alg>
1. Let _timeZoneOne_ be ? TimeZoneToString(_one_).
1. Let _timeZoneTwo_ be ? TimeZoneToString(_two_).
1. If _timeZoneOne_ is _timeZoneTwo_, return *true*.
1. Return *false*.
</emu-alg>
</emu-clause>
</emu-clause>
</emu-clause>
Loading