Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
meyerweb committed May 20, 2021
1 parent 506e0f6 commit 3ae9d80
Show file tree
Hide file tree
Showing 12 changed files with 33 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@ <h2 id="examples">Examples</h2>

<pre class="brush: js">
var newcal = Temporal.Calendar.from('gregory');
newcal.toString(); // => 'gregory'
newcal.toString(); // => "gregory"
</pre>
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,11 @@ <h2 id="examples">Examples</h2>
three = Temporal.Duration.from({ days: 3, hours: 6, minutes: 50 });
sorted = [one, two, three].sort(Temporal.Duration.compare);
sorted.join(' | ');
// => 'P3DT6H50M | PT79H10M | P3DT7H630S'
// => "P3DT6H50M | PT79H10M | P3DT7H630S"

// Sorting relative to a date, taking DST changes into account:
relativeTo = Temporal.ZonedDateTime.from('2020-11-01T00:00-07:00[America/Los_Angeles]');
sorted = [one, two, three].sort((one, two) => Temporal.Duration.compare(one, two, {relativeTo}));
sorted.join(' | ');
// => 'PT79H10M | P3DT6H50M | P3DT7H630S'
// => "PT79H10M | P3DT6H50M | P3DT7H630S"
</pre>
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ <h2 id="examples">Examples</h2>
<pre class="brush: js">
date = Temporal.PlainDate.from('2006-08-24');
date.toLocaleString(); // example output: 8/24/2006
date.toLocaleString('de-DE'); // example output: '24.8.2006'
date.toLocaleString('de-DE', { weekday: 'long' }); // => 'Donnerstag'
date.toLocaleString('en-US-u-nu-fullwide'); // => '8/24/2006'
date.toLocaleString('de-DE'); // example output: "24.8.2006"
date.toLocaleString('de-DE', { weekday: 'long' }); // => "Donnerstag"
date.toLocaleString('en-US-u-nu-fullwide'); // => "8/24/2006"
</pre>
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,6 @@ <h2 id="examples">Examples</h2>
// => 1970-02-21[u-ca=hebrew]
md = Temporal.PlainMonthDay.from({ month: 6, day: 15, year: 5779, calendar: 'hebrew' });
// => 1970-02-21[u-ca=hebrew]
/* WRONG */ md = Temporal.PlainMonthDay.from({ month: 6, day: 15, calendar: 'hebrew' });
// => throws ('year' is required with 'month', though not 'monthCode')
md = Temporal.PlainMonthDay.from('2019-02-20[u-ca=hebrew]');
md.monthCode; // => 'M05L'
md.day; // => 15
Expand All @@ -108,3 +106,8 @@ <h2 id="examples">Examples</h2>
md.year; // undefined
// (year property is not present in this type)
</pre>
<pre class="brush: js example-bad">
/* WRONG */
md = Temporal.PlainMonthDay.from({ month: 6, day: 15, calendar: 'hebrew' });
// => throws ('year' is required with 'month', though not 'monthCode')
</pre>
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,5 @@ <h2 id="examples">Examples</h2>
two = Temporal.PlainTime.from('01:24');
three = Temporal.PlainTime.from('01:24:05');
sorted = [one, two, three].sort(Temporal.PlainTime.compare);
sorted.join(' | '); // => '01:24:00 | 01:24:05 | 03:24:00'
sorted.join(' | '); // => "01:24:00 | 01:24:05 | 03:24:00"
</pre>
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,5 @@ <h2 id="examples">Examples</h2>

<pre class="brush: js">
// Leet hour
leetTime = new Temporal.PlainTime(13, 37); // => 13:37:00.000000000
leetTime = new Temporal.PlainTime(13, 37); // => 13:37:00
</pre>
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,17 @@ <h2 id="examples">Examples</h2>
tz = new Temporal.TimeZone('Asia/Katmandu'); // alias of Asia/Kathmandu
tz = new Temporal.TimeZone('-04:00');
tz = new Temporal.TimeZone('+0645');
</pre>

<pre class="brush: js example-bad">
/* WRONG */
tz = new Temporal.TimeZone('local'); // not a time zone, so throws a RangeError
tz = new Temporal.TimeZone('local'); // throws, not a time zone
</pre>

<pre class="brush: js">
tz1 = new Temporal.TimeZone('-08:00');
tz2 = new Temporal.TimeZone('America/Vancouver');
inst = Temporal.ZonedDateTime.from({ year: 2020, month: 1, day: 1, timeZone: tz2 }).toInstant();
tz1.getNextTransition(inst); // => null; UTC offsets do not have DST schedules
tz1.getNextTransition(inst); // => null, UTC offsets do not have DST schedules
tz2.getPreviousTransition(inst); // => 2020-03-08T10:00Z
</pre>
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,9 @@ <h2 id="examples">Examples</h2>

