From 3a142eced48a7ab8a36cb7664c2f421289cdf082 Mon Sep 17 00:00:00 2001 From: Ujjwal Sharma Date: Thu, 25 Jun 2020 20:09:19 +0530 Subject: [PATCH 01/27] polyfill: rename inTimeZone to toAbsolute and toDateTime Rename Temporal.DateTime.prototype.inTimeZone to Temporal.DateTime.prototype.toAbsolute and Temporal.Absolute.prototype.inTimezone to Temporal.Absolute.prototype.toDtoDateTime for the sake of clarity. --- polyfill/index.d.ts | 4 +- polyfill/lib/absolute.mjs | 2 +- polyfill/lib/datetime.mjs | 2 +- .../Absolute/prototype/inTimeZone/branding.js | 16 ------ .../Absolute/prototype/toDateTime/branding.js | 16 ++++++ .../{inTimeZone => toDateTime}/prop-desc.js | 6 +-- polyfill/test/absolute.mjs | 16 +++--- polyfill/test/datetime.mjs | 50 +++++++++---------- polyfill/test/regex.mjs | 2 +- polyfill/test/usercalendar.mjs | 16 +++--- polyfill/test/usertimezone.mjs | 24 ++++----- 11 files changed, 77 insertions(+), 77 deletions(-) delete mode 100644 polyfill/test/Absolute/prototype/inTimeZone/branding.js create mode 100644 polyfill/test/Absolute/prototype/toDateTime/branding.js rename polyfill/test/Absolute/prototype/{inTimeZone => toDateTime}/prop-desc.js (67%) diff --git a/polyfill/index.d.ts b/polyfill/index.d.ts index efda105220..52d73cb80d 100644 --- a/polyfill/index.d.ts +++ b/polyfill/index.d.ts @@ -209,7 +209,7 @@ export namespace Temporal { other: Temporal.Absolute, options?: DifferenceOptions<'days' | 'hours' | 'minutes' | 'seconds'> ): Temporal.Duration; - inTimeZone(tzLike: TimeZoneProtocol | string, calendar?: CalendarProtocol | string): Temporal.DateTime; + toDateTime(tzLike: TimeZoneProtocol | string, calendar?: CalendarProtocol | string): Temporal.DateTime; toLocaleString(locales?: string | string[], options?: Intl.DateTimeFormatOptions): string; toJSON(): string; toString(tzLike?: TimeZoneProtocol | string): string; @@ -474,7 +474,7 @@ export namespace Temporal { other: Temporal.DateTime, options?: DifferenceOptions<'years' | 'months' | 'weeks' | 'days' | 'hours' | 'minutes' | 'seconds'> ): Temporal.Duration; - inTimeZone(tzLike: TimeZoneProtocol | string, options?: ToAbsoluteOptions): Temporal.Absolute; + toAbsolute(tzLike: TimeZoneProtocol | string, options?: ToAbsoluteOptions): Temporal.Absolute; getDate(): Temporal.Date; getYearMonth(): Temporal.YearMonth; getMonthDay(): Temporal.MonthDay; diff --git a/polyfill/lib/absolute.mjs b/polyfill/lib/absolute.mjs index ff182a7895..748c2edf80 100644 --- a/polyfill/lib/absolute.mjs +++ b/polyfill/lib/absolute.mjs @@ -156,7 +156,7 @@ export class Absolute { valueOf() { throw new TypeError('use compare() or equals() to compare Temporal.Absolute'); } - inTimeZone(temporalTimeZoneLike, calendar = undefined) { + toDateTime(temporalTimeZoneLike, calendar = undefined) { if (!ES.IsTemporalAbsolute(this)) throw new TypeError('invalid receiver'); const TemporalTimeZone = GetIntrinsic('%Temporal.TimeZone%'); const timeZone = TemporalTimeZone.from(temporalTimeZoneLike); diff --git a/polyfill/lib/datetime.mjs b/polyfill/lib/datetime.mjs index 484e7c0128..816db84a96 100644 --- a/polyfill/lib/datetime.mjs +++ b/polyfill/lib/datetime.mjs @@ -458,7 +458,7 @@ export class DateTime { throw new TypeError('use compare() or equals() to compare Temporal.DateTime'); } - inTimeZone(temporalTimeZoneLike, options) { + toAbsolute(temporalTimeZoneLike, options) { if (!ES.IsTemporalDateTime(this)) throw new TypeError('invalid receiver'); const TemporalTimeZone = GetIntrinsic('%Temporal.TimeZone%'); const timeZone = TemporalTimeZone.from(temporalTimeZoneLike); diff --git a/polyfill/test/Absolute/prototype/inTimeZone/branding.js b/polyfill/test/Absolute/prototype/inTimeZone/branding.js deleted file mode 100644 index d94575220a..0000000000 --- a/polyfill/test/Absolute/prototype/inTimeZone/branding.js +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright (C) 2020 Igalia, S.L. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. - -const inTimeZone = Temporal.Absolute.prototype.inTimeZone; - -assert.sameValue(typeof inTimeZone, "function"); - -assert.throws(TypeError, () => inTimeZone.call(undefined), "undefined"); -assert.throws(TypeError, () => inTimeZone.call(null), "null"); -assert.throws(TypeError, () => inTimeZone.call(true), "true"); -assert.throws(TypeError, () => inTimeZone.call(""), "empty string"); -assert.throws(TypeError, () => inTimeZone.call(Symbol()), "symbol"); -assert.throws(TypeError, () => inTimeZone.call(1), "1"); -assert.throws(TypeError, () => inTimeZone.call({}), "plain object"); -assert.throws(TypeError, () => inTimeZone.call(Temporal.Absolute), "Temporal.Absolute"); -assert.throws(TypeError, () => inTimeZone.call(Temporal.Absolute.prototype), "Temporal.Absolute.prototype"); diff --git a/polyfill/test/Absolute/prototype/toDateTime/branding.js b/polyfill/test/Absolute/prototype/toDateTime/branding.js new file mode 100644 index 0000000000..964842d664 --- /dev/null +++ b/polyfill/test/Absolute/prototype/toDateTime/branding.js @@ -0,0 +1,16 @@ +// Copyright (C) 2020 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +const toDateTime = Temporal.Absolute.prototype.toDateTime; + +assert.sameValue(typeof toDateTime, "function"); + +assert.throws(TypeError, () => toDateTime.call(undefined), "undefined"); +assert.throws(TypeError, () => toDateTime.call(null), "null"); +assert.throws(TypeError, () => toDateTime.call(true), "true"); +assert.throws(TypeError, () => toDateTime.call(""), "empty string"); +assert.throws(TypeError, () => toDateTime.call(Symbol()), "symbol"); +assert.throws(TypeError, () => toDateTime.call(1), "1"); +assert.throws(TypeError, () => toDateTime.call({}), "plain object"); +assert.throws(TypeError, () => toDateTime.call(Temporal.Absolute), "Temporal.Absolute"); +assert.throws(TypeError, () => toDateTime.call(Temporal.Absolute.prototype), "Temporal.Absolute.prototype"); diff --git a/polyfill/test/Absolute/prototype/inTimeZone/prop-desc.js b/polyfill/test/Absolute/prototype/toDateTime/prop-desc.js similarity index 67% rename from polyfill/test/Absolute/prototype/inTimeZone/prop-desc.js rename to polyfill/test/Absolute/prototype/toDateTime/prop-desc.js index 19e6fce471..2335f0d8bd 100644 --- a/polyfill/test/Absolute/prototype/inTimeZone/prop-desc.js +++ b/polyfill/test/Absolute/prototype/toDateTime/prop-desc.js @@ -7,12 +7,12 @@ includes: [propertyHelper.js] const { Absolute } = Temporal; assert.sameValue( - typeof Absolute.prototype.inTimeZone, + typeof Absolute.prototype.toDateTime, "function", - "`typeof Absolute.prototype.inTimeZone` is `function`" + "`typeof Absolute.prototype.toDateTime` is `function`" ); -verifyProperty(Absolute.prototype, "inTimeZone", { +verifyProperty(Absolute.prototype, "toDateTime", { writable: true, enumerable: false, configurable: true, diff --git a/polyfill/test/absolute.mjs b/polyfill/test/absolute.mjs index 5f14ba6e29..27f4b0519c 100644 --- a/polyfill/test/absolute.mjs +++ b/polyfill/test/absolute.mjs @@ -476,8 +476,8 @@ describe('Absolute', () => { it('converting from DateTime', () => { const min = Temporal.DateTime.from('-271821-04-19T00:00:00.000000001'); const max = Temporal.DateTime.from('+275760-09-13T23:59:59.999999999'); - throws(() => min.inTimeZone('UTC'), RangeError); - throws(() => max.inTimeZone('UTC'), RangeError); + throws(() => min.toAbsolute('UTC'), RangeError); + throws(() => max.toAbsolute('UTC'), RangeError); const utc = Temporal.TimeZone.from('UTC'); throws(() => utc.getAbsoluteFor(min), RangeError); throws(() => utc.getAbsoluteFor(max), RangeError); @@ -489,22 +489,22 @@ describe('Absolute', () => { throws(() => max.plus({ nanoseconds: 1 }), RangeError); }); }); - describe('Absolute.inTimeZone works', () => { + describe('Absolute.toDateTime works', () => { const iso = '1976-11-18T14:23:30.123456789Z'; const abs = Absolute.from(iso); it('without parameter', () => { - throws(() => abs.inTimeZone(), RangeError); + throws(() => abs.toDateTime(), RangeError); }); it('time zone parameter UTC', () => { const tz = Temporal.TimeZone.from('UTC'); - const dt = abs.inTimeZone(tz); - equal(abs.getEpochNanoseconds(), dt.inTimeZone(tz).getEpochNanoseconds()); + const dt = abs.toDateTime(tz); + equal(abs.getEpochNanoseconds(), dt.toAbsolute(tz).getEpochNanoseconds()); equal(`${dt}`, '1976-11-18T14:23:30.123456789'); }); it('time zone parameter non-UTC', () => { const tz = Temporal.TimeZone.from('America/New_York'); - const dt = abs.inTimeZone(tz); - equal(abs.getEpochNanoseconds(), dt.inTimeZone(tz).getEpochNanoseconds()); + const dt = abs.toDateTime(tz); + equal(abs.getEpochNanoseconds(), dt.toAbsolute(tz).getEpochNanoseconds()); equal(`${dt}`, '1976-11-18T09:23:30.123456789'); }); }); diff --git a/polyfill/test/datetime.mjs b/polyfill/test/datetime.mjs index 3007908cdc..03b4d7a577 100644 --- a/polyfill/test/datetime.mjs +++ b/polyfill/test/datetime.mjs @@ -78,8 +78,8 @@ describe('DateTime', () => { it('DateTime.prototype.equals is a Function', () => { equal(typeof DateTime.prototype.equals, 'function'); }); - it('DateTime.prototype.inTimeZone is a Function', () => { - equal(typeof DateTime.prototype.inTimeZone, 'function'); + it('DateTime.prototype.toAbsolute is a Function', () => { + equal(typeof DateTime.prototype.toAbsolute, 'function'); }); it('DateTime.prototype.getDate is a Function', () => { equal(typeof DateTime.prototype.getDate, 'function'); @@ -495,42 +495,42 @@ describe('DateTime', () => { equal(`${DateTime.from('1976-11-18')}`, '1976-11-18T00:00'); }); }); - describe('DateTime.inTimeZone() works', () => { + describe('DateTime.toAbsolute() works', () => { it('recent date', () => { const dt = DateTime.from('2019-10-29T10:46:38.271986102'); const tz = Temporal.TimeZone.from('Europe/Amsterdam'); - equal(`${dt.inTimeZone(tz)}`, '2019-10-29T09:46:38.271986102Z'); - equal(`${dt.inTimeZone('Europe/Amsterdam')}`, '2019-10-29T09:46:38.271986102Z'); + equal(`${dt.toAbsolute(tz)}`, '2019-10-29T09:46:38.271986102Z'); + equal(`${dt.toAbsolute('Europe/Amsterdam')}`, '2019-10-29T09:46:38.271986102Z'); }); it('year ≤ 99', () => { const dt = DateTime.from('+000098-10-29T10:46:38.271986102'); - equal(`${dt.inTimeZone('+06:00')}`, '+000098-10-29T04:46:38.271986102Z'); + equal(`${dt.toAbsolute('+06:00')}`, '+000098-10-29T04:46:38.271986102Z'); }); it('year < 1', () => { let dt = DateTime.from('+000000-10-29T10:46:38.271986102'); - equal(`${dt.inTimeZone('+06:00')}`, '+000000-10-29T04:46:38.271986102Z'); + equal(`${dt.toAbsolute('+06:00')}`, '+000000-10-29T04:46:38.271986102Z'); dt = DateTime.from('-001000-10-29T10:46:38.271986102'); - equal(`${dt.inTimeZone('+06:00')}`, '-001000-10-29T04:46:38.271986102Z'); + equal(`${dt.toAbsolute('+06:00')}`, '-001000-10-29T04:46:38.271986102Z'); }); it('datetime with multiple absolute - Fall DST in Brazil', () => { const dt = DateTime.from('2019-02-16T23:45'); - equal(`${dt.inTimeZone('America/Sao_Paulo')}`, '2019-02-17T01:45Z'); - equal(`${dt.inTimeZone('America/Sao_Paulo', { disambiguation: 'compatible' })}`, '2019-02-17T01:45Z'); - equal(`${dt.inTimeZone('America/Sao_Paulo', { disambiguation: 'earlier' })}`, '2019-02-17T01:45Z'); - equal(`${dt.inTimeZone('America/Sao_Paulo', { disambiguation: 'later' })}`, '2019-02-17T02:45Z'); - throws(() => dt.inTimeZone('America/Sao_Paulo', { disambiguation: 'reject' }), RangeError); + equal(`${dt.toAbsolute('America/Sao_Paulo')}`, '2019-02-17T01:45Z'); + equal(`${dt.toAbsolute('America/Sao_Paulo', { disambiguation: 'compatible' })}`, '2019-02-17T01:45Z'); + equal(`${dt.toAbsolute('America/Sao_Paulo', { disambiguation: 'earlier' })}`, '2019-02-17T01:45Z'); + equal(`${dt.toAbsolute('America/Sao_Paulo', { disambiguation: 'later' })}`, '2019-02-17T02:45Z'); + throws(() => dt.toAbsolute('America/Sao_Paulo', { disambiguation: 'reject' }), RangeError); }); it('datetime with multiple absolute - Spring DST in Los Angeles', () => { const dt = DateTime.from('2020-03-08T02:30'); - equal(`${dt.inTimeZone('America/Los_Angeles')}`, '2020-03-08T10:30Z'); - equal(`${dt.inTimeZone('America/Los_Angeles', { disambiguation: 'compatible' })}`, '2020-03-08T10:30Z'); - equal(`${dt.inTimeZone('America/Los_Angeles', { disambiguation: 'earlier' })}`, '2020-03-08T09:30Z'); - equal(`${dt.inTimeZone('America/Los_Angeles', { disambiguation: 'later' })}`, '2020-03-08T10:30Z'); - throws(() => dt.inTimeZone('America/Los_Angeles', { disambiguation: 'reject' }), RangeError); + equal(`${dt.toAbsolute('America/Los_Angeles')}`, '2020-03-08T10:30Z'); + equal(`${dt.toAbsolute('America/Los_Angeles', { disambiguation: 'compatible' })}`, '2020-03-08T10:30Z'); + equal(`${dt.toAbsolute('America/Los_Angeles', { disambiguation: 'earlier' })}`, '2020-03-08T09:30Z'); + equal(`${dt.toAbsolute('America/Los_Angeles', { disambiguation: 'later' })}`, '2020-03-08T10:30Z'); + throws(() => dt.toAbsolute('America/Los_Angeles', { disambiguation: 'reject' }), RangeError); }); it('throws on bad disambiguation', () => { ['', 'EARLIER', 'xyz', 3, null].forEach((disambiguation) => - throws(() => DateTime.from('2019-10-29T10:46').inTimeZone('UTC', { disambiguation }), RangeError) + throws(() => DateTime.from('2019-10-29T10:46').toAbsolute('UTC', { disambiguation }), RangeError) ); }); }); @@ -580,8 +580,8 @@ describe('DateTime', () => { it('converting from Absolute', () => { const min = Temporal.Absolute.from('-271821-04-20T00:00Z'); const max = Temporal.Absolute.from('+275760-09-13T00:00Z'); - equal(`${min.inTimeZone('-23:59')}`, '-271821-04-19T00:01'); - equal(`${max.inTimeZone('+23:59')}`, '+275760-09-13T23:59'); + equal(`${min.toDateTime('-23:59')}`, '-271821-04-19T00:01'); + equal(`${max.toDateTime('+23:59')}`, '+275760-09-13T23:59'); }); it('converting from Date and Time', () => { const midnight = Temporal.Time.from('00:00'); @@ -605,19 +605,19 @@ describe('DateTime', () => { }); }); }); - describe('DateTime.inTimeZone() works', () => { + describe('DateTime.toAbsolute() works', () => { const dt = DateTime.from('1976-11-18T15:23:30.123456789'); it('without parameter', () => { - throws(() => dt.inTimeZone(), RangeError); + throws(() => dt.toAbsolute(), RangeError); }); it('time zone parameter UTC', () => { const tz = Temporal.TimeZone.from('UTC'); - const abs = dt.inTimeZone(tz); + const abs = dt.toAbsolute(tz); equal(`${abs}`, '1976-11-18T15:23:30.123456789Z'); }); it('time zone parameter non-UTC', () => { const tz = Temporal.TimeZone.from('America/New_York'); - const abs = dt.inTimeZone(tz); + const abs = dt.toAbsolute(tz); equal(`${abs}`, '1976-11-18T20:23:30.123456789Z'); }); }); diff --git a/polyfill/test/regex.mjs b/polyfill/test/regex.mjs index 7956aad49f..cab0a42412 100644 --- a/polyfill/test/regex.mjs +++ b/polyfill/test/regex.mjs @@ -15,7 +15,7 @@ describe('fromString regex', () => { it(isoString, () => { const [y, mon, d, h = 0, min = 0, s = 0, ms = 0, µs = 0, ns = 0] = components; const absolute = Temporal.Absolute.from(isoString); - const datetime = absolute.inTimeZone('UTC'); + const datetime = absolute.toDateTime('UTC'); equal(datetime.year, y); equal(datetime.month, mon); equal(datetime.day, d); diff --git a/polyfill/test/usercalendar.mjs b/polyfill/test/usercalendar.mjs index a4beebf227..e833ef3ee9 100644 --- a/polyfill/test/usercalendar.mjs +++ b/polyfill/test/usercalendar.mjs @@ -111,9 +111,9 @@ describe('Userland calendar', () => { const dt = tz.getDateTimeFor(abs, obj); equal(dt.calendar.id, obj.id); }); - it('absolute.inTimeZone()', () => { + it('absolute.toDateTime()', () => { const abs = Temporal.Absolute.fromEpochSeconds(0); - const dt = abs.inTimeZone('UTC', obj); + const dt = abs.toDateTime('UTC', obj); equal(dt.calendar.id, obj.id); }); it('Temporal.now.dateTime()', () => { @@ -204,9 +204,9 @@ describe('Userland calendar', () => { const dt = tz.getDateTimeFor(abs, 'zerobased'); equal(dt.calendar.id, 'zerobased'); }); - it('works for Absolute.inTimeZone', () => { + it('works for Absolute.toDateTime', () => { const abs = Temporal.Absolute.fromEpochSeconds(0); - const dt = abs.inTimeZone('UTC', 'zerobased'); + const dt = abs.toDateTime('UTC', 'zerobased'); equal(dt.calendar.id, 'zerobased'); }); it('works for Temporal.now.dateTime', () => { @@ -351,9 +351,9 @@ describe('Userland calendar', () => { const dt = tz.getDateTimeFor(abs, obj); equal(dt.calendar.id, obj.id); }); - it('absolute.inTimeZone()', () => { + it('absolute.toDateTime()', () => { const abs = Temporal.Absolute.fromEpochSeconds(0); - const dt = abs.inTimeZone('UTC', obj); + const dt = abs.toDateTime('UTC', obj); equal(dt.calendar.id, obj.id); }); it('Temporal.now.dateTime()', () => { @@ -444,9 +444,9 @@ describe('Userland calendar', () => { const dt = tz.getDateTimeFor(abs, 'decimal'); equal(dt.calendar.id, 'decimal'); }); - it('works for Absolute.inTimeZone', () => { + it('works for Absolute.toDateTime', () => { const abs = Temporal.Absolute.fromEpochSeconds(0); - const dt = abs.inTimeZone('UTC', 'decimal'); + const dt = abs.toDateTime('UTC', 'decimal'); equal(dt.calendar.id, 'decimal'); }); it('works for Temporal.now.dateTime', () => { diff --git a/polyfill/test/usertimezone.mjs b/polyfill/test/usertimezone.mjs index 61e41e40a4..1b98b669cb 100644 --- a/polyfill/test/usertimezone.mjs +++ b/polyfill/test/usertimezone.mjs @@ -52,11 +52,11 @@ describe('Userland time zone', () => { it('has offset string +00:00', () => equal(obj.getOffsetStringFor(abs), '+00:00')); it('converts to DateTime', () => { equal(`${obj.getDateTimeFor(abs)}`, '1970-01-01T00:00'); - equal(`${abs.inTimeZone(obj)}`, '1970-01-01T00:00'); + equal(`${abs.toDateTime(obj)}`, '1970-01-01T00:00'); }); it('converts to Absolute', () => { equal(`${obj.getAbsoluteFor(dt)}`, '1976-11-18T15:23:30.123456789Z'); - equal(`${dt.inTimeZone(obj)}`, '1976-11-18T15:23:30.123456789Z'); + equal(`${dt.toAbsolute(obj)}`, '1976-11-18T15:23:30.123456789Z'); }); it('converts to string', () => equal(`${obj}`, obj.name)); it('prints in absolute.toString', () => @@ -99,13 +99,13 @@ describe('Userland time zone', () => { const abs = Temporal.Absolute.fromEpochSeconds(0); equal(abs.toString('Etc/Custom_UTC_Subclass'), '1970-01-01T00:00+00:00[Etc/Custom_UTC_Subclass]'); }); - it('works for Absolute.inTimeZone', () => { + it('works for Absolute.toDateTime', () => { const abs = Temporal.Absolute.fromEpochSeconds(0); - equal(`${abs.inTimeZone('Etc/Custom_UTC_Subclass')}`, '1970-01-01T00:00'); + equal(`${abs.toDateTime('Etc/Custom_UTC_Subclass')}`, '1970-01-01T00:00'); }); - it('works for DateTime.inTimeZone', () => { + it('works for DateTime.toAbsolute', () => { const dt = Temporal.DateTime.from('1970-01-01T00:00'); - equal(dt.inTimeZone('Etc/Custom_UTC_Subclass').getEpochSeconds(), 0); + equal(dt.toAbsolute('Etc/Custom_UTC_Subclass').getEpochSeconds(), 0); }); it('works for Temporal.now', () => { assert(Temporal.now.dateTime('Etc/Custom_UTC_Subclass') instanceof Temporal.DateTime); @@ -141,11 +141,11 @@ describe('Userland time zone', () => { equal(Temporal.TimeZone.prototype.getOffsetStringFor.call(obj, abs), '+00:00')); it('converts to DateTime', () => { equal(`${Temporal.TimeZone.prototype.getDateTimeFor.call(obj, abs)}`, '1970-01-01T00:00'); - equal(`${abs.inTimeZone(obj)}`, '1970-01-01T00:00'); + equal(`${abs.toDateTime(obj)}`, '1970-01-01T00:00'); }); it('converts to Absolute', () => { equal(`${Temporal.TimeZone.prototype.getAbsoluteFor.call(obj, dt)}`, '1976-11-18T15:23:30.123456789Z'); - equal(`${dt.inTimeZone(obj)}`, '1976-11-18T15:23:30.123456789Z'); + equal(`${dt.toAbsolute(obj)}`, '1976-11-18T15:23:30.123456789Z'); }); it('prints in absolute.toString', () => equal(abs.toString(obj), '1970-01-01T00:00+00:00[Etc/Custom_UTC_Protocol]')); @@ -185,13 +185,13 @@ describe('Userland time zone', () => { const abs = Temporal.Absolute.fromEpochSeconds(0); equal(abs.toString('Etc/Custom_UTC_Protocol'), '1970-01-01T00:00+00:00[Etc/Custom_UTC_Protocol]'); }); - it('works for Absolute.inTimeZone', () => { + it('works for Absolute.toDateTime', () => { const abs = Temporal.Absolute.fromEpochSeconds(0); - equal(`${abs.inTimeZone('Etc/Custom_UTC_Protocol')}`, '1970-01-01T00:00'); + equal(`${abs.toDateTime('Etc/Custom_UTC_Protocol')}`, '1970-01-01T00:00'); }); - it('works for DateTime.inTimeZone', () => { + it('works for DateTime.toAbsolute', () => { const dt = Temporal.DateTime.from('1970-01-01T00:00'); - equal(dt.inTimeZone('Etc/Custom_UTC_Protocol').getEpochSeconds(), 0); + equal(dt.toAbsolute('Etc/Custom_UTC_Protocol').getEpochSeconds(), 0); }); it('works for Temporal.now', () => { assert(Temporal.now.dateTime('Etc/Custom_UTC_Protocol') instanceof Temporal.DateTime); From 1cb902da1fe8311f8d7b68665a4af019bf5dde50 Mon Sep 17 00:00:00 2001 From: Ujjwal Sharma Date: Fri, 26 Jun 2020 00:28:20 +0530 Subject: [PATCH 02/27] spec: rename inTimeZone to toAbsolute and toDateTime --- spec/absolute.html | 6 +++--- spec/datetime.html | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/spec/absolute.html b/spec/absolute.html index 4dc4f83d8e..6ff52c58a8 100644 --- a/spec/absolute.html +++ b/spec/absolute.html @@ -367,10 +367,10 @@

Temporal.Absolute.prototype.valueOf ( )

- -

Temporal.Absolute.prototype.inTimeZone ( _temporalTimeZoneLike_ )

+ +

Temporal.Absolute.prototype.toDateTime ( _temporalTimeZoneLike_ )

- The `inTimeZone` method takes one argument _temporalTimeZoneLike_. + The `toDateTime` method takes one argument _temporalTimeZoneLike_. The following steps are taken:

diff --git a/spec/datetime.html b/spec/datetime.html index ede6e61b50..417b4e840a 100644 --- a/spec/datetime.html +++ b/spec/datetime.html @@ -518,10 +518,10 @@

Temporal.DateTime.prototype.valueOf ( )

- -

Temporal.DateTime.prototype.inTimeZone ( _temporalTimeZoneLike_ [ , _options_ ] )

+ +

Temporal.DateTime.prototype.toAbsolute ( _temporalTimeZoneLike_ [ , _options_ ] )

- The `inTimeZone` method takes two arguments, _temporalTimeZoneLike_ and _options_. + The `toAbsolute` method takes two arguments, _temporalTimeZoneLike_ and _options_. The following steps are taken:

From db2bf1b4e937c47d8142c441f569ebedd9fbe3f9 Mon Sep 17 00:00:00 2001 From: Ujjwal Sharma Date: Fri, 26 Jun 2020 02:45:37 +0530 Subject: [PATCH 03/27] docs: rename inTimeZone to toAbsolute and toDateTime --- docs/absolute.md | 12 ++++++------ docs/ambiguity.md | 16 ++++++++-------- docs/cookbook.md | 2 +- docs/cookbook/calculateDailyOccurrence.mjs | 2 +- docs/cookbook/getBusinessOpenStateText.mjs | 2 +- docs/cookbook/getInstantWithLocalTimeInZone.mjs | 6 +++--- docs/cookbook/getLocalizedArrival.mjs | 2 +- ...seableZonedStringWithLocalTimeInOtherZone.mjs | 2 +- docs/cookbook/localTimeForFutureEvents.mjs | 2 +- docs/cookbook/meetingPlanner.js | 6 +++--- docs/cookbook/nextWeeklyOccurrence.mjs | 4 ++-- docs/cookbook/storageTank.js | 2 +- docs/datetime.md | 4 ++-- docs/now.md | 4 ++-- docs/timezone.md | 6 +++--- 15 files changed, 36 insertions(+), 36 deletions(-) diff --git a/docs/absolute.md b/docs/absolute.md index 85dc03aa6a..1ac33d0282 100644 --- a/docs/absolute.md +++ b/docs/absolute.md @@ -206,7 +206,7 @@ Same as `getEpochSeconds()`, but with nanosecond (10−9 second) The value returned from this method is suitable to be passed to `new Temporal.Absolute()`. -### absolute.**inTimeZone**(_timeZone_: object | string, _calendar_?: object | string) : Temporal.DateTime +### absolute.**toDateTime**(_timeZone_: object | string, _calendar_?: object | string) : Temporal.DateTime **Parameters:** - `timeZone` (object or string): A `Temporal.TimeZone` object, or an object implementing the [time zone protocol](./timezone.md#protocol), or a string description of the time zone; either its IANA name or UTC offset. @@ -227,14 +227,14 @@ Example usage: ```js // Converting a specific absolute time to a calendar date / wall-clock time timestamp = new Temporal.Absolute(1553993100000000000n); -timestamp.inTimeZone('Europe/Berlin'); // => 2019-03-31T01:45 -timestamp.inTimeZone('UTC'); // => 2019-03-31T00:45 -timestamp.inTimeZone('-08:00'); // => 2019-02-01T16:45 +timestamp.toDateTime('Europe/Berlin'); // => 2019-03-31T01:45 +timestamp.toDateTime('UTC'); // => 2019-03-31T00:45 +timestamp.toDateTime('-08:00'); // => 2019-02-01T16:45 // What time was the Unix epoch (timestamp 0) in Bell Labs (Murray Hill, New Jersey, USA)? epoch = new Temporal.Absolute(0n); tz = new Temporal.TimeZone('America/New_York'); -epoch.inTimeZone(tz); // => 1969-12-31T19:00 +epoch.toDateTime(tz); // => 1969-12-31T19:00 ``` ### absolute.**plus**(_duration_: object) : Temporal.Absolute @@ -334,7 +334,7 @@ billion.difference(epoch, { largestUnit: 'days' }) // => P11574DT1H46M40S // in years, you can eliminate the ambiguity by choosing your starting // point explicitly. For example, using the corresponding UTC date: utc = Temporal.TimeZone.from('UTC'); -billion.inTimeZone(utc).difference(epoch.inTimeZone(utc), { largestUnit: 'years' }); +billion.toDateTime(utc).difference(epoch.toDateTime(utc), { largestUnit: 'years' }); // => P31Y8M8DT1H46M40S ``` diff --git a/docs/ambiguity.md b/docs/ambiguity.md index 76a682c97a..670b18272e 100644 --- a/docs/ambiguity.md +++ b/docs/ambiguity.md @@ -5,7 +5,7 @@ Converting a [`Temporal.DateTime`](./datetime.md) wall-clock time to a [`Temporal.Absolute`](./absolute.md) is not necessarily a one-to-one conversion. Due to DST time changes, there is a possibility that a wall-clock time either does not exist, or has existed twice. -There are two mostly equivalent methods that accomplish this conversion: [`Temporal.DateTime.prototype.inTimeZone`](./datetime.html#inTimeZone) and [`Temporal.TimeZone.prototype.getAbsoluteFor`](./timezone.html#getAbsoluteFor). +There are two mostly equivalent methods that accomplish this conversion: [`Temporal.DateTime.prototype.toAbsolute`](./datetime.html#toAbsolute) and [`Temporal.TimeZone.prototype.getAbsoluteFor`](./timezone.html#getAbsoluteFor). The `disambiguation` option to these methods controls what absolute time to return in the case of ambiguity: - `'compatible'` (the default): Acts like `'earlier'` for backward transitions and `'later'` for forward transitions. @@ -46,9 +46,9 @@ tz.getAbsoluteFor(dt, { disambiguation: 'reject' }); // throws In this example, the wall-clock time 2:45 doesn't exist, so it is treated as either 1:45 +01:00 or 3:45 +02:00, which can be seen by converting the absolute back to a wall-clock time in the time zone: ```javascript -tz.getAbsoluteFor(dt, { disambiguation: 'earlier' }).inTimeZone(tz); // => 2019-03-31T01:45 -tz.getAbsoluteFor(dt, { disambiguation: 'later' }).inTimeZone(tz); // => 2019-03-31T03:45 -tz.getAbsoluteFor(dt, { disambiguation: 'compatible' }).inTimeZone(tz); // => 2019-03-31T03:45 +tz.getAbsoluteFor(dt, { disambiguation: 'earlier' }).toDateTime(tz); // => 2019-03-31T01:45 +tz.getAbsoluteFor(dt, { disambiguation: 'later' }).toDateTime(tz); // => 2019-03-31T03:45 +tz.getAbsoluteFor(dt, { disambiguation: 'compatible' }).toDateTime(tz); // => 2019-03-31T03:45 ``` Using [`Temporal.TimeZone.prototype.getPossibleAbsolutesFor`](./timezone.html#getPossibleAbsolutesFor) we can show that the wall-clock time doesn't exist: @@ -66,10 +66,10 @@ In `'compatible'` mode, the same time is returned as `'earlier'` mode, which mat ```javascript tz = new Temporal.TimeZone('America/Sao_Paulo'); dt = new Temporal.DateTime(2019, 2, 16, 23, 45); -dt.inTimeZone(tz, { disambiguation: 'earlier' }); // => 2019-02-17T01:45Z -dt.inTimeZone(tz, { disambiguation: 'later' }); // => 2019-02-17T02:45Z -dt.inTimeZone(tz, { disambiguation: 'compatible' }); // => 2019-02-17T01:45Z -dt.inTimeZone(tz, { disambiguation: 'reject' }); // throws +dt.toAbsolute(tz, { disambiguation: 'earlier' }); // => 2019-02-17T01:45Z +dt.toAbsolute(tz, { disambiguation: 'later' }); // => 2019-02-17T02:45Z +dt.toAbsolute(tz, { disambiguation: 'compatible' }); // => 2019-02-17T01:45Z +dt.toAbsolute(tz, { disambiguation: 'reject' }); // throws ``` In this example, the wall-clock time 23:45 exists twice, which can also be verified with `getPossibleAbsolutesFor`: diff --git a/docs/cookbook.md b/docs/cookbook.md index 0251eb158e..ed972fef59 100644 --- a/docs/cookbook.md +++ b/docs/cookbook.md @@ -132,7 +132,7 @@ Here's an example of rounding a time _down_ to the previously occurring whole ho ### Preserving local time Map a zoneless date and time of day into a `Temporal.Absolute` instance at which the local date and time of day in a specified time zone matches it. -This is easily done with `dateTime.inTimeZone()`, but here is an example of implementing different disambiguation behaviors than the `'compatible'`, `'earlier'`, `'later'`, and `'reject'` ones built in to Temporal. +This is easily done with `dateTime.toAbsolute()`, but here is an example of implementing different disambiguation behaviors than the `'compatible'`, `'earlier'`, `'later'`, and `'reject'` ones built in to Temporal. ```javascript {{cookbook/getInstantWithLocalTimeInZone.mjs}} diff --git a/docs/cookbook/calculateDailyOccurrence.mjs b/docs/cookbook/calculateDailyOccurrence.mjs index a549945698..9decb6aec8 100644 --- a/docs/cookbook/calculateDailyOccurrence.mjs +++ b/docs/cookbook/calculateDailyOccurrence.mjs @@ -9,7 +9,7 @@ */ function* calculateDailyOccurrence(startDate, time, timeZone) { for (let date = startDate; ; date = date.plus({ days: 1 })) { - yield date.withTime(time).inTimeZone(timeZone); + yield date.withTime(time).toAbsolute(timeZone); } } diff --git a/docs/cookbook/getBusinessOpenStateText.mjs b/docs/cookbook/getBusinessOpenStateText.mjs index a352a41f41..25654829b5 100644 --- a/docs/cookbook/getBusinessOpenStateText.mjs +++ b/docs/cookbook/getBusinessOpenStateText.mjs @@ -24,7 +24,7 @@ function getBusinessOpenStateText(now, timeZone, businessHours, soonWindow) { return Temporal.Absolute.compare(abs, start) >= 0 && Temporal.Absolute.compare(abs, end) < 0; } - const dateTime = now.inTimeZone(timeZone); + const dateTime = now.toDateTime(timeZone); const weekday = dateTime.dayOfWeek % 7; // convert to 0-based, for array indexing // Because of times wrapping around at midnight, we may need to consider diff --git a/docs/cookbook/getInstantWithLocalTimeInZone.mjs b/docs/cookbook/getInstantWithLocalTimeInZone.mjs index f5ff7701e9..ba9be3c10c 100644 --- a/docs/cookbook/getInstantWithLocalTimeInZone.mjs +++ b/docs/cookbook/getInstantWithLocalTimeInZone.mjs @@ -1,7 +1,7 @@ /** * Get an absolute time corresponding with a calendar date / wall-clock time in * a particular time zone, the same as Temporal.TimeZone.getAbsoluteFor() or - * Temporal.DateTime.inTimeZone(), but with more disambiguation options. + * Temporal.DateTime.toAbsolute(), but with more disambiguation options. * * As well as the default Temporal disambiguation options 'compatible', * 'earlier', 'later', and 'reject', there are additional options possible: @@ -34,13 +34,13 @@ function getInstantWithLocalTimeInZone(dateTime, timeZone, disambiguation = 'ear switch (disambiguation) { case 'clipEarlier': if (possible.length === 0) { - const before = dateTime.inTimeZone(timeZone, { disambiguation: 'earlier' }); + const before = dateTime.toAbsolute(timeZone, { disambiguation: 'earlier' }); return timeZone.getNextTransition(before).minus({ nanoseconds: 1 }); } return possible[0]; case 'clipLater': if (possible.length === 0) { - const before = dateTime.inTimeZone(timeZone, { disambiguation: 'earlier' }); + const before = dateTime.toAbsolute(timeZone, { disambiguation: 'earlier' }); return timeZone.getNextTransition(before); } return possible[possible.length - 1]; diff --git a/docs/cookbook/getLocalizedArrival.mjs b/docs/cookbook/getLocalizedArrival.mjs index 7fd93c3911..38e7d27bf1 100644 --- a/docs/cookbook/getLocalizedArrival.mjs +++ b/docs/cookbook/getLocalizedArrival.mjs @@ -11,7 +11,7 @@ function getLocalizedArrival(parseableDeparture, flightTime, destinationTimeZone) { const departure = Temporal.Absolute.from(parseableDeparture); const arrival = departure.plus(flightTime); - return arrival.inTimeZone(destinationTimeZone); + return arrival.toDateTime(destinationTimeZone); } const arrival = getLocalizedArrival( diff --git a/docs/cookbook/getParseableZonedStringWithLocalTimeInOtherZone.mjs b/docs/cookbook/getParseableZonedStringWithLocalTimeInOtherZone.mjs index f7216acb5f..9191a7a23c 100644 --- a/docs/cookbook/getParseableZonedStringWithLocalTimeInOtherZone.mjs +++ b/docs/cookbook/getParseableZonedStringWithLocalTimeInOtherZone.mjs @@ -22,7 +22,7 @@ function getParseableZonedStringWithLocalTimeInOtherZone( targetTimeZone, sourceDisambiguationPolicy = 'reject' ) { - let instant = sourceDateTime.inTimeZone(sourceTimeZone, { disambiguation: sourceDisambiguationPolicy }); + let instant = sourceDateTime.toAbsolute(sourceTimeZone, { disambiguation: sourceDisambiguationPolicy }); return instant.toString(targetTimeZone); } diff --git a/docs/cookbook/localTimeForFutureEvents.mjs b/docs/cookbook/localTimeForFutureEvents.mjs index a4b0fd673d..7744d7b2b7 100644 --- a/docs/cookbook/localTimeForFutureEvents.mjs +++ b/docs/cookbook/localTimeForFutureEvents.mjs @@ -30,7 +30,7 @@ const tc39meetings = [ // need to join: const localTimeZone = Temporal.TimeZone.from('Asia/Tokyo'); const localTimes = tc39meetings.map(({ dateTime, timeZone }) => { - return Temporal.DateTime.from(dateTime).inTimeZone(timeZone, { disambiguation: 'reject' }).inTimeZone(localTimeZone); + return Temporal.DateTime.from(dateTime).toAbsolute(timeZone, { disambiguation: 'reject' }).toDateTime(localTimeZone); }); assert.deepEqual( diff --git a/docs/cookbook/meetingPlanner.js b/docs/cookbook/meetingPlanner.js index cd933a6681..24bc5f0b5b 100644 --- a/docs/cookbook/meetingPlanner.js +++ b/docs/cookbook/meetingPlanner.js @@ -9,10 +9,10 @@ const timeZones = [ ]; // Start the table at midnight local time -const calendarNow = now.inTimeZone(here); +const calendarNow = now.toDateTime(here); const startTime = calendarNow .with(Temporal.Time.from('00:00')) // midnight - .inTimeZone(here); + .toAbsolute(here); // Build the table const table = document.getElementById('meeting-planner'); @@ -26,7 +26,7 @@ timeZones.forEach(({ name, tz }) => { for (let hours = 0; hours < 24; hours++) { const cell = document.createElement('td'); - const dt = startTime.plus({ hours }).inTimeZone(tz); + const dt = startTime.plus({ hours }).toDateTime(tz); cell.className = `time-${dt.hour}`; // Highlight the current hour in each row diff --git a/docs/cookbook/nextWeeklyOccurrence.mjs b/docs/cookbook/nextWeeklyOccurrence.mjs index 06c031fe7c..6100df96ed 100644 --- a/docs/cookbook/nextWeeklyOccurrence.mjs +++ b/docs/cookbook/nextWeeklyOccurrence.mjs @@ -10,7 +10,7 @@ * @returns {Temporal.DateTime} Local date and time of next occurrence */ function nextWeeklyOccurrence(now, localTimeZone, weekday, eventTime, eventTimeZone) { - const dateTime = now.inTimeZone(eventTimeZone); + const dateTime = now.toDateTime(eventTimeZone); const nextDate = dateTime.getDate().plus({ days: (weekday + 7 - dateTime.dayOfWeek) % 7 }); let nextOccurrence = nextDate.withTime(eventTime); @@ -19,7 +19,7 @@ function nextWeeklyOccurrence(now, localTimeZone, weekday, eventTime, eventTimeZ nextOccurrence = nextOccurrence.plus({ days: 7 }); } - return nextOccurrence.inTimeZone(eventTimeZone).inTimeZone(localTimeZone); + return nextOccurrence.toAbsolute(eventTimeZone).toDateTime(localTimeZone); } // "Weekly on Thursdays at 08:45 California time": diff --git a/docs/cookbook/storageTank.js b/docs/cookbook/storageTank.js index d0e1590e38..0a80265003 100644 --- a/docs/cookbook/storageTank.js +++ b/docs/cookbook/storageTank.js @@ -4,7 +4,7 @@ // Show data starting from the most recent midnight in the tank's location (Stockholm) const tankTimeZone = Temporal.TimeZone.from('Europe/Stockholm'); -const tankMidnight = Temporal.now.dateTime(tankTimeZone).with(Temporal.Time.from('00:00')).inTimeZone(tankTimeZone); +const tankMidnight = Temporal.now.dateTime(tankTimeZone).with(Temporal.Time.from('00:00')).toAbsolute(tankTimeZone); const atOrAfterMidnight = (x) => Temporal.Absolute.compare(x, tankMidnight) >= 0; const dataStartIndex = tankDataX.findIndex(atOrAfterMidnight); const labelFormatter = new Intl.DateTimeFormat(undefined, { diff --git a/docs/datetime.md b/docs/datetime.md index d244737687..f9f2eb1745 100644 --- a/docs/datetime.md +++ b/docs/datetime.md @@ -46,7 +46,7 @@ Together, `isoYear`, `isoMonth`, and `isoDay` must represent a valid date in tha > **NOTE**: Although Temporal does not deal with leap seconds, dates coming from other software may have a `second` value of 60. > This value will cause the constructor will throw, so if you have to interoperate with times that may contain leap seconds, use `Temporal.DateTime.from()` instead. -The range of allowed values for this type is exactly enough that calling [`inTimeZone()`](./absolute.html#inTimeZone) on any valid `Temporal.Absolute` with any valid `Temporal.TimeZone` will succeed. +The range of allowed values for this type is exactly enough that calling [`toDateTime()`](./absolute.html#toDateTime) on any valid `Temporal.Absolute` with any valid `Temporal.TimeZone` will succeed. If the parameters passed in to this constructor form a date outside of this range, then this function will throw a `RangeError`. > **NOTE**: The `isoMonth` argument ranges from 1 to 12, which is different from legacy `Date` where months are represented by zero-based indices (0 to 11). @@ -573,7 +573,7 @@ This method overrides `Object.prototype.valueOf()` and always throws an exceptio This is because it's not possible to compare `Temporal.DateTime` objects with the relational operators `<`, `<=`, `>`, or `>=`. Use `Temporal.DateTime.compare()` for this, or `datetime.equals()` for equality. -### datetime.**inTimeZone**(_timeZone_ : object | string, _options_?: object) : Temporal.Absolute +### datetime.**toAbsolute**(_timeZone_ : object | string, _options_?: object) : Temporal.Absolute **Parameters:** - `timeZone` (optional string or object): The time zone in which to interpret `dateTime`, as a `Temporal.TimeZone` object, an object implementing the [time zone protocol](./timezone.md#protocol), or a string. diff --git a/docs/now.md b/docs/now.md index 7fbc4c5814..d9d21d3832 100644 --- a/docs/now.md +++ b/docs/now.md @@ -48,8 +48,8 @@ now = Temporal.now.absolute(); nextTransition = tz.getNextTransition(now); before = tz.getOffsetStringFor(nextTransition.minus({nanoseconds: 1})); after = tz.getOffsetStringFor(nextTransition.plus({nanoseconds: 1})); -console.log(`On ${nextTransition.inTimeZone(tz)} the clock will change from UTC ${before} to ${after}`); -nextTransition.inTimeZone(tz); +console.log(`On ${nextTransition.toDateTime(tz)} the clock will change from UTC ${before} to ${after}`); +nextTransition.toDateTime(tz); // example output: // On 2020-03-08T03:00 the clock will change from UTC -08:00 to -07:00 ``` diff --git a/docs/timezone.md b/docs/timezone.md index 13a24bd018..8aa6bb5637 100644 --- a/docs/timezone.md +++ b/docs/timezone.md @@ -60,7 +60,7 @@ For example: ```javascript tz1 = new Temporal.TimeZone('-08:00'); tz2 = new Temporal.TimeZone('America/Vancouver'); -abs = Temporal.DateTime.from({year: 2020, month: 1, day: 1}).inTimeZone(tz2); +abs = Temporal.DateTime.from({year: 2020, month: 1, day: 1}).toAbsolute(tz2); tz1.getNextTransition(abs); // => null tz2.getPreviousTransition(abs); // => 2020-03-08T10:00Z ``` @@ -211,7 +211,7 @@ tz.getDateTimeFor(epoch); // => 1969-12-31T19:00 **Returns:** A `Temporal.Absolute` object indicating the absolute time in `timeZone` at the time of the calendar date and wall-clock time from `dateTime`. This method is one way to convert a `Temporal.DateTime` to a `Temporal.Absolute`. -It is identical to [`dateTime.inTimeZone(timeZone, disambiguation)`](./datetime.html#inTimeZone). +It is identical to [`dateTime.toAbsolute(timeZone, disambiguation)`](./datetime.html#toAbsolute). In the case of ambiguity, the `disambiguation` option controls what absolute time to return: - `'compatible'` (the default): Acts like `'earlier'` for backward transitions and `'later'` for forward transitions. @@ -286,7 +286,7 @@ Example usage: // How long until the previous DST change from now, in the current location? tz = Temporal.now.timeZone(); now = Temporal.now.absolute(); -previousTransition = tz.getPreviousTransition(now); +previousTransition = tz.getPreviousTransition(now); duration = now.difference(previousTransition); duration.toLocaleString(); // output will vary ``` From ad2b6817fe89f9917def6c63948005505e657acf Mon Sep 17 00:00:00 2001 From: Ujjwal Sharma Date: Mon, 29 Jun 2020 18:06:56 +0530 Subject: [PATCH 04/27] polyfill: rename withYear to toDate --- polyfill/index.d.ts | 2 +- polyfill/lib/monthday.mjs | 2 +- .../prototype/withYear/infinity-throws-rangeerror.js | 10 +++++----- .../withYear/negative-infinity-throws-rangeerror.js | 10 +++++----- polyfill/test/date.mjs | 8 ++++---- polyfill/test/monthday.mjs | 12 ++++++------ 6 files changed, 22 insertions(+), 22 deletions(-) diff --git a/polyfill/index.d.ts b/polyfill/index.d.ts index 52d73cb80d..509cb7518b 100644 --- a/polyfill/index.d.ts +++ b/polyfill/index.d.ts @@ -512,7 +512,7 @@ export namespace Temporal { readonly calendar: CalendarProtocol; equals(other: Temporal.MonthDay): boolean; with(monthDayLike: MonthDayLike, options?: AssignmentOptions): Temporal.MonthDay; - withYear(year: number | { era?: string | undefined; year: number }): Temporal.Date; + toDate(year: number | { era?: string | undefined; year: number }): Temporal.Date; getFields(): MonthDayFields; getISOCalendarFields(): DateISOCalendarFields; toLocaleString(locales?: string | string[], options?: Intl.DateTimeFormatOptions): string; diff --git a/polyfill/lib/monthday.mjs b/polyfill/lib/monthday.mjs index a1f98da970..ad4e215850 100644 --- a/polyfill/lib/monthday.mjs +++ b/polyfill/lib/monthday.mjs @@ -91,7 +91,7 @@ export class MonthDay { valueOf() { throw new TypeError('use equals() to compare Temporal.MonthDay'); } - withYear(item) { + toDate(item) { if (!ES.IsTemporalMonthDay(this)) throw new TypeError('invalid receiver'); let era, year; if (typeof item === 'object' && item !== null) { diff --git a/polyfill/test/MonthDay/prototype/withYear/infinity-throws-rangeerror.js b/polyfill/test/MonthDay/prototype/withYear/infinity-throws-rangeerror.js index 9a1aaebe13..695fde4697 100644 --- a/polyfill/test/MonthDay/prototype/withYear/infinity-throws-rangeerror.js +++ b/polyfill/test/MonthDay/prototype/withYear/infinity-throws-rangeerror.js @@ -2,14 +2,14 @@ // This code is governed by the BSD license found in the LICENSE file. /*--- -description: Temporal.MonthDay.prototype.withYear throws a RangeError if the argument is Infinity -esid: sec-temporal.monthday.prototype.withyear +description: Temporal.MonthDay.prototype.toDate throws a RangeError if the argument is Infinity +esid: sec-temporal.monthday.prototype.todate ---*/ const instance = new Temporal.MonthDay(5, 2); -assert.throws(RangeError, () => instance.withYear(Infinity)); -assert.throws(RangeError, () => instance.withYear({ year: Infinity })); +assert.throws(RangeError, () => instance.toDate(Infinity)); +assert.throws(RangeError, () => instance.toDate({ year: Infinity })); let calls = 0; const fields = { @@ -30,5 +30,5 @@ const obj = new Proxy(fields, { }, }); -assert.throws(RangeError, () => instance.withYear(obj)); +assert.throws(RangeError, () => instance.toDate(obj)); assert.sameValue(calls, 1, "it fails after fetching the primitive value"); diff --git a/polyfill/test/MonthDay/prototype/withYear/negative-infinity-throws-rangeerror.js b/polyfill/test/MonthDay/prototype/withYear/negative-infinity-throws-rangeerror.js index cdd5689fac..9a8fdc2eaf 100644 --- a/polyfill/test/MonthDay/prototype/withYear/negative-infinity-throws-rangeerror.js +++ b/polyfill/test/MonthDay/prototype/withYear/negative-infinity-throws-rangeerror.js @@ -2,14 +2,14 @@ // This code is governed by the BSD license found in the LICENSE file. /*--- -description: Temporal.MonthDay.prototype.withYear throws a RangeError if the argument is -Infinity -esid: sec-temporal.monthday.prototype.withyear +description: Temporal.MonthDay.prototype.toDate throws a RangeError if the argument is -Infinity +esid: sec-temporal.monthday.prototype.todate ---*/ const instance = new Temporal.MonthDay(5, 2); -assert.throws(RangeError, () => instance.withYear(-Infinity)); -assert.throws(RangeError, () => instance.withYear({ year: -Infinity })); +assert.throws(RangeError, () => instance.toDate(-Infinity)); +assert.throws(RangeError, () => instance.toDate({ year: -Infinity })); let calls = 0; const fields = { @@ -30,5 +30,5 @@ const obj = new Proxy(fields, { }, }); -assert.throws(RangeError, () => instance.withYear(obj)); +assert.throws(RangeError, () => instance.toDate(obj)); assert.sameValue(calls, 1, "it fails after fetching the primitive value"); diff --git a/polyfill/test/date.mjs b/polyfill/test/date.mjs index d2a4f93008..0bdfb21cf8 100644 --- a/polyfill/test/date.mjs +++ b/polyfill/test/date.mjs @@ -521,10 +521,10 @@ describe('Date', () => { const dec31 = Temporal.MonthDay.from('12-31'); const minYear = -271821; const maxYear = 275760; - throws(() => jan1.withYear(minYear), RangeError); - throws(() => dec31.withYear(maxYear), RangeError); - equal(`${jan1.withYear(minYear + 1)}`, '-271820-01-01'); - equal(`${dec31.withYear(maxYear - 1)}`, '+275759-12-31'); + throws(() => jan1.toDate(minYear), RangeError); + throws(() => dec31.toDate(maxYear), RangeError); + equal(`${jan1.toDate(minYear + 1)}`, '-271820-01-01'); + equal(`${dec31.toDate(maxYear - 1)}`, '+275759-12-31'); }); it('adding and subtracting beyond limit', () => { const min = Date.from('-271821-04-19'); diff --git a/polyfill/test/monthday.mjs b/polyfill/test/monthday.mjs index 8b015919fd..08845786a2 100644 --- a/polyfill/test/monthday.mjs +++ b/polyfill/test/monthday.mjs @@ -154,20 +154,20 @@ describe('MonthDay', () => { it('<=', () => throws(() => md1 <= md2)); it('>=', () => throws(() => md1 >= md2)); }); - describe('MonthDay.withYear()', () => { + describe('MonthDay.toDate()', () => { const md = MonthDay.from('01-22'); it('takes a number argument', () => { - equal(`${md.withYear(2002)}`, '2002-01-22'); + equal(`${md.toDate(2002)}`, '2002-01-22'); }); it('takes an object argument with year property', () => { - equal(`${md.withYear({ year: 2002 })}`, '2002-01-22'); + equal(`${md.toDate({ year: 2002 })}`, '2002-01-22'); }); it('needs at least a year property on the object in the ISO calendar', () => { - throws(() => md.withYear({ something: 'nothing' }), TypeError); + throws(() => md.toDate({ something: 'nothing' }), TypeError); }); it('converts a non-object argument to integer', () => { - equal(`${md.withYear('2002')}`, '2002-01-22'); - equal(`${md.withYear(null)}`, '+000000-01-22'); + equal(`${md.toDate('2002')}`, '2002-01-22'); + equal(`${md.toDate(null)}`, '+000000-01-22'); }); }); describe('monthDay.getFields() works', () => { From 5a4e5e2c2a4a8de9b02f8ef29f66dbfd711c689c Mon Sep 17 00:00:00 2001 From: Ujjwal Sharma Date: Mon, 29 Jun 2020 18:11:05 +0530 Subject: [PATCH 05/27] spec: rename withYear to toDate --- spec/monthday.html | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/spec/monthday.html b/spec/monthday.html index c7bd4230ac..8e84c61c85 100644 --- a/spec/monthday.html +++ b/spec/monthday.html @@ -223,10 +223,10 @@

Temporal.MonthDay.prototype.valueOf ( )

- -

Temporal.MonthDay.prototype.withYear ( _item_ )

+ +

Temporal.MonthDay.prototype.toDate ( _item_ )

- The `withYear` method takes one argument _item_. + The `toDate` method takes one argument _item_. The following steps are taken:

From a0d7ffce90d8efd5c9da239a92618deff7101224 Mon Sep 17 00:00:00 2001 From: Ujjwal Sharma Date: Mon, 29 Jun 2020 18:13:47 +0530 Subject: [PATCH 06/27] docs: rename withYear to toDate --- docs/cookbook/birthdayIn2030.mjs | 2 +- docs/cookbook/bridgePublicHolidays.mjs | 2 +- docs/monthday.md | 18 +++++++++--------- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/docs/cookbook/birthdayIn2030.mjs b/docs/cookbook/birthdayIn2030.mjs index e8a1a240e3..74bdb668bc 100644 --- a/docs/cookbook/birthdayIn2030.mjs +++ b/docs/cookbook/birthdayIn2030.mjs @@ -1,6 +1,6 @@ const birthday = Temporal.MonthDay.from('12-15'); -const birthdayIn2030 = birthday.withYear(2030); +const birthdayIn2030 = birthday.toDate(2030); birthdayIn2030.dayOfWeek; // => 7 assert(birthdayIn2030 instanceof Temporal.Date); diff --git a/docs/cookbook/bridgePublicHolidays.mjs b/docs/cookbook/bridgePublicHolidays.mjs index 4e97d42683..4777ad2ba7 100644 --- a/docs/cookbook/bridgePublicHolidays.mjs +++ b/docs/cookbook/bridgePublicHolidays.mjs @@ -8,7 +8,7 @@ * @returns {Temporal.Date[]} List of dates to be taken off work */ function bridgePublicHolidays(holiday, year) { - const date = holiday.withYear(year); + const date = holiday.toDate(year); switch (date.dayOfWeek) { case 1: // Mon case 3: // Wed diff --git a/docs/monthday.md b/docs/monthday.md index 8752c2b2fa..16a2085589 100644 --- a/docs/monthday.md +++ b/docs/monthday.md @@ -9,7 +9,7 @@ A `Temporal.MonthDay` represents a particular day on the calendar, but without a For example, it could be used to represent a yearly recurring event, like "Bastille Day is on the 14th of July." If you need to refer to a certain instance of a calendar event, in a particular year, use `Temporal.Date` or even `Temporal.DateTime`. -A `Temporal.MonthDay` can be converted into a `Temporal.Date` by combining it with a year, using the `withYear()` method. +A `Temporal.MonthDay` can be converted into a `Temporal.Date` by combining it with a year, using the `toDate()` method. ## Constructor @@ -144,7 +144,7 @@ Since `Temporal.MonthDay` objects are immutable, use this method instead of modi > **NOTE**: Unlike in `Temporal.Date.prototype.with()`, a `calendar` property is not allowed on `monthDayLike`. > It is not possible to convert a `Temporal.MonthDay` to another calendar system without knowing the year. -> If you need to do this, use `monthDay.withYear(year).withCalendar(calendar).getMonthDay()`. +> If you need to do this, use `monthDay.toDate(year).withCalendar(calendar).getMonthDay()`. Usage example: ```javascript @@ -249,7 +249,7 @@ This method overrides `Object.prototype.valueOf()` and always throws an exceptio This is because it's not possible to compare `Temporal.MonthDay` objects with the relational operators `<`, `<=`, `>`, or `>=`. Instead, use `monthDay.equals()` to check for equality. -### monthDay.**withYear**(_year_: number | object) : Temporal.Date +### monthDay.**toDate**(_year_: number | object) : Temporal.Date **Parameters:** - `year` (number | object): A year, which must have a day corresponding to `monthDay`. Additionally, an object with a `'year'` property is also accepted. @@ -262,15 +262,15 @@ The converted object carries a copy of all the relevant fields of `monthDay`. Usage example: ```javascript md = Temporal.MonthDay.from('08-24'); -md.withYear(2017) // => 2017-08-24 -md.withYear({ year: 2017 }) // equivalent to above +md.toDate(2017) // => 2017-08-24 +md.toDate({ year: 2017 }) // equivalent to above md = Temporal.MonthDay.from('02-29'); -md.withYear(2017) // throws -md.withYear(2020) // => 2020-02-29 +md.toDate(2017) // throws +md.toDate(2020) // => 2020-02-29 ``` -In calendars where more information than just the year is needed to convert a `Temporal.MonthDay` to a `Temporal.Date`, you can pass an object to `withYear()` that contains the necessary properties. +In calendars where more information than just the year is needed to convert a `Temporal.MonthDay` to a `Temporal.Date`, you can pass an object to `toDate()` that contains the necessary properties. Example: ```javascript @@ -280,7 +280,7 @@ md = Temporal.MonthDay.from({ day: 1 }); -date = md.withYear({ era: 'reiwa', year: 2 }); +date = md.toDate({ era: 'reiwa', year: 2 }); ``` ### monthDay.**getFields**() : { month: number, day: number, calendar: object, [propName: string]: unknown } From 90d062261149786e3657eb5fe6149a9ab68bca8e Mon Sep 17 00:00:00 2001 From: Ujjwal Sharma Date: Mon, 29 Jun 2020 18:20:11 +0530 Subject: [PATCH 07/27] polyfill: rename withDay to toDate --- polyfill/index.d.ts | 2 +- polyfill/lib/yearmonth.mjs | 2 +- .../prototype/withDay/infinity-throws-rangeerror.js | 8 ++++---- .../withDay/negative-infinity-throws-rangeerror.js | 8 ++++---- polyfill/test/date.mjs | 8 ++++---- 5 files changed, 14 insertions(+), 14 deletions(-) diff --git a/polyfill/index.d.ts b/polyfill/index.d.ts index 509cb7518b..bfd8b4db1f 100644 --- a/polyfill/index.d.ts +++ b/polyfill/index.d.ts @@ -655,7 +655,7 @@ export namespace Temporal { plus(durationLike: Temporal.Duration | DurationLike, options?: ArithmeticOptions): Temporal.YearMonth; minus(durationLike: Temporal.Duration | DurationLike, options?: ArithmeticOptions): Temporal.YearMonth; difference(other: Temporal.YearMonth, options?: DifferenceOptions<'years' | 'months'>): Temporal.Duration; - withDay(day: number): Temporal.Date; + toDate(day: number): Temporal.Date; getFields(): YearMonthFields; getISOCalendarFields(): DateISOCalendarFields; toLocaleString(locales?: string | string[], options?: Intl.DateTimeFormatOptions): string; diff --git a/polyfill/lib/yearmonth.mjs b/polyfill/lib/yearmonth.mjs index 153de5b4e3..7b4b0c1c81 100644 --- a/polyfill/lib/yearmonth.mjs +++ b/polyfill/lib/yearmonth.mjs @@ -175,7 +175,7 @@ export class YearMonth { valueOf() { throw new TypeError('use compare() or equals() to compare Temporal.YearMonth'); } - withDay(day) { + toDate(day) { if (!ES.IsTemporalYearMonth(this)) throw new TypeError('invalid receiver'); const calendar = GetSlot(this, CALENDAR); const fields = ES.ToTemporalYearMonthRecord(this); diff --git a/polyfill/test/YearMonth/prototype/withDay/infinity-throws-rangeerror.js b/polyfill/test/YearMonth/prototype/withDay/infinity-throws-rangeerror.js index 38092dd01d..5b211e5e16 100644 --- a/polyfill/test/YearMonth/prototype/withDay/infinity-throws-rangeerror.js +++ b/polyfill/test/YearMonth/prototype/withDay/infinity-throws-rangeerror.js @@ -2,13 +2,13 @@ // This code is governed by the BSD license found in the LICENSE file. /*--- -description: Temporal.YearMonth.prototype.withDay throws a RangeError if the argument is Infinity -esid: sec-temporal.yearmonth.prototype.withday +description: Temporal.YearMonth.prototype.toDate throws a RangeError if the argument is Infinity +esid: sec-temporal.yearmonth.prototype.todate ---*/ const instance = new Temporal.YearMonth(2000, 5); -assert.throws(RangeError, () => instance.withDay(Infinity)); +assert.throws(RangeError, () => instance.toDate(Infinity)); let calls = 0; const obj = { @@ -18,5 +18,5 @@ const obj = { } }; -assert.throws(RangeError, () => instance.withDay(obj)); +assert.throws(RangeError, () => instance.toDate(obj)); assert.sameValue(calls, 1, "it fails after fetching the primitive value"); diff --git a/polyfill/test/YearMonth/prototype/withDay/negative-infinity-throws-rangeerror.js b/polyfill/test/YearMonth/prototype/withDay/negative-infinity-throws-rangeerror.js index 9b016a2716..dde995bddd 100644 --- a/polyfill/test/YearMonth/prototype/withDay/negative-infinity-throws-rangeerror.js +++ b/polyfill/test/YearMonth/prototype/withDay/negative-infinity-throws-rangeerror.js @@ -2,13 +2,13 @@ // This code is governed by the BSD license found in the LICENSE file. /*--- -description: Temporal.YearMonth.prototype.withDay throws a RangeError if the argument is -Infinity -esid: sec-temporal.yearmonth.prototype.withday +description: Temporal.YearMonth.prototype.toDate throws a RangeError if the argument is -Infinity +esid: sec-temporal.yearmonth.prototype.todate ---*/ const instance = new Temporal.YearMonth(2000, 5); -assert.throws(RangeError, () => instance.withDay(-Infinity)); +assert.throws(RangeError, () => instance.toDate(-Infinity)); let calls = 0; const obj = { @@ -18,5 +18,5 @@ const obj = { } }; -assert.throws(RangeError, () => instance.withDay(obj)); +assert.throws(RangeError, () => instance.toDate(obj)); assert.sameValue(calls, 1, "it fails after fetching the primitive value"); diff --git a/polyfill/test/date.mjs b/polyfill/test/date.mjs index 0bdfb21cf8..d34422ee38 100644 --- a/polyfill/test/date.mjs +++ b/polyfill/test/date.mjs @@ -511,10 +511,10 @@ describe('Date', () => { it('converting from YearMonth', () => { const min = Temporal.YearMonth.from('-271821-04'); const max = Temporal.YearMonth.from('+275760-09'); - throws(() => min.withDay(1), RangeError); - throws(() => max.withDay(30), RangeError); - equal(`${min.withDay(19)}`, '-271821-04-19'); - equal(`${max.withDay(13)}`, '+275760-09-13'); + throws(() => min.toDate(1), RangeError); + throws(() => max.toDate(30), RangeError); + equal(`${min.toDate(19)}`, '-271821-04-19'); + equal(`${max.toDate(13)}`, '+275760-09-13'); }); it('converting from MonthDay', () => { const jan1 = Temporal.MonthDay.from('01-01'); From d5dfcda293b756b0811ccbae4faaf1a88856e5aa Mon Sep 17 00:00:00 2001 From: Ujjwal Sharma Date: Mon, 29 Jun 2020 18:31:55 +0530 Subject: [PATCH 08/27] spec: rename withDay to toDate --- spec/yearmonth.html | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/spec/yearmonth.html b/spec/yearmonth.html index 5d6ac9c6b4..2b073a8251 100644 --- a/spec/yearmonth.html +++ b/spec/yearmonth.html @@ -340,10 +340,10 @@

Temporal.YearMonth.prototype.valueOf ( )

- -

Temporal.YearMonth.prototype.withDay ( _day_ )

+ +

Temporal.YearMonth.prototype.toDate ( _day_ )

- The `withDay` method takes one argument _day_. + The `toDate` method takes one argument _day_. The following steps are taken:

From 3845d048fa52ffce9c2d10b9465f5715d6afda25 Mon Sep 17 00:00:00 2001 From: Ujjwal Sharma Date: Mon, 29 Jun 2020 18:32:05 +0530 Subject: [PATCH 09/27] docs: rename withDay to toDate --- docs/cookbook/getFirstTuesdayOfMonth.mjs | 6 +++--- docs/cookbook/getWeeklyDaysInMonth.mjs | 2 +- docs/yearmonth.md | 10 +++++----- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/docs/cookbook/getFirstTuesdayOfMonth.mjs b/docs/cookbook/getFirstTuesdayOfMonth.mjs index 6362f410ad..e09418bfc1 100644 --- a/docs/cookbook/getFirstTuesdayOfMonth.mjs +++ b/docs/cookbook/getFirstTuesdayOfMonth.mjs @@ -6,7 +6,7 @@ */ function getFirstTuesday(queriedMonth) { // We first need to convert to a date - const firstOfMonth = queriedMonth.withDay(1); + const firstOfMonth = queriedMonth.toDate(1); // We have Monday = 1, Sunday = 7, and we want to add a positive number // smaller than 7 to get to the first Tuesday. @@ -24,12 +24,12 @@ assert.equal(firstTuesdayOfMonth.toString(), '2020-02-04'); assert.equal(firstTuesdayOfMonth.dayOfWeek, 2); // Similarly, to get the second Tuesday: -const secondWeek = myMonth.withDay(8); +const secondWeek = myMonth.toDate(8); const secondTuesday = secondWeek.plus({ days: [1, 0, 6, 5, 4, 3, 2][secondWeek.dayOfWeek - 1] }); assert.equal(secondTuesday.day, firstTuesdayOfMonth.day + 7); // And the last Tuesday: -const lastOfMonth = myMonth.withDay(myMonth.daysInMonth); +const lastOfMonth = myMonth.toDate(myMonth.daysInMonth); const lastTuesday = lastOfMonth.minus({ days: [6, 0, 1, 2, 3, 4, 5][lastOfMonth.dayOfWeek - 1] }); assert.equal(lastTuesday.toString(), '2020-02-25'); assert.equal(lastTuesday.dayOfWeek, 2); diff --git a/docs/cookbook/getWeeklyDaysInMonth.mjs b/docs/cookbook/getWeeklyDaysInMonth.mjs index cf47ee5d4c..15ae9b27d1 100644 --- a/docs/cookbook/getWeeklyDaysInMonth.mjs +++ b/docs/cookbook/getWeeklyDaysInMonth.mjs @@ -7,7 +7,7 @@ * @returns {Temporal.Date[]} Array of dates */ function getWeeklyDaysInMonth(yearMonth, dayNumberOfTheWeek) { - const firstOfMonth = yearMonth.withDay(1); + const firstOfMonth = yearMonth.toDate(1); let nextWeekday = firstOfMonth.plus({ days: (7 + dayNumberOfTheWeek - firstOfMonth.dayOfWeek) % 7 }); const result = []; while (nextWeekday.month === yearMonth.month) { diff --git a/docs/yearmonth.md b/docs/yearmonth.md index 3202563a43..5df95e6c67 100644 --- a/docs/yearmonth.md +++ b/docs/yearmonth.md @@ -9,7 +9,7 @@ A `Temporal.YearMonth` represents a particular month on the calendar. For example, it could be used to represent a particular instance of a monthly recurring event, like "the June 2019 meeting". `Temporal.YearMonth` refers to the whole of a specific month; if you need to refer to a calendar event on a certain day, use `Temporal.Date` or even `Temporal.DateTime`. -A `Temporal.YearMonth` can be converted into a `Temporal.Date` by combining it with a day of the month, using the `withDay()` method. +A `Temporal.YearMonth` can be converted into a `Temporal.Date` by combining it with a day of the month, using the `toDate()` method. ## Constructor @@ -220,7 +220,7 @@ If the result is earlier or later than the range of dates that `Temporal.YearMon > **NOTE**: Unlike in `Temporal.Date.prototype.with()`, a `calendar` property is not allowed on `yearMonthLike`. > It is not possible to convert a `Temporal.YearMonth` to another calendar system without knowing the day of the month. -> If you need to do this, use `yearMonth.withDay(day).withCalendar(calendar).getYearMonth()`. +> If you need to do this, use `yearMonth.toDate(day).withCalendar(calendar).getYearMonth()`. Usage example: ```javascript @@ -321,7 +321,7 @@ other.difference(ym, { largestUnit: 'months' }) // => throws RangeError // day of the month (and if applicable, the time of that day) from which // you want to reckon the difference. For example, using the first of // the month to calculate a number of days: -ym.withDay(1).difference(other.withDay(1), { largestUnit: 'days' }); // => P4687D +ym.toDate(1).difference(other.toDate(1), { largestUnit: 'days' }); // => P4687D ``` ### yearMonth.**equals**(_other_: Temporal.YearMonth) : boolean @@ -429,7 +429,7 @@ This method overrides `Object.prototype.valueOf()` and always throws an exceptio This is because it's not possible to compare `Temporal.YearMonth` objects with the relational operators `<`, `<=`, `>`, or `>=`. Use `Temporal.YearMonth.compare()` for this, or `yearMonth.equals()` for equality. -### yearMonth.**withDay**(_day_: number) : Temporal.Date +### yearMonth.**toDate**(_day_: number) : Temporal.Date **Parameters:** - `day` (number): A day of the month, which must be a valid day of `yearMonth`. @@ -442,7 +442,7 @@ The converted object carries a copy of all the relevant fields of `yearMonth`. Usage example: ```javascript ym = Temporal.YearMonth.from('2019-06'); -ym.withDay(24) // => 2019-06-24 +ym.toDate(24) // => 2019-06-24 ``` ### yearMonth.**getFields**() : { year: number, month: number, calendar: object, [propName: string]: unknown } From 343670cc31cb64a059f40982d3e4e87a49e6478b Mon Sep 17 00:00:00 2001 From: Ujjwal Sharma Date: Mon, 29 Jun 2020 18:43:16 +0530 Subject: [PATCH 10/27] polyfill: rename withDate to toDateTime --- polyfill/index.d.ts | 4 ++-- polyfill/lib/intl.mjs | 2 +- polyfill/lib/time.mjs | 2 +- polyfill/test/datetime.mjs | 6 +++--- polyfill/test/time.mjs | 12 ++++++------ 5 files changed, 13 insertions(+), 13 deletions(-) diff --git a/polyfill/index.d.ts b/polyfill/index.d.ts index bfd8b4db1f..ddb0818523 100644 --- a/polyfill/index.d.ts +++ b/polyfill/index.d.ts @@ -542,7 +542,7 @@ export namespace Temporal { * need to refer to a specific time on a specific day, use * `Temporal.DateTime`. A `Temporal.Time` can be converted into a * `Temporal.DateTime` by combining it with a `Temporal.Date` using the - * `withDate()` method. + * `toDateTime()` method. * * See https://tc39.es/proposal-temporal/docs/time.html for more details. */ @@ -568,7 +568,7 @@ export namespace Temporal { plus(durationLike: Temporal.Duration | DurationLike, options?: ArithmeticOptions): Temporal.Time; minus(durationLike: Temporal.Duration | DurationLike, options?: ArithmeticOptions): Temporal.Time; difference(other: Temporal.Time, options?: DifferenceOptions<'hours' | 'minutes' | 'seconds'>): Temporal.Duration; - withDate(temporalDate: Temporal.Date): Temporal.DateTime; + toDateTime(temporalDate: Temporal.Date): Temporal.DateTime; getFields(): TimeFields; toLocaleString(locales?: string | string[], options?: Intl.DateTimeFormatOptions): string; toJSON(): string; diff --git a/polyfill/lib/intl.mjs b/polyfill/lib/intl.mjs index 43ba4a217e..0e9a22f5ec 100644 --- a/polyfill/lib/intl.mjs +++ b/polyfill/lib/intl.mjs @@ -203,7 +203,7 @@ function extractOverrides(datetime, main) { const YearMonth = GetIntrinsic('%Temporal.YearMonth%'); if (datetime instanceof Time) { - datetime = datetime.withDate(new Date(1970, 1, 1)); + datetime = datetime.toDateTime(new Date(1970, 1, 1)); formatter = main[TIME]; } if (datetime instanceof YearMonth) { diff --git a/polyfill/lib/time.mjs b/polyfill/lib/time.mjs index 5c23c56ff5..74ba083e9c 100644 --- a/polyfill/lib/time.mjs +++ b/polyfill/lib/time.mjs @@ -228,7 +228,7 @@ export class Time { throw new TypeError('use compare() or equals() to compare Temporal.Time'); } - withDate(temporalDate) { + toDateTime(temporalDate) { if (!ES.IsTemporalTime(this)) throw new TypeError('invalid receiver'); if (!ES.IsTemporalDate(temporalDate)) throw new TypeError('invalid Temporal.Date object'); const year = GetSlot(temporalDate, ISO_YEAR); diff --git a/polyfill/test/datetime.mjs b/polyfill/test/datetime.mjs index 03b4d7a577..151a9c795d 100644 --- a/polyfill/test/datetime.mjs +++ b/polyfill/test/datetime.mjs @@ -590,11 +590,11 @@ describe('DateTime', () => { const min = Temporal.Date.from('-271821-04-19'); const max = Temporal.Date.from('+275760-09-13'); throws(() => min.withTime(midnight), RangeError); - throws(() => midnight.withDate(min), RangeError); + throws(() => midnight.toDateTime(min), RangeError); equal(`${min.withTime(firstNs)}`, '-271821-04-19T00:00:00.000000001'); - equal(`${firstNs.withDate(min)}`, '-271821-04-19T00:00:00.000000001'); + equal(`${firstNs.toDateTime(min)}`, '-271821-04-19T00:00:00.000000001'); equal(`${max.withTime(lastNs)}`, '+275760-09-13T23:59:59.999999999'); - equal(`${lastNs.withDate(max)}`, '+275760-09-13T23:59:59.999999999'); + equal(`${lastNs.toDateTime(max)}`, '+275760-09-13T23:59:59.999999999'); }); it('adding and subtracting beyond limit', () => { const min = DateTime.from('-271821-04-19T00:00:00.000000001'); diff --git a/polyfill/test/time.mjs b/polyfill/test/time.mjs index 50d394f61f..3e5f1dc291 100644 --- a/polyfill/test/time.mjs +++ b/polyfill/test/time.mjs @@ -60,8 +60,8 @@ describe('Time', () => { it('Time.prototype.equals is a Function', () => { equal(typeof Time.prototype.equals, 'function'); }); - it('Time.prototype.withDate is a Function', () => { - equal(typeof Time.prototype.withDate, 'function'); + it('Time.prototype.toDateTime is a Function', () => { + equal(typeof Time.prototype.toDateTime, 'function'); }); it('Time.prototype.getFields is a Function', () => { equal(typeof Time.prototype.getFields, 'function'); @@ -193,14 +193,14 @@ describe('Time', () => { ); }); }); - describe('time.withDate() works', () => { + describe('time.toDateTime() works', () => { const time = Time.from('11:30:23.123456789'); - const dt = time.withDate(Temporal.Date.from('1976-11-18')); + const dt = time.toDateTime(Temporal.Date.from('1976-11-18')); it('returns a Temporal.DateTime', () => assert(dt instanceof Temporal.DateTime)); it('combines the date and time', () => equal(`${dt}`, '1976-11-18T11:30:23.123456789')); it("doesn't cast argument", () => { - throws(() => time.withDate({ year: 1976, month: 11, day: 18 }), TypeError); - throws(() => time.withDate('1976-11-18'), TypeError); + throws(() => time.toDateTime({ year: 1976, month: 11, day: 18 }), TypeError); + throws(() => time.toDateTime('1976-11-18'), TypeError); }); }); describe('time.difference() works', () => { From bca9bab9cfdc2baca0b870163a6b44f315a13f93 Mon Sep 17 00:00:00 2001 From: Ujjwal Sharma Date: Mon, 29 Jun 2020 18:44:25 +0530 Subject: [PATCH 11/27] spec: rename withDate to toDateTime --- spec/time.html | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/spec/time.html b/spec/time.html index bd0579436f..2717a34b8a 100644 --- a/spec/time.html +++ b/spec/time.html @@ -323,10 +323,10 @@

Temporal.Time.prototype.equals ( _other_ )

- -

Temporal.Time.prototype.withDate ( _temporalDate_ )

+ +

Temporal.Time.prototype.toDateTime ( _temporalDate_ )

- The `withDate` method takes one argument _temporalDate_. + The `toDateTime` method takes one argument _temporalDate_. The following steps are taken:

From 10670abce54288c940501073c95e72dc8b4c2118 Mon Sep 17 00:00:00 2001 From: Ujjwal Sharma Date: Mon, 29 Jun 2020 18:46:15 +0530 Subject: [PATCH 12/27] docs: rename withDate to toDateTime --- docs/date.md | 2 +- docs/time.md | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/date.md b/docs/date.md index 7c52dfc279..b7e445620e 100644 --- a/docs/date.md +++ b/docs/date.md @@ -517,7 +517,7 @@ Use `Temporal.Date.compare()` for this, or `date.equals()` for equality. This method can be used to convert `Temporal.Date` into a `Temporal.DateTime`, by supplying the time of day to use. The converted object carries a copy of all the relevant fields of `date` and `time`. -This is exactly equivalent to [`time.withDate(date)`](./time.html#withDate). +This is exactly equivalent to [`time.toDateTime(date)`](./time.html#toDateTime). Usage example: ```javascript diff --git a/docs/time.md b/docs/time.md index 16aacadec7..1088b3ec23 100644 --- a/docs/time.md +++ b/docs/time.md @@ -10,7 +10,7 @@ A `Temporal.Time` represents a wall-clock time, with a precision in nanoseconds, For example, it could be used to represent an event that happens daily at a certain time, no matter what time zone. `Temporal.Time` refers to a time with no associated calendar date; if you need to refer to a specific time on a specific day, use `Temporal.DateTime`. -A `Temporal.Time` can be converted into a `Temporal.DateTime` by combining it with a `Temporal.Date` using the `withDate()` method. +A `Temporal.Time` can be converted into a `Temporal.DateTime` by combining it with a `Temporal.Date` using the `toDateTime()` method. ## Constructor @@ -363,7 +363,7 @@ This method overrides `Object.prototype.valueOf()` and always throws an exceptio This is because it's not possible to compare `Temporal.Time` objects with the relational operators `<`, `<=`, `>`, or `>=`. Use `Temporal.Time.compare()` for this, or `time.equals()` for equality. -### time.**withDate**(_date_: Temporal.Date) : Temporal.DateTime +### time.**toDateTime**(_date_: Temporal.Date) : Temporal.DateTime **Parameters:** - `date` (`Temporal.Date`): A calendar date on which to place `time`. @@ -379,7 +379,7 @@ Usage example: ```javascript time = Temporal.Time.from('15:23:30.003'); date = Temporal.Date.from('2006-08-24'); -time.withDate(date) // => 2006-08-24T15:23:30.003 +time.toDateTime(date) // => 2006-08-24T15:23:30.003 ``` ### time.**getFields**() : { hour: number, minute: number, second: number, millisecond: number, microsecond: number, nanosecond: number } From 4a2f4597b9808935846dfdba60a620b2fa385d4e Mon Sep 17 00:00:00 2001 From: Ujjwal Sharma Date: Mon, 29 Jun 2020 18:52:34 +0530 Subject: [PATCH 13/27] polyfill: rename withTime to toDateTime --- polyfill/index.d.ts | 2 +- polyfill/lib/date.mjs | 2 +- polyfill/lib/intl.mjs | 2 +- polyfill/test/date.mjs | 12 ++++++------ polyfill/test/datetime.mjs | 6 +++--- 5 files changed, 12 insertions(+), 12 deletions(-) diff --git a/polyfill/index.d.ts b/polyfill/index.d.ts index ddb0818523..89a37b3ade 100644 --- a/polyfill/index.d.ts +++ b/polyfill/index.d.ts @@ -373,7 +373,7 @@ export namespace Temporal { other: Temporal.Date, options?: DifferenceOptions<'years' | 'months' | 'weeks' | 'days'> ): Temporal.Duration; - withTime(temporalTime: Temporal.Time): Temporal.DateTime; + toDateTime(temporalTime: Temporal.Time): Temporal.DateTime; getYearMonth(): Temporal.YearMonth; getMonthDay(): Temporal.MonthDay; getFields(): DateFields; diff --git a/polyfill/lib/date.mjs b/polyfill/lib/date.mjs index 7d199f2da8..f9484cb445 100644 --- a/polyfill/lib/date.mjs +++ b/polyfill/lib/date.mjs @@ -198,7 +198,7 @@ export class Date { valueOf() { throw new TypeError('use compare() or equals() to compare Temporal.Date'); } - withTime(temporalTime) { + toDateTime(temporalTime) { if (!ES.IsTemporalDate(this)) throw new TypeError('invalid receiver'); if (!ES.IsTemporalTime(temporalTime)) throw new TypeError('invalid Temporal.Time object'); const year = GetSlot(this, ISO_YEAR); diff --git a/polyfill/lib/intl.mjs b/polyfill/lib/intl.mjs index 0e9a22f5ec..80cf2080ba 100644 --- a/polyfill/lib/intl.mjs +++ b/polyfill/lib/intl.mjs @@ -220,7 +220,7 @@ function extractOverrides(datetime, main) { } if (datetime instanceof Date) { calendar = calendar || datetime.calendar.id; - datetime = datetime.withTime(new Time(12, 0)); + datetime = datetime.toDateTime(new Time(12, 0)); formatter = formatter || main[DATE]; } if (datetime instanceof DateTime) { diff --git a/polyfill/test/date.mjs b/polyfill/test/date.mjs index d34422ee38..857fd0f027 100644 --- a/polyfill/test/date.mjs +++ b/polyfill/test/date.mjs @@ -60,8 +60,8 @@ describe('Date', () => { it('Date.prototype.equals is a Function', () => { equal(typeof Date.prototype.equals, 'function'); }); - it('Date.prototype.withTime is a Function', () => { - equal(typeof Date.prototype.withTime, 'function'); + it('Date.prototype.toDateTime is a Function', () => { + equal(typeof Date.prototype.toDateTime, 'function'); }); it('Date.prototype.getYearMonth is a Function', () => { equal(typeof Date.prototype.getYearMonth, 'function'); @@ -145,14 +145,14 @@ describe('Date', () => { ); }); }); - describe('Date.withTime() works', () => { + describe('Date.toDateTime() works', () => { const date = Date.from('1976-11-18'); - const dt = date.withTime(Temporal.Time.from('11:30:23')); + const dt = date.toDateTime(Temporal.Time.from('11:30:23')); it('returns a Temporal.DateTime', () => assert(dt instanceof Temporal.DateTime)); it('combines the date and time', () => equal(`${dt}`, '1976-11-18T11:30:23')); it("doesn't cast argument", () => { - throws(() => date.withTime({ hour: 11, minute: 30, second: 23 }), TypeError); - throws(() => date.withTime('11:30:23'), TypeError); + throws(() => date.toDateTime({ hour: 11, minute: 30, second: 23 }), TypeError); + throws(() => date.toDateTime('11:30:23'), TypeError); }); }); describe('date.difference() works', () => { diff --git a/polyfill/test/datetime.mjs b/polyfill/test/datetime.mjs index 151a9c795d..eac163b284 100644 --- a/polyfill/test/datetime.mjs +++ b/polyfill/test/datetime.mjs @@ -589,11 +589,11 @@ describe('DateTime', () => { const lastNs = Temporal.Time.from('23:59:59.999999999'); const min = Temporal.Date.from('-271821-04-19'); const max = Temporal.Date.from('+275760-09-13'); - throws(() => min.withTime(midnight), RangeError); + throws(() => min.toDateTime(midnight), RangeError); throws(() => midnight.toDateTime(min), RangeError); - equal(`${min.withTime(firstNs)}`, '-271821-04-19T00:00:00.000000001'); + equal(`${min.toDateTime(firstNs)}`, '-271821-04-19T00:00:00.000000001'); equal(`${firstNs.toDateTime(min)}`, '-271821-04-19T00:00:00.000000001'); - equal(`${max.withTime(lastNs)}`, '+275760-09-13T23:59:59.999999999'); + equal(`${max.toDateTime(lastNs)}`, '+275760-09-13T23:59:59.999999999'); equal(`${lastNs.toDateTime(max)}`, '+275760-09-13T23:59:59.999999999'); }); it('adding and subtracting beyond limit', () => { From 6c381a35d1438d7241fc98eedf8762d91aa7a1f7 Mon Sep 17 00:00:00 2001 From: Ujjwal Sharma Date: Mon, 29 Jun 2020 18:53:32 +0530 Subject: [PATCH 14/27] spec: rename withTime to toDateTime --- spec/date.html | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/spec/date.html b/spec/date.html index 145219be03..631434b599 100644 --- a/spec/date.html +++ b/spec/date.html @@ -391,10 +391,10 @@

Temporal.Date.prototype.equals ( _other_ )

- -

Temporal.Date.prototype.withTime ( _temporalTime_ )

+ +

Temporal.Date.prototype.toDateTime ( _temporalTime_ )

- The `withTime` method takes one argument _temporalTime_. + The `toDateTime` method takes one argument _temporalTime_. The following steps are taken:

From fb2a4d2e882de5b2d74f428d96e9913086f6f7c8 Mon Sep 17 00:00:00 2001 From: Ujjwal Sharma Date: Mon, 29 Jun 2020 19:00:41 +0530 Subject: [PATCH 15/27] docs: rename withTime to toDateTime --- docs/cookbook/adjustDayOfMonth.mjs | 2 +- docs/cookbook/calculateDailyOccurrence.mjs | 2 +- docs/cookbook/getBusinessOpenStateText.mjs | 8 ++++---- docs/cookbook/nextWeeklyOccurrence.mjs | 2 +- docs/cookbook/noonOnDate.mjs | 2 +- docs/date.md | 8 ++++---- docs/time.md | 2 +- 7 files changed, 13 insertions(+), 13 deletions(-) diff --git a/docs/cookbook/adjustDayOfMonth.mjs b/docs/cookbook/adjustDayOfMonth.mjs index 6909330f7b..497c4ed1c5 100644 --- a/docs/cookbook/adjustDayOfMonth.mjs +++ b/docs/cookbook/adjustDayOfMonth.mjs @@ -14,6 +14,6 @@ assert.equal(lastOfThisMonth.toString(), '2020-04-30'); // On the 18th of this month at 8 PM: -const thisMonth18thAt8PM = date.with({ day: 18 }).withTime(Temporal.Time.from('20:00')); +const thisMonth18thAt8PM = date.with({ day: 18 }).toDateTime(Temporal.Time.from('20:00')); assert.equal(thisMonth18thAt8PM.toString(), '2020-04-18T20:00'); diff --git a/docs/cookbook/calculateDailyOccurrence.mjs b/docs/cookbook/calculateDailyOccurrence.mjs index 9decb6aec8..a453284b46 100644 --- a/docs/cookbook/calculateDailyOccurrence.mjs +++ b/docs/cookbook/calculateDailyOccurrence.mjs @@ -9,7 +9,7 @@ */ function* calculateDailyOccurrence(startDate, time, timeZone) { for (let date = startDate; ; date = date.plus({ days: 1 })) { - yield date.withTime(time).toAbsolute(timeZone); + yield date.toDateTime(time).toAbsolute(timeZone); } } diff --git a/docs/cookbook/getBusinessOpenStateText.mjs b/docs/cookbook/getBusinessOpenStateText.mjs index 25654829b5..921ce5729a 100644 --- a/docs/cookbook/getBusinessOpenStateText.mjs +++ b/docs/cookbook/getBusinessOpenStateText.mjs @@ -42,8 +42,8 @@ function getBusinessOpenStateText(now, timeZone, businessHours, soonWindow) { const { open, close } = yesterdayHours; if (Temporal.Time.compare(close, open) < 0) { businessHoursOverlappingToday.push({ - open: yesterday.withTime(open).inTimeZone(timeZone), - close: today.withTime(close).inTimeZone(timeZone) + open: yesterday.toDateTime(open).toAbsolute(timeZone), + close: today.toDateTime(close).toAbsolute(timeZone) }); } } @@ -52,8 +52,8 @@ function getBusinessOpenStateText(now, timeZone, businessHours, soonWindow) { const { open, close } = todayHours; const todayOrTomorrow = Temporal.Time.compare(close, open) >= 0 ? today : tomorrow; businessHoursOverlappingToday.push({ - open: today.withTime(open).inTimeZone(timeZone), - close: todayOrTomorrow.withTime(close).inTimeZone(timeZone) + open: today.toDateTime(open).toAbsolute(timeZone), + close: todayOrTomorrow.toDateTime(close).toAbsolute(timeZone) }); } diff --git a/docs/cookbook/nextWeeklyOccurrence.mjs b/docs/cookbook/nextWeeklyOccurrence.mjs index 6100df96ed..33e4d4f35c 100644 --- a/docs/cookbook/nextWeeklyOccurrence.mjs +++ b/docs/cookbook/nextWeeklyOccurrence.mjs @@ -12,7 +12,7 @@ function nextWeeklyOccurrence(now, localTimeZone, weekday, eventTime, eventTimeZone) { const dateTime = now.toDateTime(eventTimeZone); const nextDate = dateTime.getDate().plus({ days: (weekday + 7 - dateTime.dayOfWeek) % 7 }); - let nextOccurrence = nextDate.withTime(eventTime); + let nextOccurrence = nextDate.toDateTime(eventTime); // Handle the case where the event is today but already happened if (Temporal.DateTime.compare(dateTime, nextOccurrence) > 0) { diff --git a/docs/cookbook/noonOnDate.mjs b/docs/cookbook/noonOnDate.mjs index a6eb087d0f..2ee59d61a7 100644 --- a/docs/cookbook/noonOnDate.mjs +++ b/docs/cookbook/noonOnDate.mjs @@ -1,6 +1,6 @@ const date = Temporal.Date.from('2020-05-14'); -const noonOnDate = date.withTime(Temporal.Time.from({ hour: 12 })); +const noonOnDate = date.toDateTime(Temporal.Time.from({ hour: 12 })); assert(noonOnDate instanceof Temporal.DateTime); assert.equal(noonOnDate.toString(), '2020-05-14T12:00'); diff --git a/docs/date.md b/docs/date.md index b7e445620e..261f69a6e1 100644 --- a/docs/date.md +++ b/docs/date.md @@ -10,7 +10,7 @@ A `Temporal.Date` represents a calendar date. For example, it could be used to represent an event on a calendar which happens during the whole day no matter which time zone it's happening in. `Temporal.Date` refers to the whole of a specific day; if you need to refer to a specific time on that day, use `Temporal.DateTime`. -A `Temporal.Date` can be converted into a `Temporal.DateTime` by combining it with a `Temporal.Time` using the `withTime()` method. +A `Temporal.Date` can be converted into a `Temporal.DateTime` by combining it with a `Temporal.Time` using the `toDateTime()` method. `Temporal.YearMonth` and `Temporal.MonthDay` carry less information than `Temporal.Date` and should be used when complete information is not required. @@ -404,7 +404,7 @@ other.difference(date, { largestUnit: 'years' }) // => throws RangeError // point in time from which you want to reckon the difference. For // example, using midnight: midnight = Temporal.Time.from('00:00'); -date.withTime(midnight).difference(other.withTime(midnight), { largestUnit: 'hours' }) +date.toDateTime(midnight).difference(other.toDateTime(midnight), { largestUnit: 'hours' }) // => PT109032H ``` @@ -507,7 +507,7 @@ This method overrides `Object.prototype.valueOf()` and always throws an exceptio This is because it's not possible to compare `Temporal.Date` objects with the relational operators `<`, `<=`, `>`, or `>=`. Use `Temporal.Date.compare()` for this, or `date.equals()` for equality. -### date.**withTime**(_time_: Temporal.Time) : Temporal.DateTime +### date.**toDateTime**(_time_: Temporal.Time) : Temporal.DateTime **Parameters:** - `time` (`Temporal.Time`): A time of day on `date`. @@ -523,7 +523,7 @@ Usage example: ```javascript date = Temporal.Date.from('2006-08-24'); time = Temporal.Time.from('15:23:30.003'); -date.withTime(time) // => 2006-08-24T15:23:30.003 +date.toDateTime(time) // => 2006-08-24T15:23:30.003 ``` ### date.**getYearMonth**() : Temporal.YearMonth diff --git a/docs/time.md b/docs/time.md index 1088b3ec23..40b7ca6b56 100644 --- a/docs/time.md +++ b/docs/time.md @@ -373,7 +373,7 @@ Use `Temporal.Time.compare()` for this, or `time.equals()` for equality. This method can be used to convert `Temporal.Time` into a `Temporal.DateTime`, by supplying the calendar date to use. The converted object carries a copy of all the relevant fields of `date` and `time`. -This is exactly equivalent to [`date.withTime(time)`](./date.html#withTime). +This is exactly equivalent to [`date.toDateTime(time)`](./date.html#toDateTime). Usage example: ```javascript From 8994165693daf3f7b0378538084385c3446c0672 Mon Sep 17 00:00:00 2001 From: Ujjwal Sharma Date: Wed, 1 Jul 2020 18:42:40 +0530 Subject: [PATCH 16/27] polyfill: rename getDate to toDate --- polyfill/index.d.ts | 2 +- polyfill/lib/datetime.mjs | 2 +- polyfill/lib/now.mjs | 2 +- polyfill/test/date.mjs | 4 ++-- polyfill/test/datetime.mjs | 4 ++-- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/polyfill/index.d.ts b/polyfill/index.d.ts index 89a37b3ade..2017bbdf62 100644 --- a/polyfill/index.d.ts +++ b/polyfill/index.d.ts @@ -475,7 +475,7 @@ export namespace Temporal { options?: DifferenceOptions<'years' | 'months' | 'weeks' | 'days' | 'hours' | 'minutes' | 'seconds'> ): Temporal.Duration; toAbsolute(tzLike: TimeZoneProtocol | string, options?: ToAbsoluteOptions): Temporal.Absolute; - getDate(): Temporal.Date; + toDate(): Temporal.Date; getYearMonth(): Temporal.YearMonth; getMonthDay(): Temporal.MonthDay; getTime(): Temporal.Time; diff --git a/polyfill/lib/datetime.mjs b/polyfill/lib/datetime.mjs index 816db84a96..c914402de6 100644 --- a/polyfill/lib/datetime.mjs +++ b/polyfill/lib/datetime.mjs @@ -466,7 +466,7 @@ export class DateTime { if (typeof timeZone.getAbsoluteFor === 'function') return timeZone.getAbsoluteFor(this, { disambiguation }); return TemporalTimeZone.prototype.getAbsoluteFor.call(timeZone, this, { disambiguation }); } - getDate() { + toDate() { if (!ES.IsTemporalDateTime(this)) throw new TypeError('invalid receiver'); const Date = GetIntrinsic('%Temporal.Date%'); return new Date(GetSlot(this, ISO_YEAR), GetSlot(this, ISO_MONTH), GetSlot(this, ISO_DAY), GetSlot(this, CALENDAR)); diff --git a/polyfill/lib/now.mjs b/polyfill/lib/now.mjs index 749257ba13..32fea29a11 100644 --- a/polyfill/lib/now.mjs +++ b/polyfill/lib/now.mjs @@ -21,7 +21,7 @@ function dateTime(temporalTimeZoneLike = timeZone(), calendar = undefined) { return TemporalTimeZone.prototype.getDateTimeFor.call(timeZone, abs, calendar); } function date(temporalTimeZoneLike, calendar = undefined) { - return dateTime(temporalTimeZoneLike, calendar).getDate(); + return dateTime(temporalTimeZoneLike, calendar).toDate(); } function time(temporalTimeZoneLike) { return dateTime(temporalTimeZoneLike).getTime(); diff --git a/polyfill/test/date.mjs b/polyfill/test/date.mjs index 857fd0f027..3a3e3a1b26 100644 --- a/polyfill/test/date.mjs +++ b/polyfill/test/date.mjs @@ -505,8 +505,8 @@ describe('Date', () => { it('converting from DateTime', () => { const min = Temporal.DateTime.from('-271821-04-19T00:00:00.000000001'); const max = Temporal.DateTime.from('+275760-09-13T23:59:59.999999999'); - equal(`${min.getDate()}`, '-271821-04-19'); - equal(`${max.getDate()}`, '+275760-09-13'); + equal(`${min.toDate()}`, '-271821-04-19'); + equal(`${max.toDate()}`, '+275760-09-13'); }); it('converting from YearMonth', () => { const min = Temporal.YearMonth.from('-271821-04'); diff --git a/polyfill/test/datetime.mjs b/polyfill/test/datetime.mjs index eac163b284..89163b3d2c 100644 --- a/polyfill/test/datetime.mjs +++ b/polyfill/test/datetime.mjs @@ -81,8 +81,8 @@ describe('DateTime', () => { it('DateTime.prototype.toAbsolute is a Function', () => { equal(typeof DateTime.prototype.toAbsolute, 'function'); }); - it('DateTime.prototype.getDate is a Function', () => { - equal(typeof DateTime.prototype.getDate, 'function'); + it('DateTime.prototype.toDate is a Function', () => { + equal(typeof DateTime.prototype.toDate, 'function'); }); it('DateTime.prototype.getTime is a Function', () => { equal(typeof DateTime.prototype.getTime, 'function'); From b74ec466ee553563eeefe3cbe393ab725751b7ab Mon Sep 17 00:00:00 2001 From: Ujjwal Sharma Date: Wed, 1 Jul 2020 19:02:17 +0530 Subject: [PATCH 17/27] spec: rename getDate to toDate --- spec/datetime.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/datetime.html b/spec/datetime.html index 417b4e840a..ea121efba7 100644 --- a/spec/datetime.html +++ b/spec/datetime.html @@ -533,8 +533,8 @@

Temporal.DateTime.prototype.toAbsolute ( _temporalTimeZoneLike_ [ , _options - -

Temporal.DateTime.prototype.getDate ( )

+ +

Temporal.DateTime.prototype.toDate ( )

The following steps are taken:

From a3d99d3bbb1db0547b9e5c21b20cab8e2240ae8c Mon Sep 17 00:00:00 2001 From: Ujjwal Sharma Date: Wed, 1 Jul 2020 19:36:03 +0530 Subject: [PATCH 18/27] docs: rename getDate to toDate --- docs/cookbook/getBusinessOpenStateText.mjs | 2 +- docs/cookbook/nextWeeklyOccurrence.mjs | 2 +- docs/date.md | 2 +- docs/datetime.md | 6 +++--- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/docs/cookbook/getBusinessOpenStateText.mjs b/docs/cookbook/getBusinessOpenStateText.mjs index 921ce5729a..34749b156d 100644 --- a/docs/cookbook/getBusinessOpenStateText.mjs +++ b/docs/cookbook/getBusinessOpenStateText.mjs @@ -29,7 +29,7 @@ function getBusinessOpenStateText(now, timeZone, businessHours, soonWindow) { // Because of times wrapping around at midnight, we may need to consider // yesterday's and tomorrow's hours as well - const today = dateTime.getDate(); + const today = dateTime.toDate(); const yesterday = today.minus({ days: 1 }); const tomorrow = today.plus({ days: 1 }); diff --git a/docs/cookbook/nextWeeklyOccurrence.mjs b/docs/cookbook/nextWeeklyOccurrence.mjs index 33e4d4f35c..27b4140cde 100644 --- a/docs/cookbook/nextWeeklyOccurrence.mjs +++ b/docs/cookbook/nextWeeklyOccurrence.mjs @@ -11,7 +11,7 @@ */ function nextWeeklyOccurrence(now, localTimeZone, weekday, eventTime, eventTimeZone) { const dateTime = now.toDateTime(eventTimeZone); - const nextDate = dateTime.getDate().plus({ days: (weekday + 7 - dateTime.dayOfWeek) % 7 }); + const nextDate = dateTime.toDate().plus({ days: (weekday + 7 - dateTime.dayOfWeek) % 7 }); let nextOccurrence = nextDate.toDateTime(eventTime); // Handle the case where the event is today but already happened diff --git a/docs/date.md b/docs/date.md index 261f69a6e1..1db9c524ad 100644 --- a/docs/date.md +++ b/docs/date.md @@ -32,7 +32,7 @@ Otherwise, `Temporal.Date.from()`, which accepts more kinds of input, allows inp All values are given as reckoned in the [ISO 8601 calendar](https://en.wikipedia.org/wiki/ISO_8601#Dates). Together, `isoYear`, `isoMonth`, and `isoDay` must represent a valid date in that calendar, even if you are passing a different calendar as the `calendar` parameter. -The range of allowed values for this type is exactly enough that calling [`getDate()`](./datetime.html#getDate) on any valid `Temporal.DateTime` will succeed. +The range of allowed values for this type is exactly enough that calling [`toDate()`](./datetime.html#toDate) on any valid `Temporal.DateTime` will succeed. If `isoYear`, `isoMonth`, and `isoDay` form a date outside of this range, then this function will throw a `RangeError`. > **NOTE**: The `isoMonth` argument ranges from 1 to 12, which is different from legacy `Date` where months are represented by zero-based indices (0 to 11). diff --git a/docs/datetime.md b/docs/datetime.md index f9f2eb1745..3165c63041 100644 --- a/docs/datetime.md +++ b/docs/datetime.md @@ -604,7 +604,7 @@ For usage examples and a more complete explanation of how this disambiguation wo If the result is earlier or later than the range that `Temporal.Absolute` can represent (approximately half a million years centered on the [Unix epoch](https://en.wikipedia.org/wiki/Unix_time)), then a `RangeError` will be thrown, no matter the value of `disambiguation`. -### datetime.**getDate**() : Temporal.Date +### datetime.**toDate**() : Temporal.Date **Returns:** a `Temporal.Date` object that is the same as the date portion of `datetime`. @@ -621,12 +621,12 @@ If the result is earlier or later than the range that `Temporal.Absolute` can re **Returns:** a `Temporal.Time` object that is the same as the wall-clock time portion of `datetime`. The above four methods can be used to convert `Temporal.DateTime` into a `Temporal.Date`, `Temporal.YearMonth`, `Temporal.MonthDay`, or `Temporal.Time` respectively. -The converted object carries a copy of all the relevant fields of `datetime` (for example, in `getDate()`, the `year`, `month`, and `day` properties are copied.) +The converted object carries a copy of all the relevant fields of `datetime` (for example, in `toDate()`, the `year`, `month`, and `day` properties are copied.) Usage example: ```javascript dt = new Temporal.DateTime(1995, 12, 7, 3, 24, 30, 0, 3, 500); -dt.getDate() // => 1995-12-07 +dt.toDate() // => 1995-12-07 dt.getYearMonth() // => 1995-12 dt.getMonthDay() // => 12-07 dt.getTime() // => 03:24:30.000003500 From 2a793c5498569d7073f21a90d630bf4de830c8f6 Mon Sep 17 00:00:00 2001 From: Ujjwal Sharma Date: Wed, 1 Jul 2020 20:08:40 +0530 Subject: [PATCH 19/27] polyfill: rename getTime to toTime --- polyfill/index.d.ts | 2 +- polyfill/lib/datetime.mjs | 2 +- polyfill/lib/now.mjs | 2 +- polyfill/test/datetime.mjs | 4 ++-- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/polyfill/index.d.ts b/polyfill/index.d.ts index 2017bbdf62..fa6cae1774 100644 --- a/polyfill/index.d.ts +++ b/polyfill/index.d.ts @@ -478,7 +478,7 @@ export namespace Temporal { toDate(): Temporal.Date; getYearMonth(): Temporal.YearMonth; getMonthDay(): Temporal.MonthDay; - getTime(): Temporal.Time; + toTime(): Temporal.Time; getFields(): DateTimeFields; getISOCalendarFields(): DateTimeISOCalendarFields; toLocaleString(locales?: string | string[], options?: Intl.DateTimeFormatOptions): string; diff --git a/polyfill/lib/datetime.mjs b/polyfill/lib/datetime.mjs index c914402de6..e530823d2a 100644 --- a/polyfill/lib/datetime.mjs +++ b/polyfill/lib/datetime.mjs @@ -485,7 +485,7 @@ export class DateTime { const fields = ES.ToTemporalDateTimeRecord(this); return calendar.monthDayFromFields(fields, {}, MonthDay); } - getTime() { + toTime() { if (!ES.IsTemporalDateTime(this)) throw new TypeError('invalid receiver'); const Time = GetIntrinsic('%Temporal.Time%'); return new Time( diff --git a/polyfill/lib/now.mjs b/polyfill/lib/now.mjs index 32fea29a11..927a2c329c 100644 --- a/polyfill/lib/now.mjs +++ b/polyfill/lib/now.mjs @@ -24,7 +24,7 @@ function date(temporalTimeZoneLike, calendar = undefined) { return dateTime(temporalTimeZoneLike, calendar).toDate(); } function time(temporalTimeZoneLike) { - return dateTime(temporalTimeZoneLike).getTime(); + return dateTime(temporalTimeZoneLike).toTime(); } function timeZone() { return ES.SystemTimeZone(); diff --git a/polyfill/test/datetime.mjs b/polyfill/test/datetime.mjs index 89163b3d2c..b2083247f7 100644 --- a/polyfill/test/datetime.mjs +++ b/polyfill/test/datetime.mjs @@ -84,8 +84,8 @@ describe('DateTime', () => { it('DateTime.prototype.toDate is a Function', () => { equal(typeof DateTime.prototype.toDate, 'function'); }); - it('DateTime.prototype.getTime is a Function', () => { - equal(typeof DateTime.prototype.getTime, 'function'); + it('DateTime.prototype.toTime is a Function', () => { + equal(typeof DateTime.prototype.toTime, 'function'); }); it('DateTime.prototype.getFields is a Function', () => { equal(typeof DateTime.prototype.getFields, 'function'); From 26329455609933a71906632582d3eaa3db99af4f Mon Sep 17 00:00:00 2001 From: Ujjwal Sharma Date: Wed, 1 Jul 2020 20:28:35 +0530 Subject: [PATCH 20/27] spec: rename getTime to toTime --- spec/datetime.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/datetime.html b/spec/datetime.html index ea121efba7..d3d80d33ce 100644 --- a/spec/datetime.html +++ b/spec/datetime.html @@ -569,8 +569,8 @@

Temporal.DateTime.prototype.getMonthDay ( )

- -

Temporal.DateTime.prototype.getTime ( )

+ +

Temporal.DateTime.prototype.toTime ( )

The following steps are taken:

From 8ad3a41749e80ff48a96c9c66382f5439d981388 Mon Sep 17 00:00:00 2001 From: Ujjwal Sharma Date: Wed, 1 Jul 2020 20:33:09 +0530 Subject: [PATCH 21/27] docs: rename getTime to toTime --- docs/datetime.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/datetime.md b/docs/datetime.md index 3165c63041..ab0bd5acfb 100644 --- a/docs/datetime.md +++ b/docs/datetime.md @@ -616,7 +616,7 @@ If the result is earlier or later than the range that `Temporal.Absolute` can re **Returns:** a `Temporal.MonthDay` object that is the same as the month and day of `datetime`. -### datetime.**getTime**() : Temporal.Time +### datetime.**toTime**() : Temporal.Time **Returns:** a `Temporal.Time` object that is the same as the wall-clock time portion of `datetime`. @@ -629,7 +629,7 @@ dt = new Temporal.DateTime(1995, 12, 7, 3, 24, 30, 0, 3, 500); dt.toDate() // => 1995-12-07 dt.getYearMonth() // => 1995-12 dt.getMonthDay() // => 12-07 -dt.getTime() // => 03:24:30.000003500 +dt.toTime() // => 03:24:30.000003500 ``` ### datetime.**getFields**() : { year: number, month: number, day: number, hour: number, minute: number, second: number, millisecond: number, microsecond: number, nanosecond: number, calendar: object, [propName: string]: unknown } From 2d4cfb5238f2d8969d308d8df1cc22d7a3b5269e Mon Sep 17 00:00:00 2001 From: Ujjwal Sharma Date: Thu, 2 Jul 2020 00:03:53 +0530 Subject: [PATCH 22/27] polyfill: rename getMonthDay to toMonthDay --- polyfill/index.d.ts | 4 ++-- polyfill/lib/date.mjs | 2 +- polyfill/lib/datetime.mjs | 2 +- polyfill/test/date.mjs | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/polyfill/index.d.ts b/polyfill/index.d.ts index fa6cae1774..9f2eb4db9c 100644 --- a/polyfill/index.d.ts +++ b/polyfill/index.d.ts @@ -375,7 +375,7 @@ export namespace Temporal { ): Temporal.Duration; toDateTime(temporalTime: Temporal.Time): Temporal.DateTime; getYearMonth(): Temporal.YearMonth; - getMonthDay(): Temporal.MonthDay; + toMonthDay(): Temporal.MonthDay; getFields(): DateFields; getISOCalendarFields(): DateISOCalendarFields; toLocaleString(locales?: string | string[], options?: Intl.DateTimeFormatOptions): string; @@ -477,7 +477,7 @@ export namespace Temporal { toAbsolute(tzLike: TimeZoneProtocol | string, options?: ToAbsoluteOptions): Temporal.Absolute; toDate(): Temporal.Date; getYearMonth(): Temporal.YearMonth; - getMonthDay(): Temporal.MonthDay; + toMonthDay(): Temporal.MonthDay; toTime(): Temporal.Time; getFields(): DateTimeFields; getISOCalendarFields(): DateTimeISOCalendarFields; diff --git a/polyfill/lib/date.mjs b/polyfill/lib/date.mjs index f9484cb445..e25b1d6f19 100644 --- a/polyfill/lib/date.mjs +++ b/polyfill/lib/date.mjs @@ -221,7 +221,7 @@ export class Date { const fields = ES.ToTemporalDateRecord(this); return calendar.yearMonthFromFields(fields, {}, YearMonth); } - getMonthDay() { + toMonthDay() { if (!ES.IsTemporalDate(this)) throw new TypeError('invalid receiver'); const MonthDay = GetIntrinsic('%Temporal.MonthDay%'); const calendar = GetSlot(this, CALENDAR); diff --git a/polyfill/lib/datetime.mjs b/polyfill/lib/datetime.mjs index e530823d2a..27768f0442 100644 --- a/polyfill/lib/datetime.mjs +++ b/polyfill/lib/datetime.mjs @@ -478,7 +478,7 @@ export class DateTime { const fields = ES.ToTemporalDateTimeRecord(this); return calendar.yearMonthFromFields(fields, {}, YearMonth); } - getMonthDay() { + toMonthDay() { if (!ES.IsTemporalDateTime(this)) throw new TypeError('invalid receiver'); const MonthDay = GetIntrinsic('%Temporal.MonthDay%'); const calendar = GetSlot(this, CALENDAR); diff --git a/polyfill/test/date.mjs b/polyfill/test/date.mjs index 3a3e3a1b26..54efe04062 100644 --- a/polyfill/test/date.mjs +++ b/polyfill/test/date.mjs @@ -66,8 +66,8 @@ describe('Date', () => { it('Date.prototype.getYearMonth is a Function', () => { equal(typeof Date.prototype.getYearMonth, 'function'); }); - it('Date.prototype.getMonthDay is a Function', () => { - equal(typeof Date.prototype.getMonthDay, 'function'); + it('Date.prototype.toMonthDay is a Function', () => { + equal(typeof Date.prototype.toMonthDay, 'function'); }); it('Date.prototype.getFields is a Function', () => { equal(typeof Date.prototype.getFields, 'function'); From 6e2e9d2d2a01efbaeac9701cab013aa6d6bb23fe Mon Sep 17 00:00:00 2001 From: Ujjwal Sharma Date: Thu, 2 Jul 2020 00:04:28 +0530 Subject: [PATCH 23/27] spec: rename getMonthDay to toMonthDay --- spec/date.html | 4 ++-- spec/datetime.html | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/spec/date.html b/spec/date.html index 631434b599..e4b9327bee 100644 --- a/spec/date.html +++ b/spec/date.html @@ -244,8 +244,8 @@

Temporal.Date.prototype.getYearMonth ( )

- -

Temporal.Date.prototype.getMonthDay ( )

+ +

Temporal.Date.prototype.toMonthDay ( )

The following steps are taken:

diff --git a/spec/datetime.html b/spec/datetime.html index d3d80d33ce..87b79226d9 100644 --- a/spec/datetime.html +++ b/spec/datetime.html @@ -557,8 +557,8 @@

Temporal.DateTime.prototype.getYearMonth ( )

- -

Temporal.DateTime.prototype.getMonthDay ( )

+ +

Temporal.DateTime.prototype.toMonthDay ( )

The following steps are taken:

From bd4fe847dfd878610560d84bf3eed3bae5b6eafe Mon Sep 17 00:00:00 2001 From: Ujjwal Sharma Date: Thu, 2 Jul 2020 00:05:02 +0530 Subject: [PATCH 24/27] docs: rename getMonthDay to toMonthDay --- docs/date.md | 4 ++-- docs/datetime.md | 4 ++-- docs/monthday.md | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/docs/date.md b/docs/date.md index 1db9c524ad..d8c4ece711 100644 --- a/docs/date.md +++ b/docs/date.md @@ -530,7 +530,7 @@ date.toDateTime(time) // => 2006-08-24T15:23:30.003 **Returns:** a `Temporal.YearMonth` object that is the same as the year and month of `date`. -### date.**getMonthDay**() : Temporal.MonthDay +### date.**toMonthDay**() : Temporal.MonthDay **Returns:** a `Temporal.MonthDay` object that is the same as the month and day of `date`. @@ -541,7 +541,7 @@ Usage example: ```javascript date = Temporal.Date.from('2006-08-24'); date.getYearMonth() // => 2006-08 -date.getMonthDay() // => 08-24 +date.toMonthDay() // => 08-24 ``` ### date.**getFields**() : { year: number, month: number, day: number, calendar: object, [propName: string]: unknown } diff --git a/docs/datetime.md b/docs/datetime.md index ab0bd5acfb..767f3659ae 100644 --- a/docs/datetime.md +++ b/docs/datetime.md @@ -612,7 +612,7 @@ If the result is earlier or later than the range that `Temporal.Absolute` can re **Returns:** a `Temporal.YearMonth` object that is the same as the year and month of `datetime`. -### datetime.**getMonthDay**() : Temporal.MonthDay +### datetime.**toMonthDay**() : Temporal.MonthDay **Returns:** a `Temporal.MonthDay` object that is the same as the month and day of `datetime`. @@ -628,7 +628,7 @@ Usage example: dt = new Temporal.DateTime(1995, 12, 7, 3, 24, 30, 0, 3, 500); dt.toDate() // => 1995-12-07 dt.getYearMonth() // => 1995-12 -dt.getMonthDay() // => 12-07 +dt.toMonthDay() // => 12-07 dt.toTime() // => 03:24:30.000003500 ``` diff --git a/docs/monthday.md b/docs/monthday.md index 16a2085589..e7bbd4a82a 100644 --- a/docs/monthday.md +++ b/docs/monthday.md @@ -144,7 +144,7 @@ Since `Temporal.MonthDay` objects are immutable, use this method instead of modi > **NOTE**: Unlike in `Temporal.Date.prototype.with()`, a `calendar` property is not allowed on `monthDayLike`. > It is not possible to convert a `Temporal.MonthDay` to another calendar system without knowing the year. -> If you need to do this, use `monthDay.toDate(year).withCalendar(calendar).getMonthDay()`. +> If you need to do this, use `monthDay.toDate(year).withCalendar(calendar).toMonthDay()`. Usage example: ```javascript From a9ed7852643252d97cc7158b7de443c75b493f04 Mon Sep 17 00:00:00 2001 From: Ujjwal Sharma Date: Thu, 2 Jul 2020 00:10:36 +0530 Subject: [PATCH 25/27] polyfill: rename getYearMonth to toYearMonth --- polyfill/index.d.ts | 4 ++-- polyfill/lib/date.mjs | 2 +- polyfill/lib/datetime.mjs | 2 +- polyfill/test/date.mjs | 4 ++-- polyfill/test/yearmonth.mjs | 4 ++-- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/polyfill/index.d.ts b/polyfill/index.d.ts index 9f2eb4db9c..a2402e85c1 100644 --- a/polyfill/index.d.ts +++ b/polyfill/index.d.ts @@ -374,7 +374,7 @@ export namespace Temporal { options?: DifferenceOptions<'years' | 'months' | 'weeks' | 'days'> ): Temporal.Duration; toDateTime(temporalTime: Temporal.Time): Temporal.DateTime; - getYearMonth(): Temporal.YearMonth; + toYearMonth(): Temporal.YearMonth; toMonthDay(): Temporal.MonthDay; getFields(): DateFields; getISOCalendarFields(): DateISOCalendarFields; @@ -476,7 +476,7 @@ export namespace Temporal { ): Temporal.Duration; toAbsolute(tzLike: TimeZoneProtocol | string, options?: ToAbsoluteOptions): Temporal.Absolute; toDate(): Temporal.Date; - getYearMonth(): Temporal.YearMonth; + toYearMonth(): Temporal.YearMonth; toMonthDay(): Temporal.MonthDay; toTime(): Temporal.Time; getFields(): DateTimeFields; diff --git a/polyfill/lib/date.mjs b/polyfill/lib/date.mjs index e25b1d6f19..4cefc5e83a 100644 --- a/polyfill/lib/date.mjs +++ b/polyfill/lib/date.mjs @@ -214,7 +214,7 @@ export class Date { const DateTime = GetIntrinsic('%Temporal.DateTime%'); return new DateTime(year, month, day, hour, minute, second, millisecond, microsecond, nanosecond, calendar); } - getYearMonth() { + toYearMonth() { if (!ES.IsTemporalDate(this)) throw new TypeError('invalid receiver'); const YearMonth = GetIntrinsic('%Temporal.YearMonth%'); const calendar = GetSlot(this, CALENDAR); diff --git a/polyfill/lib/datetime.mjs b/polyfill/lib/datetime.mjs index 27768f0442..3bc6db6983 100644 --- a/polyfill/lib/datetime.mjs +++ b/polyfill/lib/datetime.mjs @@ -471,7 +471,7 @@ export class DateTime { const Date = GetIntrinsic('%Temporal.Date%'); return new Date(GetSlot(this, ISO_YEAR), GetSlot(this, ISO_MONTH), GetSlot(this, ISO_DAY), GetSlot(this, CALENDAR)); } - getYearMonth() { + toYearMonth() { if (!ES.IsTemporalDateTime(this)) throw new TypeError('invalid receiver'); const YearMonth = GetIntrinsic('%Temporal.YearMonth%'); const calendar = GetSlot(this, CALENDAR); diff --git a/polyfill/test/date.mjs b/polyfill/test/date.mjs index 54efe04062..ae996bbc04 100644 --- a/polyfill/test/date.mjs +++ b/polyfill/test/date.mjs @@ -63,8 +63,8 @@ describe('Date', () => { it('Date.prototype.toDateTime is a Function', () => { equal(typeof Date.prototype.toDateTime, 'function'); }); - it('Date.prototype.getYearMonth is a Function', () => { - equal(typeof Date.prototype.getYearMonth, 'function'); + it('Date.prototype.toYearMonth is a Function', () => { + equal(typeof Date.prototype.toYearMonth, 'function'); }); it('Date.prototype.toMonthDay is a Function', () => { equal(typeof Date.prototype.toMonthDay, 'function'); diff --git a/polyfill/test/yearmonth.mjs b/polyfill/test/yearmonth.mjs index a91895847f..37661858bf 100644 --- a/polyfill/test/yearmonth.mjs +++ b/polyfill/test/yearmonth.mjs @@ -334,8 +334,8 @@ describe('YearMonth', () => { it('converting from Date', () => { const min = Temporal.Date.from('-271821-04-19'); const max = Temporal.Date.from('+275760-09-13'); - equal(`${min.getYearMonth()}`, '-271821-04'); - equal(`${max.getYearMonth()}`, '+275760-09'); + equal(`${min.toYearMonth()}`, '-271821-04'); + equal(`${max.toYearMonth()}`, '+275760-09'); }); it('adding and subtracting beyond limit', () => { const min = YearMonth.from('-271821-04'); From c23115138b722fe643ea73b6d1df8e1c49f9e179 Mon Sep 17 00:00:00 2001 From: Ujjwal Sharma Date: Thu, 2 Jul 2020 00:10:56 +0530 Subject: [PATCH 26/27] spec: rename getYearMonth to toYearMonth --- spec/date.html | 4 ++-- spec/datetime.html | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/spec/date.html b/spec/date.html index e4b9327bee..4e08a68e41 100644 --- a/spec/date.html +++ b/spec/date.html @@ -232,8 +232,8 @@

get Temporal.Date.prototype.isLeapYear

- -

Temporal.Date.prototype.getYearMonth ( )

+ +

Temporal.Date.prototype.toYearMonth ( )

The following steps are taken:

diff --git a/spec/datetime.html b/spec/datetime.html index 87b79226d9..360909fd9a 100644 --- a/spec/datetime.html +++ b/spec/datetime.html @@ -545,8 +545,8 @@

Temporal.DateTime.prototype.toDate ( )

- -

Temporal.DateTime.prototype.getYearMonth ( )

+ +

Temporal.DateTime.prototype.toYearMonth ( )

The following steps are taken:

From e0a9d35c2f56e2d7fa294afa500c25d074fceac3 Mon Sep 17 00:00:00 2001 From: Ujjwal Sharma Date: Thu, 2 Jul 2020 00:11:29 +0530 Subject: [PATCH 27/27] docs: rename getYearMonth to toYearMonth --- docs/date.md | 6 +++--- docs/datetime.md | 4 ++-- docs/yearmonth.md | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/docs/date.md b/docs/date.md index d8c4ece711..ea92bc4a14 100644 --- a/docs/date.md +++ b/docs/date.md @@ -526,7 +526,7 @@ time = Temporal.Time.from('15:23:30.003'); date.toDateTime(time) // => 2006-08-24T15:23:30.003 ``` -### date.**getYearMonth**() : Temporal.YearMonth +### date.**toYearMonth**() : Temporal.YearMonth **Returns:** a `Temporal.YearMonth` object that is the same as the year and month of `date`. @@ -535,12 +535,12 @@ date.toDateTime(time) // => 2006-08-24T15:23:30.003 **Returns:** a `Temporal.MonthDay` object that is the same as the month and day of `date`. The above two methods can be used to convert `Temporal.Date` into a `Temporal.YearMonth` or `Temporal.MonthDay` respectively. -The converted object carries a copy of all the relevant fields of `date` (for example, in `getYearMonth()`, the `year` and `month` properties are copied.) +The converted object carries a copy of all the relevant fields of `date` (for example, in `toYearMonth()`, the `year` and `month` properties are copied.) Usage example: ```javascript date = Temporal.Date.from('2006-08-24'); -date.getYearMonth() // => 2006-08 +date.toYearMonth() // => 2006-08 date.toMonthDay() // => 08-24 ``` diff --git a/docs/datetime.md b/docs/datetime.md index 767f3659ae..d65202e2a5 100644 --- a/docs/datetime.md +++ b/docs/datetime.md @@ -608,7 +608,7 @@ If the result is earlier or later than the range that `Temporal.Absolute` can re **Returns:** a `Temporal.Date` object that is the same as the date portion of `datetime`. -### datetime.**getYearMonth**() : Temporal.YearMonth +### datetime.**toYearMonth**() : Temporal.YearMonth **Returns:** a `Temporal.YearMonth` object that is the same as the year and month of `datetime`. @@ -627,7 +627,7 @@ Usage example: ```javascript dt = new Temporal.DateTime(1995, 12, 7, 3, 24, 30, 0, 3, 500); dt.toDate() // => 1995-12-07 -dt.getYearMonth() // => 1995-12 +dt.toYearMonth() // => 1995-12 dt.toMonthDay() // => 12-07 dt.toTime() // => 03:24:30.000003500 ``` diff --git a/docs/yearmonth.md b/docs/yearmonth.md index 5df95e6c67..5e1eefdc22 100644 --- a/docs/yearmonth.md +++ b/docs/yearmonth.md @@ -30,7 +30,7 @@ Otherwise, `Temporal.YearMonth.from()`, which accepts more kinds of input, allow All values are given as reckoned in the [ISO 8601 calendar](https://en.wikipedia.org/wiki/ISO_8601#Dates). Together, `isoYear`, `isoMonth`, and `refISODay` must represent a valid date in that calendar, even if you are passing a different calendar as the `calendar` parameter. -The range of allowed values for this type is exactly enough that calling [`getYearMonth()`](./date.html#getYearMonth) on any valid `Temporal.Date` will succeed. +The range of allowed values for this type is exactly enough that calling [`toYearMonth()`](./date.html#toYearMonth) on any valid `Temporal.Date` will succeed. If `isoYear` and `isoMonth` are outside of this range, then this function will throw a `RangeError`. > **NOTE**: The `isoMonth` argument ranges from 1 to 12, which is different from legacy `Date` where months are represented by zero-based indices (0 to 11). @@ -220,7 +220,7 @@ If the result is earlier or later than the range of dates that `Temporal.YearMon > **NOTE**: Unlike in `Temporal.Date.prototype.with()`, a `calendar` property is not allowed on `yearMonthLike`. > It is not possible to convert a `Temporal.YearMonth` to another calendar system without knowing the day of the month. -> If you need to do this, use `yearMonth.toDate(day).withCalendar(calendar).getYearMonth()`. +> If you need to do this, use `yearMonth.toDate(day).withCalendar(calendar).toYearMonth()`. Usage example: ```javascript