From 8f767b37104fd1e1bffa256da45295b787d06e6a Mon Sep 17 00:00:00 2001 From: Justin Grant Date: Wed, 8 Jul 2020 09:42:03 -0700 Subject: [PATCH] Update with new toXxx method names - Convert all conversion methods to use new toXxx naming convention - Fix Test262 tests broken by build changes in #715 --- package-lock.json | 52 ++++++++++---------- polyfill/index.d.ts | 6 +-- polyfill/lib/localdatetime.mjs | 59 +++++++++++------------ polyfill/lib/poc/LocalDateTime.test.ts | 67 ++++++++++++-------------- polyfill/lib/poc/LocalDateTime.ts | 61 ++++++++++++----------- polyfill/lib/poc/postProcess.js | 7 ++- polyfill/poc.d.ts | 26 +++++----- polyfill/test/localdatetime.mjs | 67 ++++++++++++-------------- 8 files changed, 172 insertions(+), 173 deletions(-) diff --git a/package-lock.json b/package-lock.json index a9cb9930c5..da666c2026 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2283,6 +2283,12 @@ "is-glob": "^4.0.1" } }, + "is-number": { + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/is-number/-/is-number-7.0.0.tgz", + "integrity": "sha512-41Cifkg6e8TylSpdtTpeLVMqvSBEVzTttHvERD741+pnZ8ANv0004MRL43QKPDlK9cGvNp6NZWZUBlbGXYxxng==", + "dev": true + }, "micromatch": { "version": "4.0.2", "resolved": "https://registry.npmjs.org/micromatch/-/micromatch-4.0.2.tgz", @@ -2652,28 +2658,6 @@ "kind-of": "^4.0.0" }, "dependencies": { - "is-number": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/is-number/-/is-number-3.0.0.tgz", - "integrity": "sha1-JP1iAaR4LPUFYcgQJ2r8fRLXEZU=", - "dev": true, - "optional": true, - "requires": { - "kind-of": "^3.0.2" - }, - "dependencies": { - "kind-of": { - "version": "3.2.2", - "resolved": "https://registry.npmjs.org/kind-of/-/kind-of-3.2.2.tgz", - "integrity": "sha1-MeohpzS6ubuw8yRm2JOupR5KPGQ=", - "dev": true, - "optional": true, - "requires": { - "is-buffer": "^1.1.5" - } - } - } - }, "kind-of": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/kind-of/-/kind-of-4.0.0.tgz", @@ -2964,10 +2948,26 @@ } }, "is-number": { - "version": "7.0.0", - "resolved": "https://registry.npmjs.org/is-number/-/is-number-7.0.0.tgz", - "integrity": "sha512-41Cifkg6e8TylSpdtTpeLVMqvSBEVzTttHvERD741+pnZ8ANv0004MRL43QKPDlK9cGvNp6NZWZUBlbGXYxxng==", - "dev": true + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/is-number/-/is-number-3.0.0.tgz", + "integrity": "sha1-JP1iAaR4LPUFYcgQJ2r8fRLXEZU=", + "dev": true, + "optional": true, + "requires": { + "kind-of": "^3.0.2" + }, + "dependencies": { + "kind-of": { + "version": "3.2.2", + "resolved": "https://registry.npmjs.org/kind-of/-/kind-of-3.2.2.tgz", + "integrity": "sha1-MeohpzS6ubuw8yRm2JOupR5KPGQ=", + "dev": true, + "optional": true, + "requires": { + "is-buffer": "^1.1.5" + } + } + } }, "is-plain-object": { "version": "2.0.4", diff --git a/polyfill/index.d.ts b/polyfill/index.d.ts index 68c62874cb..9ee27868e5 100644 --- a/polyfill/index.d.ts +++ b/polyfill/index.d.ts @@ -536,14 +536,14 @@ export namespace Temporal { | /** @deprecated */ 'day' > ): Temporal.Duration; - toDateTime(temporalTime: Temporal.Time): Temporal.DateTime; - toYearMonth(): Temporal.YearMonth; - toMonthDay(): Temporal.MonthDay; toLocalDateTime( tzLike: TimeZoneProtocol | string, temporalTime: Temporal.Time, options?: ToAbsoluteOptions ): Temporal.LocalDateTime; + toDateTime(temporalTime: Temporal.Time): Temporal.DateTime; + toYearMonth(): Temporal.YearMonth; + toMonthDay(): Temporal.MonthDay; getFields(): DateFields; getISOFields(): DateISOFields; toLocaleString(locales?: string | string[], options?: Intl.DateTimeFormatOptions): string; diff --git a/polyfill/lib/localdatetime.mjs b/polyfill/lib/localdatetime.mjs index 258636519e..5a26fd8bef 100644 --- a/polyfill/lib/localdatetime.mjs +++ b/polyfill/lib/localdatetime.mjs @@ -1,5 +1,7 @@ -import ES2019 from 'es-abstract/es2019.js'; import { GetIntrinsic, MakeIntrinsicClass } from './intrinsicclass.mjs'; +import ToInteger from 'es-abstract/2019/ToInteger.js'; +import ToObject from 'es-abstract/2019/ToObject.js'; +import ToString from 'es-abstract/2019/ToString.js'; const Temporal = { get DateTime() { @@ -35,7 +37,7 @@ function fromObject(item, options) { // Simplest case: absolute + time zone + optional calendar if (absolute !== undefined) { const abs = Temporal.Absolute.from(absolute); - const dt = abs.inTimeZone(tz, cal); + const dt = abs.toDateTime(tz, cal); if (timeZoneOffsetNanoseconds !== undefined) { checkCompareProperty('timeZoneOffsetNanoseconds', timeZoneOffsetNanoseconds, tz.getOffsetNanosecondsFor(abs), tz); } @@ -53,15 +55,15 @@ function fromObject(item, options) { // Simple case: no time zone offset, so use user-supplied disambiguation options // TODO: edit below depending on https://github.com/tc39/proposal-temporal/issues/607 const dt = Temporal.DateTime.from(item, { disambiguation: overflow }); - const abs = dt.inTimeZone(tz, { disambiguation }); + const abs = dt.toAbsolute(tz, { disambiguation }); return new LocalDateTime(abs, tz, dt.calendar); } else { // There is a time zone offset, so we'll have to pick the correct `Absolute` // matching that offset. // TODO: edit below depending on https://github.com/tc39/proposal-temporal/issues/607 const dt = Temporal.DateTime.from(item, { disambiguation: overflow }); - const earlier = dt.inTimeZone(tz, { disambiguation: 'earlier' }); - const later = dt.inTimeZone(tz, { disambiguation: 'later' }); + const earlier = dt.toAbsolute(tz, { disambiguation: 'earlier' }); + const later = dt.toAbsolute(tz, { disambiguation: 'later' }); if (Temporal.Absolute.compare(earlier, later) === 0) { // no ambiguity return new LocalDateTime(earlier, tz, dt.calendar); @@ -71,7 +73,7 @@ function fromObject(item, options) { if (disambiguation === 'reject') { // delegate the exception throwing to Temporal.DateTime - dt.inTimeZone(tz, { disambiguation }); + dt.toAbsolute(tz, { disambiguation }); throw new Error('This code should be unreachable'); } @@ -132,7 +134,7 @@ function fromIsoString(isoString, options) { if (!offset) { // Simple case: ISO string without a TZ offset, so just convert the DateTime // to Absolute in the given time zone. - const absolute = dt.inTimeZone(timeZone, { disambiguation }); + const absolute = dt.toAbsolute(timeZone, { disambiguation }); return new LocalDateTime(absolute, timeZone, dt.calendar); } @@ -141,8 +143,8 @@ function fromIsoString(isoString, options) { // for the hour skipped by Spring DST transitions, and that API won't return // any values for those times. let possibleAbsolutes = [ - dt.inTimeZone(timeZone, { disambiguation: 'earlier' }), - dt.inTimeZone(timeZone, { disambiguation: 'later' }) + dt.toAbsolute(timeZone, { disambiguation: 'earlier' }), + dt.toAbsolute(timeZone, { disambiguation: 'later' }) ]; if (possibleAbsolutes[0].equals(possibleAbsolutes[1])) possibleAbsolutes = [possibleAbsolutes[0]]; @@ -177,7 +179,7 @@ function fromIsoString(isoString, options) { absolute = possibleAbsolutes[1]; break; case 'compatible': - absolute = timeZone.getPossibleAbsolutesFor(dt)[0] || dt.inTimeZone(timeZone, { disambiguation: 'later' }); + absolute = timeZone.getPossibleAbsolutesFor(dt)[0] || dt.toAbsolute(timeZone, { disambiguation: 'later' }); break; case 'reject': default: @@ -205,7 +207,7 @@ function doPlusOrMinus(op, durationLike, options, localDateTime) { // Absolute doesn't use disambiguation, while RFC 5455 specifies 'compatible' behavior // for disambiguation. Therefore, only 'dateTime' durations can use this option. if (disambiguation !== 'compatible' && durationKind !== 'dateTime') { - throw new RangeError('Arithmetic disambiguation is only allowed for `dateTime` durations'); + throw new RangeError('Disambiguation options are only valid for `dateTime` durations'); } switch (durationKind) { @@ -220,7 +222,7 @@ function doPlusOrMinus(op, durationLike, options, localDateTime) { // avoid disambiguation that might change the absolute. if (newDateTime.equals(dateTime)) return LocalDateTime.from(localDateTime); // Otherwise, return the result. - const abs = newDateTime.inTimeZone(timeZone, { disambiguation }); + const abs = newDateTime.toAbsolute(timeZone, { disambiguation }); return new LocalDateTime(abs, timeZone, calendar); } case 'hybrid': { @@ -245,14 +247,14 @@ function doPlusOrMinus(op, durationLike, options, localDateTime) { if (weeks) newDateTime = newDateTime[op]({ weeks }, dateTimeOverflowOption); if (days) newDateTime = newDateTime[op]({ days }, dateTimeOverflowOption); if (isZeroDuration(timeDuration)) { - const absolute = newDateTime.inTimeZone(timeZone); + const absolute = newDateTime.toAbsolute(timeZone); return LocalDateTime.from({ absolute, timeZone, calendar: localDateTime.calendar }); } else { // Now add/subtract the time. Because all time units are always the same // length, we can add/subtract all of them together without worrying about // order of operations. newDateTime = newDateTime[op](timeDuration, dateTimeOverflowOption); - let absolute = newDateTime.inTimeZone(timeZone); + let absolute = newDateTime.toAbsolute(timeZone); const reverseOp = op === 'plus' ? 'minus' : 'plus'; const backUpAbs = absolute[reverseOp]({ nanoseconds: totalNanoseconds(timeDuration) }); const backUpOffset = timeZone.getOffsetNanosecondsFor(backUpAbs); @@ -305,7 +307,7 @@ export class LocalDateTime { constructor(absolute, timeZone, calendar) { this._tz = Temporal.TimeZone.from(timeZone); this._abs = Temporal.Absolute.from(absolute); - this._dt = this._abs.inTimeZone(this._tz, calendar); + this._dt = this._abs.toDateTime(this._tz, calendar); } /** @@ -468,9 +470,6 @@ export class LocalDateTime { return this.with({ calendar }); } - // `inTimeZone` is replaced by the `absolute` field. - // inTimeZone(tzLike: Temporal.TimeZone | string, options?: Temporal.ToAbsoluteOptions): Temporal.Absolute; - /** * Returns the absolute timestamp of this `Temporal.LocalDateTime` instance as * a `Temporal.Absolute`. @@ -543,11 +542,11 @@ export class LocalDateTime { * midnight and the next day's midnight. */ get hoursInDay() { - const today = this.toDate().withTime(new Temporal.Time()); + const today = this.toDate().toDateTime(new Temporal.Time()); const tomorrow = today.plus({ days: 1 }); // TODO: add tests for Azores timezone on midnight of a DST transition - const todayAbs = today.inTimeZone(this._tz); - const tomorrowAbs = tomorrow.inTimeZone(this._tz); + const todayAbs = today.toAbsolute(this._tz); + const tomorrowAbs = tomorrow.toAbsolute(this._tz); const diff = tomorrowAbs.difference(todayAbs, { largestUnit: 'hours' }); const hours = diff.hours + @@ -828,7 +827,7 @@ export class LocalDateTime { // case where both `this` and `other` are both within 25 hours of an // offset transition, but in practice this will be exceedingly rare. let intermediateDt = this._dt.minus(dateDuration); - let intermediateAbs = intermediateDt.inTimeZone(this._tz, { disambiguation }); + let intermediateAbs = intermediateDt.toAbsolute(this._tz, { disambiguation }); let adjustedTimeDuration; if (this._tz.getOffsetNanosecondsFor(intermediateAbs) === other.timeZoneOffsetNanoseconds) { // The transition was in the date portion which is what we want. @@ -838,7 +837,7 @@ export class LocalDateTime { // time portion is on the other side next to `this`, where there's // unlikely to be another transition. intermediateDt = other._dt.plus(dateDuration); - intermediateAbs = intermediateDt.inTimeZone(this._tz, { disambiguation }); + intermediateAbs = intermediateDt.toAbsolute(this._tz, { disambiguation }); adjustedTimeDuration = this._abs.difference(intermediateAbs, { largestUnit: 'hours' }); } @@ -942,16 +941,16 @@ export class LocalDateTime { return this._dt.isLeapYear; } toDate() { - return this._dt.getDate(); + return this._dt.toDate(); } toYearMonth() { - return this._dt.getYearMonth(); + return this._dt.toYearMonth(); } toMonthDay() { - return this._dt.getMonthDay(); + return this._dt.toMonthDay(); } toTime() { - return this._dt.getTime(); + return this._dt.toTime(); } valueOf() { throw new TypeError('use compare() or equals() to compare Temporal.LocalDateTime'); @@ -1113,9 +1112,9 @@ function toLargestTemporalUnit(options, fallback, disallowedStrings = []) { } const ES = { - ToInteger: ES2019.ToInteger, - ToString: ES2019.ToString, - ToObject: ES2019.ToObject, + ToInteger: ToInteger, + ToString: ToString, + ToObject: ToObject, // replace this with public parsing API after it lands ParseFullISOString: (isoString) => { diff --git a/polyfill/lib/poc/LocalDateTime.test.ts b/polyfill/lib/poc/LocalDateTime.test.ts index 61869f8f87..c5ee116d1e 100644 --- a/polyfill/lib/poc/LocalDateTime.test.ts +++ b/polyfill/lib/poc/LocalDateTime.test.ts @@ -481,8 +481,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); @@ -494,26 +494,26 @@ 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 optional parameter', () => { - const dt = abs.inTimeZone(); - equal(abs.getEpochNanoseconds(), dt.inTimeZone().getEpochNanoseconds()); + const dt = abs.toDateTime(); + equal(abs.getEpochNanoseconds(), dt.toAbsolute().getEpochNanoseconds()); equal(`${dt}`, '1976-11-18T14:23:30.123456789'); }); */ it('optional 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('optional 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'); }); }); @@ -555,7 +555,7 @@ describe('LocalDateTime', () => { }); it('Samoa date line change: 10:00PM 29 Dec 2011 -> 11:00PM 31 Dec 2011', () => { - const dayBeforeSamoaDateLineChangeAbs = new Temporal.DateTime(2011, 12, 29, 22).inTimeZone('Pacific/Apia'); + const dayBeforeSamoaDateLineChangeAbs = new Temporal.DateTime(2011, 12, 29, 22).toAbsolute('Pacific/Apia'); const start = LocalDateTime.from({ absolute: dayBeforeSamoaDateLineChangeAbs, timeZone: 'Pacific/Apia' }); const added = start.plus({ days: 1, hours: 1 }); equal(added.day, 31); @@ -782,9 +782,6 @@ describe('LocalDateTime', () => { it('LocalDateTime.prototype.equals is a Function', () => { equal(typeof LocalDateTime.prototype.equals, 'function'); }); - // it('LocalDateTime.prototype.inTimeZone is a Function', () => { - // equal(typeof LocalDateTime.prototype.inTimeZone, 'function'); - // }); it('LocalDateTime.prototype.getDate is a Function', () => { equal(typeof LocalDateTime.prototype.toDate, 'function'); }); @@ -1140,33 +1137,33 @@ describe('LocalDateTime', () => { 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', () => { const dt = DateTime.from('2019-02-16T23:45'); - 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', { 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('throws on bad disambiguation', () => { ['', 'EARLIER', 'xyz', 3, null].forEach((disambiguation) => // @ts-ignore - throws(() => DateTime.from('2019-10-29T10:46').inTimeZone('UTC', { disambiguation }), RangeError) + throws(() => DateTime.from('2019-10-29T10:46').toAbsolute('UTC', { disambiguation }), RangeError) ); }); }); @@ -1216,8 +1213,8 @@ describe('LocalDateTime', () => { 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'); @@ -1225,12 +1222,12 @@ describe('LocalDateTime', () => { 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(() => midnight.withDate(min), RangeError); - equal(`${min.withTime(firstNs)}`, '-271821-04-19T00:00:00.000000001'); - equal(`${firstNs.withDate(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'); + throws(() => min.toDateTime(midnight), RangeError); + throws(() => midnight.toDateTime(min), RangeError); + equal(`${min.toDateTime(firstNs)}`, '-271821-04-19T00:00:00.000000001'); + equal(`${firstNs.toDateTime(min)}`, '-271821-04-19T00:00:00.000000001'); + 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', () => { const min = DateTime.from('-271821-04-19T00:00:00.000000001'); @@ -1241,22 +1238,22 @@ describe('LocalDateTime', () => { }); }); }); - describe('DateTime.inTimeZone() works', () => { + describe('DateTime.toAbsolute() works', () => { const dt = DateTime.from('1976-11-18T15:23:30.123456789'); /* it('without optional parameter', () => { - const abs = dt.inTimeZone(); + const abs = dt.toAbsolute(); equal(`${abs}`, '1976-11-18T15:23:30.123456789Z'); }); */ it('optional 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('optional 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/lib/poc/LocalDateTime.ts b/polyfill/lib/poc/LocalDateTime.ts index fefe301b28..e929b65cc8 100644 --- a/polyfill/lib/poc/LocalDateTime.ts +++ b/polyfill/lib/poc/LocalDateTime.ts @@ -1,5 +1,11 @@ import { Temporal } from '../..'; -import * as ES2019 from 'es-abstract'; +// @ts-ignore +import ToInteger from 'es-abstract/2019/ToInteger.js'; +// @ts-ignore +import ToObject from 'es-abstract/2019/ToObject.js'; +// @ts-ignore +import ToString from 'es-abstract/2019/ToString.js'; +// import { ToInteger, ToObject, ToString } from 'es-abstract'; export type LocalDateTimeLike = Temporal.DateTimeLike & { /**`Temporal.TimeZone`, IANA time zone identifier, or offset string */ @@ -155,7 +161,7 @@ function fromObject(item: Record, options?: LocalDateTimeAssign // Simplest case: absolute + time zone + optional calendar if (absolute !== undefined) { const abs = Temporal.Absolute.from(absolute); - const dt = abs.inTimeZone(tz, cal); + const dt = abs.toDateTime(tz, cal); if (timeZoneOffsetNanoseconds !== undefined) { checkCompareProperty('timeZoneOffsetNanoseconds', timeZoneOffsetNanoseconds, tz.getOffsetNanosecondsFor(abs), tz); } @@ -173,15 +179,15 @@ function fromObject(item: Record, options?: LocalDateTimeAssign // Simple case: no time zone offset, so use user-supplied disambiguation options // TODO: edit below depending on https://github.com/tc39/proposal-temporal/issues/607 const dt = Temporal.DateTime.from(item, { disambiguation: overflow }); - const abs = dt.inTimeZone(tz, { disambiguation }); + const abs = dt.toAbsolute(tz, { disambiguation }); return new LocalDateTime(abs, tz, dt.calendar); } else { // There is a time zone offset, so we'll have to pick the correct `Absolute` // matching that offset. // TODO: edit below depending on https://github.com/tc39/proposal-temporal/issues/607 const dt = Temporal.DateTime.from(item, { disambiguation: overflow }); - const earlier = dt.inTimeZone(tz, { disambiguation: 'earlier' }); - const later = dt.inTimeZone(tz, { disambiguation: 'later' }); + const earlier = dt.toAbsolute(tz, { disambiguation: 'earlier' }); + const later = dt.toAbsolute(tz, { disambiguation: 'later' }); if (Temporal.Absolute.compare(earlier, later) === 0) { // no ambiguity return new LocalDateTime(earlier, tz, dt.calendar); @@ -191,7 +197,7 @@ function fromObject(item: Record, options?: LocalDateTimeAssign if (disambiguation === 'reject') { // delegate the exception throwing to Temporal.DateTime - dt.inTimeZone(tz, { disambiguation }); + dt.toAbsolute(tz, { disambiguation }); throw new Error('This code should be unreachable'); } @@ -252,7 +258,7 @@ function fromIsoString(isoString: string, options?: LocalDateTimeAssignmentOptio if (!offset) { // Simple case: ISO string without a TZ offset, so just convert the DateTime // to Absolute in the given time zone. - const absolute = dt.inTimeZone(timeZone, { disambiguation }); + const absolute = dt.toAbsolute(timeZone, { disambiguation }); return new LocalDateTime(absolute, timeZone, dt.calendar); } @@ -261,8 +267,8 @@ function fromIsoString(isoString: string, options?: LocalDateTimeAssignmentOptio // for the hour skipped by Spring DST transitions, and that API won't return // any values for those times. let possibleAbsolutes = [ - dt.inTimeZone(timeZone, { disambiguation: 'earlier' }), - dt.inTimeZone(timeZone, { disambiguation: 'later' }) + dt.toAbsolute(timeZone, { disambiguation: 'earlier' }), + dt.toAbsolute(timeZone, { disambiguation: 'later' }) ]; if (possibleAbsolutes[0].equals(possibleAbsolutes[1])) possibleAbsolutes = [possibleAbsolutes[0]]; @@ -296,7 +302,7 @@ function fromIsoString(isoString: string, options?: LocalDateTimeAssignmentOptio absolute = possibleAbsolutes[1]; break; case 'compatible': - absolute = timeZone.getPossibleAbsolutesFor(dt)[0] || dt.inTimeZone(timeZone, { disambiguation: 'later' }); + absolute = timeZone.getPossibleAbsolutesFor(dt)[0] || dt.toAbsolute(timeZone, { disambiguation: 'later' }); break; case 'reject': default: @@ -343,7 +349,7 @@ function doPlusOrMinus( // avoid disambiguation that might change the absolute. if (newDateTime.equals(dateTime)) return LocalDateTime.from(localDateTime); // Otherwise, return the result. - const abs = newDateTime.inTimeZone(timeZone, { disambiguation }); + const abs = newDateTime.toAbsolute(timeZone, { disambiguation }); return new LocalDateTime(abs, timeZone, calendar); } case 'hybrid': { @@ -368,14 +374,14 @@ function doPlusOrMinus( if (weeks) newDateTime = newDateTime[op]({ weeks }, dateTimeOverflowOption); if (days) newDateTime = newDateTime[op]({ days }, dateTimeOverflowOption); if (isZeroDuration(timeDuration)) { - const absolute = newDateTime.inTimeZone(timeZone); + const absolute = newDateTime.toAbsolute(timeZone); return LocalDateTime.from({ absolute, timeZone, calendar: localDateTime.calendar }); } else { // Now add/subtract the time. Because all time units are always the same // length, we can add/subtract all of them together without worrying about // order of operations. newDateTime = newDateTime[op](timeDuration, dateTimeOverflowOption); - let absolute = newDateTime.inTimeZone(timeZone); + let absolute = newDateTime.toAbsolute(timeZone); const reverseOp = op === 'plus' ? 'minus' : 'plus'; const backUpAbs = absolute[reverseOp]({ nanoseconds: totalNanoseconds(timeDuration) }); const backUpOffset = timeZone.getOffsetNanosecondsFor(backUpAbs); @@ -432,7 +438,7 @@ export class LocalDateTime { constructor(absolute: Temporal.Absolute, timeZone: Temporal.TimeZone, calendar?: Temporal.CalendarProtocol) { this._tz = Temporal.TimeZone.from(timeZone); this._abs = Temporal.Absolute.from(absolute); - this._dt = this._abs.inTimeZone(this._tz, calendar); + this._dt = this._abs.toDateTime(this._tz, calendar); } /** @@ -598,9 +604,6 @@ export class LocalDateTime { return this.with({ calendar }); } - // `inTimeZone` is replaced by the `absolute` field. - // inTimeZone(tzLike: Temporal.TimeZone | string, options?: Temporal.ToAbsoluteOptions): Temporal.Absolute; - /** * Returns the absolute timestamp of this `Temporal.LocalDateTime` instance as * a `Temporal.Absolute`. @@ -673,11 +676,11 @@ export class LocalDateTime { * midnight and the next day's midnight. */ get hoursInDay(): number { - const today = this.toDate().withTime(new Temporal.Time()); + const today = this.toDate().toDateTime(new Temporal.Time()); const tomorrow = today.plus({ days: 1 }); // TODO: add tests for Azores timezone on midnight of a DST transition - const todayAbs = today.inTimeZone(this._tz); - const tomorrowAbs = tomorrow.inTimeZone(this._tz); + const todayAbs = today.toAbsolute(this._tz); + const tomorrowAbs = tomorrow.toAbsolute(this._tz); const diff = tomorrowAbs.difference(todayAbs, { largestUnit: 'hours' }); const hours = diff.hours + @@ -962,7 +965,7 @@ export class LocalDateTime { // case where both `this` and `other` are both within 25 hours of an // offset transition, but in practice this will be exceedingly rare. let intermediateDt = this._dt.minus(dateDuration); - let intermediateAbs = intermediateDt.inTimeZone(this._tz, { disambiguation }); + let intermediateAbs = intermediateDt.toAbsolute(this._tz, { disambiguation }); let adjustedTimeDuration: Temporal.Duration; if (this._tz.getOffsetNanosecondsFor(intermediateAbs) === other.timeZoneOffsetNanoseconds) { // The transition was in the date portion which is what we want. @@ -972,7 +975,7 @@ export class LocalDateTime { // time portion is on the other side next to `this`, where there's // unlikely to be another transition. intermediateDt = other._dt.plus(dateDuration); - intermediateAbs = intermediateDt.inTimeZone(this._tz, { disambiguation }); + intermediateAbs = intermediateDt.toAbsolute(this._tz, { disambiguation }); adjustedTimeDuration = this._abs.difference(intermediateAbs, { largestUnit: 'hours' }); } @@ -1076,16 +1079,16 @@ export class LocalDateTime { return this._dt.isLeapYear; } toDate(): Temporal.Date { - return this._dt.getDate(); + return this._dt.toDate(); } toYearMonth(): Temporal.YearMonth { - return this._dt.getYearMonth(); + return this._dt.toYearMonth(); } toMonthDay(): Temporal.MonthDay { - return this._dt.getMonthDay(); + return this._dt.toMonthDay(); } toTime(): Temporal.Time { - return this._dt.getTime(); + return this._dt.toTime(); } valueOf(): never { throw new TypeError('use compare() or equals() to compare Temporal.LocalDateTime'); @@ -1298,9 +1301,9 @@ function toLargestTemporalUnit number, + ToString: ToString as (x: unknown) => string, + ToObject: ToObject as (x: unknown) => Record, // replace this with public parsing API after it lands ParseFullISOString: (isoString: string) => { diff --git a/polyfill/lib/poc/postProcess.js b/polyfill/lib/poc/postProcess.js index 57f9c25e67..6289fa292f 100755 --- a/polyfill/lib/poc/postProcess.js +++ b/polyfill/lib/poc/postProcess.js @@ -20,8 +20,11 @@ function processDts(file, original, final) { function processMjs(file) { let lines = readAllLines(file); const prepend = [ - "import ES2019 from 'es-abstract/es2019.js';", + // "import ES2019 from 'es-abstract/es2019.js';", "import { GetIntrinsic, MakeIntrinsicClass } from './intrinsicclass.mjs'", + "import ToInteger from 'es-abstract/2019/ToInteger.js';", + "import ToObject from 'es-abstract/2019/ToObject.js';", + "import ToString from 'es-abstract/2019/ToString.js';", '', 'const Temporal = {', " get DateTime() { return GetIntrinsic('%Temporal.DateTime%'); },", @@ -32,7 +35,7 @@ function processMjs(file) { '};' ]; const append = ['', "MakeIntrinsicClass(LocalDateTime, 'Temporal.LocalDateTime');"]; - const updated = [...prepend, ...lines.slice(2), ...append]; + const updated = [...prepend, ...lines.slice(8), ...append]; writeAllLines(file, updated); } diff --git a/polyfill/poc.d.ts b/polyfill/poc.d.ts index 9b74f01108..bcbf5194cd 100644 --- a/polyfill/poc.d.ts +++ b/polyfill/poc.d.ts @@ -209,8 +209,8 @@ export namespace Temporal { other: Temporal.Absolute, options?: DifferenceOptions<'days' | 'hours' | 'minutes' | 'seconds'> ): Temporal.Duration; - inTimeZone(tzLike: TimeZoneProtocol | string, calendar?: CalendarProtocol | string): Temporal.DateTime; toLocalDateTime(tzLike: TimeZoneProtocol | string, calendar?: CalendarProtocol | string): Temporal.LocalDateTime; + toDateTime(tzLike: TimeZoneProtocol | string, calendar?: CalendarProtocol | string): Temporal.DateTime; toLocaleString(locales?: string | string[], options?: Intl.DateTimeFormatOptions): string; toJSON(): string; toString(tzLike?: TimeZoneProtocol | string): string; @@ -374,14 +374,14 @@ export namespace Temporal { other: Temporal.Date, options?: DifferenceOptions<'years' | 'months' | 'weeks' | 'days'> ): Temporal.Duration; - withTime(temporalTime: Temporal.Time): Temporal.DateTime; toLocalDateTime( tzLike: TimeZoneProtocol | string, temporalTime: Temporal.Time, options?: ToAbsoluteOptions ): Temporal.LocalDateTime; - getYearMonth(): Temporal.YearMonth; - getMonthDay(): Temporal.MonthDay; + toDateTime(temporalTime: Temporal.Time): Temporal.DateTime; + toYearMonth(): Temporal.YearMonth; + toMonthDay(): Temporal.MonthDay; getFields(): DateFields; getISOCalendarFields(): DateISOCalendarFields; toLocaleString(locales?: string | string[], options?: Intl.DateTimeFormatOptions): string; @@ -480,12 +480,12 @@ 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; toLocalDateTime(tzLike: TimeZoneProtocol | string, options?: ToAbsoluteOptions): Temporal.LocalDateTime; - getDate(): Temporal.Date; - getYearMonth(): Temporal.YearMonth; - getMonthDay(): Temporal.MonthDay; - getTime(): Temporal.Time; + toAbsolute(tzLike: TimeZoneProtocol | string, options?: ToAbsoluteOptions): Temporal.Absolute; + toDate(): Temporal.Date; + toYearMonth(): Temporal.YearMonth; + toMonthDay(): Temporal.MonthDay; + toTime(): Temporal.Time; getFields(): DateTimeFields; getISOCalendarFields(): DateTimeISOCalendarFields; toLocaleString(locales?: string | string[], options?: Intl.DateTimeFormatOptions): string; @@ -519,7 +519,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; @@ -549,7 +549,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. */ @@ -575,12 +575,12 @@ 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; toLocalDateTime( tzLike: TimeZoneProtocol | string, temporalDate: DateLike, options?: ToAbsoluteOptions ): Temporal.LocalDateTime; + toDateTime(temporalDate: Temporal.Date): Temporal.DateTime; getFields(): TimeFields; toLocaleString(locales?: string | string[], options?: Intl.DateTimeFormatOptions): string; toJSON(): string; @@ -668,7 +668,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/test/localdatetime.mjs b/polyfill/test/localdatetime.mjs index 2c7b8f0c38..560af46d37 100644 --- a/polyfill/test/localdatetime.mjs +++ b/polyfill/test/localdatetime.mjs @@ -447,8 +447,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); @@ -460,26 +460,26 @@ 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 optional parameter', () => { - const dt = abs.inTimeZone(); - equal(abs.getEpochNanoseconds(), dt.inTimeZone().getEpochNanoseconds()); + const dt = abs.toDateTime(); + equal(abs.getEpochNanoseconds(), dt.toAbsolute().getEpochNanoseconds()); equal(`${dt}`, '1976-11-18T14:23:30.123456789'); }); */ it('optional 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('optional 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'); }); }); @@ -521,7 +521,7 @@ describe('LocalDateTime', () => { }); it('Samoa date line change: 10:00PM 29 Dec 2011 -> 11:00PM 31 Dec 2011', () => { - const dayBeforeSamoaDateLineChangeAbs = new Temporal.DateTime(2011, 12, 29, 22).inTimeZone('Pacific/Apia'); + const dayBeforeSamoaDateLineChangeAbs = new Temporal.DateTime(2011, 12, 29, 22).toAbsolute('Pacific/Apia'); const start = LocalDateTime.from({ absolute: dayBeforeSamoaDateLineChangeAbs, timeZone: 'Pacific/Apia' }); const added = start.plus({ days: 1, hours: 1 }); equal(added.day, 31); @@ -747,9 +747,6 @@ describe('LocalDateTime', () => { it('LocalDateTime.prototype.equals is a Function', () => { equal(typeof LocalDateTime.prototype.equals, 'function'); }); - // it('LocalDateTime.prototype.inTimeZone is a Function', () => { - // equal(typeof LocalDateTime.prototype.inTimeZone, 'function'); - // }); it('LocalDateTime.prototype.getDate is a Function', () => { equal(typeof LocalDateTime.prototype.toDate, 'function'); }); @@ -1090,32 +1087,32 @@ describe('LocalDateTime', () => { 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', () => { const dt = DateTime.from('2019-02-16T23:45'); - 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', { 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('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) ); }); }); @@ -1166,8 +1163,8 @@ describe('LocalDateTime', () => { 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'); @@ -1175,12 +1172,12 @@ describe('LocalDateTime', () => { 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(() => midnight.withDate(min), RangeError); - equal(`${min.withTime(firstNs)}`, '-271821-04-19T00:00:00.000000001'); - equal(`${firstNs.withDate(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'); + throws(() => min.toDateTime(midnight), RangeError); + throws(() => midnight.toDateTime(min), RangeError); + equal(`${min.toDateTime(firstNs)}`, '-271821-04-19T00:00:00.000000001'); + equal(`${firstNs.toDateTime(min)}`, '-271821-04-19T00:00:00.000000001'); + 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', () => { const min = DateTime.from('-271821-04-19T00:00:00.000000001'); @@ -1191,22 +1188,22 @@ describe('LocalDateTime', () => { }); }); }); - describe('DateTime.inTimeZone() works', () => { + describe('DateTime.toAbsolute() works', () => { const dt = DateTime.from('1976-11-18T15:23:30.123456789'); /* it('without optional parameter', () => { - const abs = dt.inTimeZone(); + const abs = dt.toAbsolute(); equal(`${abs}`, '1976-11-18T15:23:30.123456789Z'); }); */ it('optional 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('optional 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'); }); });