<pre class="brush: js">
/* WRONG */
tz = Temporal.TimeZone.from('local'); // not a time zone
tz = Temporal.TimeZone.from('local'); // throws, not a time zone
/* WRONG */
tz = Temporal.TimeZone.from('2020-01-14T00:31:00'); // ISO 8601 string without time zone offset part
tz = Temporal.TimeZone.from('2020-01-14T00:31:00'); // throws, ISO 8601 string without time zone offset part
/* WRONG */
tz = Temporal.TimeZone.from('-08:00[America/Vancouver]'); // ISO 8601 string without date-time part
tz = Temporal.TimeZone.from('-08:00[America/Vancouver]'); // throws, ISO 8601 string without date-time part
</pre>
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ <h2 id="examples">Examples</h2>
// Getting the UTC offset for a time zone at a particular time
timestamp = Temporal.Instant.fromEpochSeconds(1553993100);
tz = Temporal.TimeZone.from('Europe/Berlin');
tz.getOffsetStringFor(timestamp); // => +01:00
tz.getOffsetStringFor(timestamp); // => "+01:00"

// TimeZone with a fixed UTC offset
tz = Temporal.TimeZone.from('-08:00');
tz.getOffsetStringFor(timestamp); // => -08:00
tz.getOffsetStringFor(timestamp); // => "-08:00"
</pre>
Original file line number Diff line number Diff line change
Expand Up @@ -36,26 +36,24 @@ <h3 id="parameters">Parameters</h3>

<h2 id="return-value">Return value</h2>

<p>A number indicating the UTC offset of the given time in nanoseconds.
</p>
<p>A <code>{{jsxref('Temporal.PlainDateTime','Temporal.PlainDateTime')}}</code> object.</p>

<h2 id="examples">Examples</h2>

<pre class="brush: js">
// Getting the UTC offset for a time zone at a particular time
timestamp = Temporal.Instant.fromEpochSeconds(1553993100);
tz = Temporal.TimeZone.from('Europe/Berlin');
tz.getPlainDateTimeFor(timestamp); // => 3600000000000

tz.getPlainDateTimeFor(timestamp); // => 2019-03-31T01:45:00
// TimeZone with a fixed UTC offset
tz = Temporal.TimeZone.from('-08:00');
tz.getPlainDateTimeFor(timestamp); // => -28800000000000
tz.getPlainDateTimeFor(timestamp); // => 2019-03-30T16:45:00
// UTC is always 0 offset
tz = Temporal.TimeZone.from('UTC');
tz.getPlainDateTimeFor(timestamp); // => 0
tz.getPlainDateTimeFor(timestamp); // => 2019-03-31T00:45:00

// Differences between DST and non-DST
tz = Temporal.TimeZone.from('Europe/London');
tz.getPlainDateTimeFor('2020-08-06T15:00Z'); // => 3600000000000
tz.getPlainDateTimeFor('2020-11-06T01:00Z'); // => 0
tz.getPlainDateTimeFor('2020-08-06T15:00Z'); // => 2020-08-06T16:00:00
tz.getPlainDateTimeFor('2020-11-06T01:00Z'); // => 2020-11-06T01:00:00
</pre>
Original file line number Diff line number Diff line change
Expand Up @@ -124,11 +124,12 @@ <h2 id="examples">Examples</h2>
// Different overflow modes
zdt = Temporal.ZonedDateTime.from({ timeZone: 'Europe/Paris', year: 2001, month: 13, day: 1 }, { overflow: 'constrain' })
// => 2001-12-01T00:00:00+01:00[Europe/Paris]
zdt = Temporal.ZonedDateTime.from({ timeZone: 'Europe/Paris', year: 2001, month: 13, day: 1 }, { overflow: 'reject' })
// => throws RangeError
</pre>

<pre class="brush: js example-bad">
zdt = Temporal.ZonedDateTime.from({ timeZone: 'Europe/Paris', year: 2001, month: 13, day: 1 }, { overflow: 'reject' })
// => throws RangeError: value out of range

zdt = Temporal.ZonedDateTime.from('1995-12-07T03:24:30');
// => throws RangeError: time zone ID required

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ <h2 id="examples">Examples</h2>

<pre class="brush: js">
datetime = Temporal.ZonedDateTime.from('2019-02-23');
datetime.monthCode; // => 'M02'
datetime.monthCode; // => "M02"

datetime = Temporal.ZonedDateTime.from('2019-02-23[u-ca=hebrew]');
datetime.monthCode; // => 'M05L'
datetime.monthCode; // => "M05L"
</pre>

0 comments on commit 3ae9d80

Please sign in to comment.