diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000000..6c6cd42899 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +node_modules/ +polyfill/index.js +polyfill/index.js.map diff --git a/polyfill/LICENSE b/polyfill/LICENSE new file mode 100644 index 0000000000..f152b20980 --- /dev/null +++ b/polyfill/LICENSE @@ -0,0 +1,16 @@ +Copyright 2018 Bloomberg LP + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software +and associated documentation files (the "Software"), to deal in the Software without restriction, +including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, +and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, +subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial +portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT +NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/polyfill/README.md b/polyfill/README.md new file mode 100644 index 0000000000..b5ebcce026 --- /dev/null +++ b/polyfill/README.md @@ -0,0 +1,37 @@ +# Temporal Polyfill + +This is an implementation of a polyfill for the [TC39 Termporal Proposal](https://github.com/tc39/proposal-temporal). + +## Implementation Issues: + +## Proposed Changes / Additions to the Proposal + +### `Instant` constructor to take single `BigInt` argument + +### `Instant.toDate()` & `Instant.fromDate()` for interoperability with `Date()` + +### `Instant.prototype.valueOf()` & `ZonedInstant.prototype.valueOf()` + +To facilitate comparisons between `Intant`s and/or `ZonedInstant`s it would be extremely useful to implement `valueOf()`. +Considering the fact that these have nanosecond precision, the proposed `[BigInt](https://github.com/tc39/proposal-bigint)` +seems to be the right choice of primitive. + +### `Instant.prototype.toDate()` & `ZonedInstant.prototype.toDate()` + +To facilitate better interoperation with existing `Date` APIs it would be useful to add a casting method to +`Instant` & `ZonedInstant`. + +An example of such APIs would be the `Intl.DateTimeFormat` apis which work well with Dates, but not (yet?) with `Instant` & +`ZonedInstant`. Though for this specific case it might be better to add `format()` (see below). + +### `Instant.prototype.format(locale = navigator.language, options = {})` & `ZonedInstant.prototype.format(locale = navigator.language, options = {})` + +Considering the frequency of converting date/time values to customized strings, the `format` convenience method seems +to make sense. It should follow the same signature as `Intl.DateTimeFormat.prototype.format` with the notable exception +that `locale` ise defaulted to `navigator.language` and the `timeZone` option is overriddent to the `ZonedInstant`'s time +zone or UTC for `Instant`s. + +### static `Instant.now()` + +This would facilitate easier creation of Instant objects eliminating the need to work with `Date` objects. In addition, +when implemented natively, this would enable a higher precision timer. diff --git a/polyfill/lib/civildate.mjs b/polyfill/lib/civildate.mjs new file mode 100644 index 0000000000..d2eb67656c --- /dev/null +++ b/polyfill/lib/civildate.mjs @@ -0,0 +1,50 @@ +/* +** Copyright (C) 2018 Bloomberg LP. All rights reserved. +** This code is governed by the license found in the LICENSE file. +*/ + +import { plus, pad } from './util.mjs'; +import { CivilDateTime } from './civildatetime.mjs'; + +const DATA = Symbol('data'); + +export class CivilDate { + constructor(years, months, days) { + const { year, month, day } = plus({}, { years, months, days }); + this[DATA] = { year, month, day }; + } + + get year() { return this[DATA].year; } + get month() { return this[DATA].month; } + get day() { return this[DATA].day; } + + plus(data) { + const { year, month, day } = plus(this, data); + return new CivilDate(year, month, day); + } + with({ year = this.year, month = this.month , day = this.day } = {}) { + return new CivilDate(year, month, day); + } + withTime(time = CivilDateTime.now().toCivilTime()) { + return new CivilDateTime.from(this, time); + } + toString() { + const { year, month, day } = this; + return `${pad(year, 4)}-${pad(month, 2)}-${pad(day, 2)}`; + } + + toDate(zone, time) { + return this.withTime(date).withZone(zone).toDate(); + } + + static now(zone) { + return CivilDateTime.now(zone).toCivilDate(); + } + static fromDate(date, zone) { + return CivilDateTime.fromDate(date, zone).toCivilDate(); + } + + static parse(string) { + return CivilDateTime.parse(string).toCivilDate(); + } +}; diff --git a/polyfill/lib/civildatetime.mjs b/polyfill/lib/civildatetime.mjs new file mode 100644 index 0000000000..53193f9782 --- /dev/null +++ b/polyfill/lib/civildatetime.mjs @@ -0,0 +1,77 @@ +/* +** Copyright (C) 2018 Bloomberg LP. All rights reserved. +** This code is governed by the license found in the LICENSE file. +*/ + +import { plus, pad, parse } from './util.mjs'; +import { toEpoch } from './epoch.mjs'; +import { CivilDate } from './civildate.mjs'; +import { CivilTime } from './civiltime.mjs'; +import { VALUE, Instant } from './instant.mjs'; +import { ZonedInstant } from './zonedinstant.mjs'; + +const DATA = Symbol('data'); + +export class CivilDateTime { + constructor(years, months, days, hours, minutes, seconds = 0, milliseconds = 0, nanoseconds = 0) { + this[DATA] = plus({}, { years, months, days, hours, minutes, seconds, milliseconds, nanoseconds }); + } + + get year() { return this[DATA].year; } + get month() { return this[DATA].month; } + get day() { return this[DATA].day; } + get hour() { return this[DATA].hour; } + get minute() { return this[DATA].minute; } + get second() { return this[DATA].second; } + get millisecond() { return this[DATA].millisecond; } + get nanosecond() { return this[DATA].nanosecond; } + + plus(data) { + const { year, month, day, hour, minute, second, millisecond, nanosecond } = plus(this, data); + return new CivilDateTime(year, month, day, hour, minute, second, millisecond, nanosecond); + } + with({ year = this.year, month = this.month , day = this.day, hour = this.hour, minute = this.minute, second = this.second, millisecond = this.millisecond, nanosecond = this.nanosecond } = {}) { + return new CivilDateTime(year, month, day, hour, minute, second, millisecond, nanosecond); + } + toCivilDate() { + const { year, month, day } = this; + return new CivilDate(year, month, day); + } + toCivilTime() { + const { hour, minute, second, millisecond, nanosecond } = this; + return new CivilTime(hour, minute, second, millisecond, nanosecond); + } + withZone(zone) { + const milliseconds = toEpoch(this, zone); + const nanoseconds = this.nanosecond; + const instant = Object.create(Instant.prototype); + instant[VALUE] = { milliseconds, nanoseconds }; + return new ZonedInstant(instant, zone); + } + toString() { + const { year, month, day, hour, minute, second, millisecond, nanosecond } = this; + const nanos = (millisecond * 1E6) + nanosecond; + return `${pad(year, 4)}-${pad(month, 2)}-${pad(day, 2)}T${pad(hour, 2)}:${pad(minute, 2)}:${pad(second, 2)}.${pad(nanos, 9)}`; + } + + toDate(zone) { + return this.withZone(zone).toDate(); + } + + static from(date = {}, time = {}) { + const { year, month, day } = date; + const { hour, minute, second, millisecond, nanosecond } = time; + return new CivilDateTime(year, month, day, hour, minute, second, millisecond, nanosecond); + } + static now(zone) { + return ZonedInstant.now(zone).toCivilDateTime(); + } + static fromDate(date, zone) { + return ZonedInstant.fromDate(date, zone).toCivilDateTime(); + } + + static parse(string) { + const { year, month, day, hour, minute, second, millisecond, nanosecond } = parse(string); + return new CivilDateTime(year, month, day, hour, minute, second, millisecond, nanosecond); + } +}; diff --git a/polyfill/lib/civiltime.mjs b/polyfill/lib/civiltime.mjs new file mode 100644 index 0000000000..ee9fd76af1 --- /dev/null +++ b/polyfill/lib/civiltime.mjs @@ -0,0 +1,60 @@ +/* +** Copyright (C) 2018 Bloomberg LP. All rights reserved. +** This code is governed by the license found in the LICENSE file. +*/ + +import { plus, pad } from './util.mjs'; +import { CivilDateTime } from './civildatetime.mjs'; +import { CivilDate } from './civildate.mjs'; + +const DATA = Symbol('data'); + +export class CivilTime { + constructor(hours, minutes, seconds = 0, milliseconds = 0, nanoseconds = 0) { + const { hour, minute, second, millisecond, nanosecond } = plus({}, { hours, minutes, seconds, milliseconds, nanoseconds }); + this[DATA] = { hour, minute, second, millisecond, nanosecond }; + } + + get hour() { return this[DATA].hour; } + get minute() { return this[DATA].minute; } + get second() { return this[DATA].second; } + get millisecond() { return this[DATA].millisecond; } + get nanosecond() { return this[DATA].nanosecond; } + + plus(data) { + const { + hour, + minute, + second, + millisecond, + nanosecond + } = plus(this, data); + return new CivilTime(hour, minute, second, millisecond, nanosecond); + } + with({ hour = this.hour, minute = this.minute, second = this.second, millisecond = this.millisecond, nanosecond = this.nanosecond } = {}) { + return new CivilTime(hour, minute, second, millisecond, nanosecond); + } + withDate(date = CivilDateTime.now().toCivilDate()) { + return new CivilDateTime.from(date, this); + } + toString() { + const { hour, minute, second, millisecond, nanosecond } = this; + const nanos = (millisecond * 1E6) + nanosecond; + return `${pad(hour, 2)}:${pad(minute, 2)}:${pad(second, 2)}.${pad(nanos, 9)}`; + } + + toDate(zone, date) { + return this.withDate(date).withZone(zone).toDate(); + } + + static now(zone) { + return CivilDateTime.now(zone).toCivilTime(); + } + static fromDate(date, zone) { + return CivilDateTime.fromDate(date, zone).toCivilTime(); + } + + static parse(string) { + return CivilDateTime.parse(string).toCivilTime(); + } +} diff --git a/polyfill/lib/epoch.mjs b/polyfill/lib/epoch.mjs new file mode 100644 index 0000000000..e834617fb1 --- /dev/null +++ b/polyfill/lib/epoch.mjs @@ -0,0 +1,117 @@ +/* +** Copyright (C) 2018 Bloomberg LP. All rights reserved. +** This code is governed by the license found in the LICENSE file. +*/ + +export function toEpoch({ year = 1970, month = 1, day = 1, hour = 0, minute = 0, second = 0, millisecond = 0 } = {}, zone) { + const ts = Date.UTC(year, month - 1, day, hour, minute, second, millisecond); + + const offsetI = guessOffset(ts, zone); + + const offsetA = guessOffset(ts + offsetI, zone); + if (checkOffset(ts + offsetA, zone, { year, month, day, hour, minute, second, millisecond })) { + return ts + offsetA; + } + + const offsetB = guessOffset(ts - offsetI, zone); + if (checkOffset(ts + offsetB, zone, { year, month, day, hour, minute, second, millisecond })) { + return ts + offsetB; + } + + return ts + Math.min(offsetA, offsetB); +} + +export function fromEpoch(ts = 0, zone) { + const date = new Date(ts); + const fmt = formatter(zone); + const { year, month, day, hour, minute, second } = fmt.formatToParts(date).reduce((res, item)=>{ + if (item.type !== 'literal') res[item.type] = parseInt(item.value, 10); + return res; + }, {}); + return { + year, month, day, + hour, minute, second, + millisecond: date.getUTCMilliseconds() + }; +} + +export function zoneOffset(ts, zone) { + const offset = Math.floor(guessOffset(ts, zone) / 60000); + const sign = offset <= 0 ? '+' : '-'; + const hours = ('00' + Math.floor(Math.abs(offset) / 60)).slice(-2); + const minutes = ('00' + Math.abs(offset % 60)).slice(-2); + + return `${sign}${hours}:${minutes}`; +} + +function guessOffset(ts, zone) { + const offset = fromEpoch(ts, zone); + const zoned = Date.UTC(offset.year, offset.month - 1, offset.day, offset.hour, offset.minute, offset.second, ts % 1000); + return ts - zoned; +} + +function checkOffset(ts, zone, { year, month, day, hour, minute, second, millisecond }) { + const parts = fromEpoch(ts, zone); + return true && + (year === parts.year) && + (month === parts.month) && + (day === parts.day) && + (hour === parts.hour) && + (minute === parts.minute) && + (second === parts.second) && + (millisecond === parts.millisecond); +} + +function formatter(zone) { + if (zone === 'SYSTEM') { + return { + formatToParts: (date)=>[ + { type: 'year', value: '' + r.getFullYear() }, + { type: 'literal', value: '-' }, + { type: 'month', value: '' + (r.getMonth() + 1) }, + { type: 'literal', value: '-' }, + { type: 'day', value: '' + r.getDate() }, + { type: 'literal', value: ' ' }, + { type: 'hour', value: '' + r.getHours() }, + { type: 'literal', value: ':' }, + { type: 'minute', value: '' + r.getMinutes() }, + { type: 'literal', value: ':' }, + { type: 'second', value: '' + r.getSeconds() } + ] + }; + } + const parts = /([+-])(\d{1,2})(?::?(\d{2}))?/.exec(zone); + if (parts) { + const minutes = (+parts[2] * 60) + (parts[3] || 0); + const offset = (parts[1] === '-') ? -minutes : +minutes; + return { + formatToParts: (date)=>{ + const ts = date.valueOf() - offset; + const r = new Date(ts); + return [ + { type: 'year', value: '' + r.getUTCFullYear() }, + { type: 'literal', value: '-' }, + { type: 'month', value: '' + (r.getUTCMonth() + 1) }, + { type: 'literal', value: '-' }, + { type: 'day', value: '' + r.getUTCDate() }, + { type: 'literal', value: ' ' }, + { type: 'hour', value: '' + r.getUTCHours() }, + { type: 'literal', value: ':' }, + { type: 'minute', value: '' + r.getUTCMinutes() }, + { type: 'literal', value: ':' }, + { type: 'second', value: '' + r.getUTCSeconds() } + ]; + } + }; + } + return new Intl.DateTimeFormat('en-iso', { + year: 'numeric', + month: 'numeric', + day: 'numeric', + hour: 'numeric', + minute: 'numeric', + second: 'numeric', + hour12: false, + timeZone: zone + }); +} diff --git a/polyfill/lib/index.mjs b/polyfill/lib/index.mjs new file mode 100644 index 0000000000..a18295c12d --- /dev/null +++ b/polyfill/lib/index.mjs @@ -0,0 +1,10 @@ +/* +** Copyright (C) 2018 Bloomberg LP. All rights reserved. +** This code is governed by the license found in the LICENSE file. +*/ + +export { CivilDate } from './civildate.mjs'; +export { CivilTime } from './civiltime.mjs'; +export { CivilDateTime } from './civildatetime.mjs'; +export { Instant } from './instant.mjs'; +export { ZonedInstant } from './zonedinstant.mjs'; diff --git a/polyfill/lib/instant.mjs b/polyfill/lib/instant.mjs new file mode 100644 index 0000000000..cdae8ad41e --- /dev/null +++ b/polyfill/lib/instant.mjs @@ -0,0 +1,87 @@ +/* +** Copyright (C) 2018 Bloomberg LP. All rights reserved. +** This code is governed by the license found in the LICENSE file. +*/ + +import { plus, pad } from './util.mjs'; +import { ZonedInstant } from './zonedinstant.mjs'; + +export const VALUE = Symbol('value'); + +export class Instant { + constructor(nanos = 0) { + if('bigint' !== typeof nanos) { nanos = BigInt(nanos); } + const milliseconds = Number(nanos / BigInt(1e6)); + const nanoseconds = Number(nanos % BigInt(1e6)); + this[VALUE] = { milliseconds, nanoseconds }; + } + + get milliseconds() { return this[VALUE].milliseconds; } + get nanoseconds() { return this[VALUE].nanoseconds; } + + plus(data) { + const object = Object.create(Instant.prototype); + object[VALUE] = fromParts( + plus( + toParts(this[VALUE]), + data + ) + ); + return object; + } + withZone(zone) { + return new ZonedInstant(this, zone); + } + toString() { + return this.withZone('UTC').toString(); + } + + toDate() { + return new Date(this.milliseconds); + } + valueOf() { + return BigInt(this[VALUE].milliseconds) * BigInt(1e6) + BigInt(this[VALUE].nanoseconds); + } + format(locale, options) { + return this.withZone().format(locale, options); + } + + static now() { + const object = Object.create(Instant.prototype); + object[VALUE] = { + milliseconds: Date.now(), + nanoseconds: 0 + }; + return object; + } + static fromDate(date) { + const object = Object.create(Instant.prototype); + object[VALUE] = { + milliseconds: (date || 0).valueOf(), + nanoseconds: 0 + }; + return object; + } + + static parse(string) { + return ZonedInstant.parse(string).toInstant(); + } +} + +function toParts(value) { + const millis = value.milliseconds; + const date = new Date(millis); + const year = date.getUTCFullYear(); + const month = date.getUTCMonth() + 1; + const day = date.getUTCDate(); + const hour = date.getUTCHours(); + const minute = date.getUTCMinutes(); + const second = date.getUTCSeconds(); + const millisecond = date.getUTCMilliseconds(); + const nanosecond = value.nanoseconds; + return { year, month, day, hour, minute, second, millisecond, nanosecond }; +} +function fromParts({ year = 0, month = 1, day = 1, hour = 0, minute = 0, second = 0, millisecond = 0, nanoseconds = 0 }) { + const milliseconds = Date.UTC(year, month - 1, day, hour, minute, second, millisecond); + return { milliseconds, nanoseconds }; +} diff --git a/polyfill/lib/util.mjs b/polyfill/lib/util.mjs new file mode 100644 index 0000000000..f8a9181e3d --- /dev/null +++ b/polyfill/lib/util.mjs @@ -0,0 +1,136 @@ +/* +** Copyright (C) 2018 Bloomberg LP. All rights reserved. +** This code is governed by the license found in the LICENSE file. +*/ + +import { zones } from './zones.mjs'; + +export function plus( + { year: ly = 0, month: lm = 0, day: ld = 0, hour: lhr = 0, minute: lmn = 0, second: lsd = 0, millisecond: lms = 0, nanosecond: lns = 0 } = {}, + { years: ry = 0, months: rm = 0, days: rd = 0, hours: rhr = 0, minutes: rmn = 0, seconds: rsd = 0, milliseconds: rms = 0, nanoseconds: rns = 0 } = {} +) { + let year = ly + ry; + let month = lm + rm; + let day = ld + rd; + let hour = lhr + rhr; + let minute = lmn + rmn; + let second = lsd + rsd; + let millisecond = lms + rms; + let nanosecond = lns + rns; + + while (nanosecond < 0) { + nanosecond += 1E6; + millisecond -= 1; + } + while (nanosecond >= 1E6) { + nanosecond -= 1E6; + millisecond += 1; + } + + const date = new Date(Date.UTC(year, month - 1, day, hour, minute, second, millisecond)); + + return { + year: date.getUTCFullYear(), + month: date.getUTCMonth() + 1, + day: date.getUTCDate(), + hour: date.getUTCHours(), + minute: date.getUTCMinutes(), + second: date.getUTCSeconds(), + millisecond: date.getUTCMilliseconds(), + nanosecond + }; +}; + +export function pad(num, cnt) { + return `0000000000${`${num}`.trim()}`.slice(-1 * cnt); +}; + +let systemZone; +export function systemTimeZone() { + if (systemZone) { return systemZone; } + const zone = new Intl.DateTimeFormat('en-us', { timeZoneName: 'long' }).formatToParts().find((i)=>(i.type==='timeZoneName')); + if (zones[zone.value]) { return zone.value; } + const iana = Object.keys(zones); + for (let iananame of iana) { + const data = zones[iananame]; + if (Object.keys(data).find((off)=>(data[off] === zone.value))) { + return (systemZone = iananame); + }; + } + + const offset = (new Date()).getTimezoneOffset(); + const sign = offset < 0 ? '-' : '+'; + const hours = ('00' + Math.floor(Math.abs(offset) / 60)).slice(-2); + const minutes = ('00' + Math.floor(Math.abs(offset) % 60)).slice(-2); + const short = `${sign}${hours}:${minutes}`; + + for (let iananame of iana) { + const data = iana[iananame]; + if (data[short]) { return iananame; } + } + return short; +}; + +function findTimeZone(offset) { + const base = Math.abs(Math.floor(offset / 60000)) + const hours = ('00' + Math.floor(base / 60)).slice(-2); + const minutes = ('00' + (base % 60)).slice(-2); + const string = `${offset < 0 ? '-' : '+'}${hours}:${minutes}`; + + const iana = Object.keys(zones); + for (let iananame of iana) { + const data = zones[iananame]; + if (data[string]) return iananame; + } + return undefined; +} + +export function validZone(zone) { + zone = zone === 'SYSTEM' ? systemTimeZone() : zone; + if (!!zones[zone]) { return zone; } + const match = /([+-])?(\d{1,2})(:?(\d{1,2}))?/.exec(zone); + if (!match) throw new TypeError(`Invalid Time-Zone: ${zone}`); + const sign = match[1] || '+'; + const hours = ('00' + match[2]).slice(-2); + const minutes = ('00' + (mathc[3] || '')).slice(-2); + return `${sign}${hours}:{$minutes}`; +} + +const parseExpression = (()=>{ + const date = '(\\d{4})-(\\d{2})-(\\d{2})'; + const time = '(\\d{2}):(\\d{2}):(\\d{2})(?:\\.(\\d{3,9}))?'; + const offs = '([+-]?\\d{1,2}(?::?\\d{2})?)'; + const zone = '(?:\\[(\\w+\/\\w+|UTC)\\])'; + return new RegExp(`^${date}T${time}${offs}?${zone}?$`); +})(); +const parseOffset = (str)=>{ + if (!str) return undefined; + const match = /([+-]?\d{1,2}):?(\d{2})?/.exec(str) || [ null, '0', '0' ]; + const hour = match[1] || '0'; + const mins = match[2] || '0'; + return ((+hour * 60) + (+mins)) * 60000; +}; + +export function parse(str) { + const match = parseExpression.exec(str) || []; + const year = +match[1]; + const month = +match[2]; + const day = +match[3]; + const hour = +match[4]; + const minute = +match[5]; + const second = +match[6]; + const subsec = +((isNaN(+match[7])?0:+match[7]) + '000000000').slice(0, 9).replace(/^0+/,''); + + const millisecond = Math.floor(subsec / 1e6); + const nanosecond = (subsec % 1e6); + + const offset = parseOffset(match[8]); + const zone = match[9] || findTimeZone(offset) || systemTimeZone(); + + return { + year, month, day, + hour, minute, second, + millisecond, nanosecond, + offset, zone + }; +}; diff --git a/polyfill/lib/zonedinstant.mjs b/polyfill/lib/zonedinstant.mjs new file mode 100644 index 0000000000..4d5df932ec --- /dev/null +++ b/polyfill/lib/zonedinstant.mjs @@ -0,0 +1,77 @@ +/* +** Copyright (C) 2018 Bloomberg LP. All rights reserved. +** This code is governed by the license found in the LICENSE file. +*/ + +import { plus, pad, validZone, parse } from './util.mjs'; +import { fromEpoch, zoneOffset } from './epoch.mjs'; +import { CivilDate } from './civildate.mjs'; +import { CivilTime } from './civiltime.mjs'; +import { CivilDateTime } from './civildatetime.mjs'; + +const INSTANT = Symbol('instant'); +const ZONE = Symbol('zone'); + +export class ZonedInstant{ + constructor(instant, zone = 'SYSTEM') { + zone = validZone(zone); + this[INSTANT] = instant; + this[ZONE] = zone; + } + + get milliseconds() { return this[INSTANT].milliseconds; } + get nanoseconds() { return this[INSTANT].nanoseconds; } + get timeZone() { return this[ZONE]; } + + toCivilDateTime() { + const { year, month, day, hour, minute, second, millisecond } = fromEpoch(this[INSTANT].milliseconds, this[ZONE]); + const nanosecond = this[INSTANT].nanoseconds; + return new CivilDateTime(year, month, day, hour, minute, second, millisecond, nanosecond); + } + toCivilTime() { + const { hour, minute, second, millisecond } = fromEpoch(this[INSTANT].milliseconds, this[ZONE]); + const nanosecond = this[INSTANT].nanoseconds; + return new CivilTime(hour, minute, second, millisecond, nanosecond); + } + toCivilDate() { + const { year, month, day } = fromEpoch(this[INSTANT].milliseconds, this[ZONE]); + return new CivilDate(year, month, day); + } + toInstant() { return this[INSTANT]; } + toString() { + const ts = this[INSTANT].milliseconds; + const { year, month, day, hour, minute, second, millisecond } = fromEpoch(ts, this[ZONE]); + const nanosecond = (millisecond * 1e6) + this[INSTANT].nanoseconds; + const offset = zoneOffset(ts, this[ZONE]); + const zone = ((this[ZONE].indexOf('/') > -1) || (this[ZONE] === 'UTC')) ? `[${this[ZONE]}]` : ''; + return `${pad(year,4)}-${pad(month,2)}-${pad(day,2)}T${pad(hour,2)}:${pad(minute,2)}:${pad(second,2)}.${pad(nanosecond,9)}${offset}${zone}`; + } + + toDate() { + return this.toInstant().toDate(); + } + valueOf() { + return this.toInstant().valueOf(); + } + format(locale = navigator.language, options = {}) { + const fmt = new Intl.DateTimeFormat( + locale, + Object.assign({}, options, { timeZone: this.timeZone }) + ); + return fmt.format(this.toDate()); + } + + static now(zone) { + return Instant.now().withZone(zone); + } + static fromDate(date, zone) { + return Instant.fromDate(date).withZone(zone); + } + + static parse(string) { + const { year, month, day, hour, minute, second, millisecond, nanosecond, zone } = parse(string); + const civil = new CivilDateTime(year, month, day, hour, minute, second, millisecond, nanosecond); + return civil.withZone(zone); + } +}; + diff --git a/polyfill/lib/zones.mjs b/polyfill/lib/zones.mjs new file mode 100644 index 0000000000..132e396bba --- /dev/null +++ b/polyfill/lib/zones.mjs @@ -0,0 +1,1430 @@ +/* +** Copyright (C) 2018 Bloomberg LP. All rights reserved. +** This code is governed by the license found in the LICENSE file. +*/ + +export const zones = { + "Europe/Andorra": { + "+01:00": "Central European Standard Time", + "+02:00": "Central European Summer Time" + }, + "Asia/Dubai": { + "+04:00": "Gulf Standard Time" + }, + "Asia/Kabul": { + "+04:30": "Afghanistan Time" + }, + "America/Antigua": { + "-04:00": "Atlantic Standard Time" + }, + "America/Anguilla": { + "-04:00": "Atlantic Standard Time" + }, + "Europe/Tirane": { + "+01:00": "Central European Standard Time", + "+02:00": "Central European Summer Time" + }, + "Asia/Yerevan": { + "+04:00": "Armenia Standard Time" + }, + "Africa/Luanda": { + "+01:00": "West Africa Standard Time" + }, + "Antarctica/Casey": { + "+11:00": "Casey Time" + }, + "Antarctica/Davis": { + "+07:00": "Davis Time" + }, + "Antarctica/Mawson": { + "+05:00": "Mawson Time" + }, + "Antarctica/Palmer": { + "-03:00": "GMT-03:00" + }, + "Antarctica/Rothera": { + "-03:00": "Rothera Time" + }, + "Antarctica/Syowa": { + "+03:00": "Syowa Time" + }, + "Antarctica/Troll": { + "+00:00": "Greenwich Mean Time", + "+02:00": "GMT+02:00" + }, + "Antarctica/Vostok": { + "+06:00": "Vostok Time" + }, + "America/Argentina/Buenos_Aires": { + "-03:00": "Argentina Standard Time" + }, + "America/Argentina/Cordoba": { + "-03:00": "Argentina Standard Time" + }, + "America/Argentina/Salta": { + "-03:00": "Argentina Standard Time" + }, + "America/Argentina/Jujuy": { + "-03:00": "Argentina Standard Time" + }, + "America/Argentina/Tucuman": { + "-03:00": "Argentina Standard Time" + }, + "America/Argentina/Catamarca": { + "-03:00": "Argentina Standard Time" + }, + "America/Argentina/La_Rioja": { + "-03:00": "Argentina Standard Time" + }, + "America/Argentina/San_Juan": { + "-03:00": "Argentina Standard Time" + }, + "America/Argentina/Mendoza": { + "-03:00": "Argentina Standard Time" + }, + "America/Argentina/San_Luis": { + "-03:00": "Western Argentina Standard Time" + }, + "America/Argentina/Rio_Gallegos": { + "-03:00": "Argentina Standard Time" + }, + "America/Argentina/Ushuaia": { + "-03:00": "Argentina Standard Time" + }, + "Pacific/Pago_Pago": { + "-11:00": "Samoa Standard Time" + }, + "Europe/Vienna": { + "+01:00": "Central European Standard Time", + "+02:00": "Central European Summer Time" + }, + "Australia/Lord_Howe": { + "+11:00": "Lord Howe Daylight Time", + "+10:30": "Lord Howe Standard Time" + }, + "Antarctica/Macquarie": { + "+11:00": "Macquarie Island Time" + }, + "Australia/Hobart": { + "+11:00": "Australian Eastern Daylight Time", + "+10:00": "Australian Eastern Standard Time" + }, + "Australia/Currie": { + "+11:00": "Australian Eastern Daylight Time", + "+10:00": "Australian Eastern Standard Time" + }, + "Australia/Melbourne": { + "+11:00": "Australian Eastern Daylight Time", + "+10:00": "Australian Eastern Standard Time" + }, + "Australia/Sydney": { + "+11:00": "Australian Eastern Daylight Time", + "+10:00": "Australian Eastern Standard Time" + }, + "Australia/Broken_Hill": { + "+10:30": "Australian Central Daylight Time", + "+09:30": "Australian Central Standard Time" + }, + "Australia/Brisbane": { + "+10:00": "Australian Eastern Standard Time" + }, + "Australia/Lindeman": { + "+10:00": "Australian Eastern Standard Time" + }, + "Australia/Adelaide": { + "+10:30": "Australian Central Daylight Time", + "+09:30": "Australian Central Standard Time" + }, + "Australia/Darwin": { + "+09:30": "Australian Central Standard Time" + }, + "Australia/Perth": { + "+08:00": "Australian Western Standard Time" + }, + "Australia/Eucla": { + "+08:45": "Australian Central Western Standard Time" + }, + "America/Aruba": { + "-04:00": "Atlantic Standard Time" + }, + "Europe/Mariehamn": { + "+02:00": "Eastern European Standard Time", + "+03:00": "Eastern European Summer Time" + }, + "Asia/Baku": { + "+04:00": "Azerbaijan Standard Time" + }, + "Europe/Sarajevo": { + "+01:00": "Central European Standard Time", + "+02:00": "Central European Summer Time" + }, + "America/Barbados": { + "-04:00": "Atlantic Standard Time" + }, + "Asia/Dhaka": { + "+06:00": "Bangladesh Standard Time" + }, + "Europe/Brussels": { + "+01:00": "Central European Standard Time", + "+02:00": "Central European Summer Time" + }, + "Africa/Ouagadougou": { + "+00:00": "Greenwich Mean Time" + }, + "Europe/Sofia": { + "+02:00": "Eastern European Standard Time", + "+03:00": "Eastern European Summer Time" + }, + "Asia/Bahrain": { + "+03:00": "Arabian Standard Time" + }, + "Africa/Bujumbura": { + "+02:00": "Central Africa Time" + }, + "Africa/Porto-Novo": { + "+01:00": "West Africa Standard Time" + }, + "America/St_Barthelemy": { + "-04:00": "Atlantic Standard Time" + }, + "Atlantic/Bermuda": { + "-04:00": "Atlantic Standard Time", + "-03:00": "Atlantic Daylight Time" + }, + "Asia/Brunei": { + "+08:00": "Brunei Darussalam Time" + }, + "America/La_Paz": { + "-04:00": "Bolivia Time" + }, + "America/Kralendijk": { + "-04:00": "Atlantic Standard Time" + }, + "America/Noronha": { + "-02:00": "Fernando de Noronha Standard Time" + }, + "America/Belem": { + "-03:00": "Brasilia Standard Time" + }, + "America/Fortaleza": { + "-03:00": "Brasilia Standard Time" + }, + "America/Recife": { + "-03:00": "Brasilia Standard Time" + }, + "America/Araguaina": { + "-03:00": "Brasilia Standard Time" + }, + "America/Maceio": { + "-03:00": "Brasilia Standard Time" + }, + "America/Bahia": { + "-03:00": "Brasilia Standard Time" + }, + "America/Sao_Paulo": { + "-02:00": "Brasilia Summer Time", + "-03:00": "Brasilia Standard Time" + }, + "America/Campo_Grande": { + "-03:00": "Amazon Summer Time", + "-04:00": "Amazon Standard Time" + }, + "America/Cuiaba": { + "-03:00": "Amazon Summer Time", + "-04:00": "Amazon Standard Time" + }, + "America/Santarem": { + "-03:00": "Brasilia Standard Time" + }, + "America/Porto_Velho": { + "-04:00": "Amazon Standard Time" + }, + "America/Boa_Vista": { + "-04:00": "Amazon Standard Time" + }, + "America/Manaus": { + "-04:00": "Amazon Standard Time" + }, + "America/Eirunepe": { + "-05:00": "Acre Standard Time" + }, + "America/Rio_Branco": { + "-05:00": "Acre Standard Time" + }, + "America/Nassau": { + "-05:00": "Eastern Standard Time", + "-04:00": "Eastern Daylight Time" + }, + "Asia/Thimphu": { + "+06:00": "Bhutan Time" + }, + "Africa/Gaborone": { + "+02:00": "Central Africa Time" + }, + "Europe/Minsk": { + "+03:00": "Moscow Standard Time" + }, + "America/Belize": { + "-06:00": "Central Standard Time" + }, + "America/St_Johns": { + "-03:30": "Newfoundland Standard Time", + "-02:30": "Newfoundland Daylight Time" + }, + "America/Halifax": { + "-04:00": "Atlantic Standard Time", + "-03:00": "Atlantic Daylight Time" + }, + "America/Glace_Bay": { + "-04:00": "Atlantic Standard Time", + "-03:00": "Atlantic Daylight Time" + }, + "America/Moncton": { + "-04:00": "Atlantic Standard Time", + "-03:00": "Atlantic Daylight Time" + }, + "America/Goose_Bay": { + "-04:00": "Atlantic Standard Time", + "-03:00": "Atlantic Daylight Time" + }, + "America/Blanc-Sablon": { + "-04:00": "Atlantic Standard Time" + }, + "America/Toronto": { + "-05:00": "Eastern Standard Time", + "-04:00": "Eastern Daylight Time" + }, + "America/Nipigon": { + "-05:00": "Eastern Standard Time", + "-04:00": "Eastern Daylight Time" + }, + "America/Thunder_Bay": { + "-05:00": "Eastern Standard Time", + "-04:00": "Eastern Daylight Time" + }, + "America/Iqaluit": { + "-05:00": "Eastern Standard Time", + "-04:00": "Eastern Daylight Time" + }, + "America/Pangnirtung": { + "-05:00": "Eastern Standard Time", + "-04:00": "Eastern Daylight Time" + }, + "America/Atikokan": { + "-05:00": "Eastern Standard Time" + }, + "America/Winnipeg": { + "-06:00": "Central Standard Time", + "-05:00": "Central Daylight Time" + }, + "America/Rainy_River": { + "-06:00": "Central Standard Time", + "-05:00": "Central Daylight Time" + }, + "America/Resolute": { + "-06:00": "Central Standard Time", + "-05:00": "Central Daylight Time" + }, + "America/Rankin_Inlet": { + "-06:00": "Central Standard Time", + "-05:00": "Central Daylight Time" + }, + "America/Regina": { + "-06:00": "Central Standard Time" + }, + "America/Swift_Current": { + "-06:00": "Central Standard Time" + }, + "America/Edmonton": { + "-07:00": "Mountain Standard Time", + "-06:00": "Mountain Daylight Time" + }, + "America/Cambridge_Bay": { + "-07:00": "Mountain Standard Time", + "-06:00": "Mountain Daylight Time" + }, + "America/Yellowknife": { + "-07:00": "Mountain Standard Time", + "-06:00": "Mountain Daylight Time" + }, + "America/Inuvik": { + "-07:00": "Mountain Standard Time", + "-06:00": "Mountain Daylight Time" + }, + "America/Creston": { + "-07:00": "Mountain Standard Time" + }, + "America/Dawson_Creek": { + "-07:00": "Mountain Standard Time" + }, + "America/Fort_Nelson": { + "-07:00": "Mountain Standard Time" + }, + "America/Vancouver": { + "-08:00": "Pacific Standard Time", + "-07:00": "Pacific Daylight Time" + }, + "America/Whitehorse": { + "-08:00": "Pacific Standard Time", + "-07:00": "Pacific Daylight Time" + }, + "America/Dawson": { + "-08:00": "Pacific Standard Time", + "-07:00": "Pacific Daylight Time" + }, + "Indian/Cocos": { + "+06:30": "Cocos Islands Time" + }, + "Africa/Kinshasa": { + "+01:00": "West Africa Standard Time" + }, + "Africa/Lubumbashi": { + "+02:00": "Central Africa Time" + }, + "Africa/Bangui": { + "+01:00": "West Africa Standard Time" + }, + "Africa/Brazzaville": { + "+01:00": "West Africa Standard Time" + }, + "Europe/Zurich": { + "+01:00": "Central European Standard Time", + "+02:00": "Central European Summer Time" + }, + "Africa/Abidjan": { + "+00:00": "Greenwich Mean Time" + }, + "Pacific/Rarotonga": { + "-10:00": "Cook Islands Standard Time" + }, + "America/Santiago": { + "-03:00": "Chile Summer Time", + "-04:00": "Chile Standard Time" + }, + "America/Punta_Arenas": { + "-03:00": "GMT-03:00" + }, + "Pacific/Easter": { + "-05:00": "Easter Island Summer Time", + "-06:00": "Easter Island Standard Time" + }, + "Africa/Douala": { + "+01:00": "West Africa Standard Time" + }, + "Asia/Shanghai": { + "+08:00": "China Standard Time" + }, + "Asia/Urumqi": { + "+06:00": "GMT+06:00" + }, + "America/Bogota": { + "-05:00": "Colombia Standard Time" + }, + "America/Costa_Rica": { + "-06:00": "Central Standard Time" + }, + "America/Havana": { + "-05:00": "Cuba Standard Time", + "-04:00": "Cuba Daylight Time" + }, + "Atlantic/Cape_Verde": { + "-01:00": "Cape Verde Standard Time" + }, + "America/Curacao": { + "-04:00": "Atlantic Standard Time" + }, + "Indian/Christmas": { + "+07:00": "Christmas Island Time" + }, + "Asia/Nicosia": { + "+02:00": "Eastern European Standard Time", + "+03:00": "Eastern European Summer Time" + }, + "Asia/Famagusta": { + "+02:00": "GMT+02:00", + "+03:00": "GMT+03:00" + }, + "Europe/Prague": { + "+01:00": "Central European Standard Time", + "+02:00": "Central European Summer Time" + }, + "Europe/Berlin": { + "+01:00": "Central European Standard Time", + "+02:00": "Central European Summer Time" + }, + "Europe/Busingen": { + "+01:00": "Central European Standard Time", + "+02:00": "Central European Summer Time" + }, + "Africa/Djibouti": { + "+03:00": "East Africa Time" + }, + "Europe/Copenhagen": { + "+01:00": "Central European Standard Time", + "+02:00": "Central European Summer Time" + }, + "America/Dominica": { + "-04:00": "Atlantic Standard Time" + }, + "America/Santo_Domingo": { + "-04:00": "Atlantic Standard Time" + }, + "Africa/Algiers": { + "+01:00": "Central European Standard Time" + }, + "America/Guayaquil": { + "-05:00": "Ecuador Time" + }, + "Pacific/Galapagos": { + "-06:00": "Galapagos Time" + }, + "Europe/Tallinn": { + "+02:00": "Eastern European Standard Time", + "+03:00": "Eastern European Summer Time" + }, + "Africa/Cairo": { + "+02:00": "Eastern European Standard Time" + }, + "Africa/El_Aaiun": { + "+00:00": "Western European Standard Time", + "+01:00": "Western European Summer Time" + }, + "Africa/Asmara": { + "+03:00": "East Africa Time" + }, + "Europe/Madrid": { + "+01:00": "Central European Standard Time", + "+02:00": "Central European Summer Time" + }, + "Africa/Ceuta": { + "+01:00": "Central European Standard Time", + "+02:00": "Central European Summer Time" + }, + "Atlantic/Canary": { + "+00:00": "Western European Standard Time", + "+01:00": "Western European Summer Time" + }, + "Africa/Addis_Ababa": { + "+03:00": "East Africa Time" + }, + "Europe/Helsinki": { + "+02:00": "Eastern European Standard Time", + "+03:00": "Eastern European Summer Time" + }, + "Pacific/Fiji": { + "+13:00": "Fiji Summer Time", + "+12:00": "Fiji Standard Time" + }, + "Atlantic/Stanley": { + "-03:00": "Falkland Islands Standard Time" + }, + "Pacific/Chuuk": { + "+10:00": "Chuuk Time" + }, + "Pacific/Pohnpei": { + "+11:00": "Ponape Time" + }, + "Pacific/Kosrae": { + "+11:00": "Kosrae Time" + }, + "Atlantic/Faroe": { + "+00:00": "Western European Standard Time", + "+01:00": "Western European Summer Time" + }, + "Europe/Paris": { + "+01:00": "Central European Standard Time", + "+02:00": "Central European Summer Time" + }, + "Africa/Libreville": { + "+01:00": "West Africa Standard Time" + }, + "Europe/London": { + "+00:00": "Greenwich Mean Time", + "+01:00": "British Summer Time" + }, + "America/Grenada": { + "-04:00": "Atlantic Standard Time" + }, + "Asia/Tbilisi": { + "+04:00": "Georgia Standard Time" + }, + "America/Cayenne": { + "-03:00": "French Guiana Time" + }, + "Europe/Guernsey": { + "+00:00": "Greenwich Mean Time", + "+01:00": "GMT+01:00" + }, + "Africa/Accra": { + "+00:00": "Greenwich Mean Time" + }, + "Europe/Gibraltar": { + "+01:00": "Central European Standard Time", + "+02:00": "Central European Summer Time" + }, + "America/Godthab": { + "-03:00": "West Greenland Standard Time", + "-02:00": "West Greenland Summer Time" + }, + "America/Danmarkshavn": { + "+00:00": "Greenwich Mean Time" + }, + "America/Scoresbysund": { + "-01:00": "East Greenland Standard Time", + "+00:00": "East Greenland Summer Time" + }, + "America/Thule": { + "-04:00": "Atlantic Standard Time", + "-03:00": "Atlantic Daylight Time" + }, + "Africa/Banjul": { + "+00:00": "Greenwich Mean Time" + }, + "Africa/Conakry": { + "+00:00": "Greenwich Mean Time" + }, + "America/Guadeloupe": { + "-04:00": "Atlantic Standard Time" + }, + "Africa/Malabo": { + "+01:00": "West Africa Standard Time" + }, + "Europe/Athens": { + "+02:00": "Eastern European Standard Time", + "+03:00": "Eastern European Summer Time" + }, + "Atlantic/South_Georgia": { + "-02:00": "South Georgia Time" + }, + "America/Guatemala": { + "-06:00": "Central Standard Time" + }, + "Pacific/Guam": { + "+10:00": "Chamorro Standard Time" + }, + "Africa/Bissau": { + "+00:00": "Greenwich Mean Time" + }, + "America/Guyana": { + "-04:00": "Guyana Time" + }, + "Asia/Hong_Kong": { + "+08:00": "Hong Kong Standard Time" + }, + "America/Tegucigalpa": { + "-06:00": "Central Standard Time" + }, + "Europe/Zagreb": { + "+01:00": "Central European Standard Time", + "+02:00": "Central European Summer Time" + }, + "America/Port-au-Prince": { + "-05:00": "Eastern Standard Time", + "-04:00": "Eastern Daylight Time" + }, + "Europe/Budapest": { + "+01:00": "Central European Standard Time", + "+02:00": "Central European Summer Time" + }, + "Asia/Jakarta": { + "+07:00": "Western Indonesia Time" + }, + "Asia/Pontianak": { + "+07:00": "Western Indonesia Time" + }, + "Asia/Makassar": { + "+08:00": "Central Indonesia Time" + }, + "Asia/Jayapura": { + "+09:00": "Eastern Indonesia Time" + }, + "Europe/Dublin": { + "+00:00": "Greenwich Mean Time", + "+01:00": "Irish Standard Time" + }, + "Asia/Jerusalem": { + "+02:00": "Israel Standard Time", + "+03:00": "Israel Daylight Time" + }, + "Europe/Isle_of_Man": { + "+00:00": "Greenwich Mean Time", + "+01:00": "GMT+01:00" + }, + "Asia/Kolkata": { + "+05:30": "India Standard Time" + }, + "Indian/Chagos": { + "+06:00": "Indian Ocean Time" + }, + "Asia/Baghdad": { + "+03:00": "Arabian Standard Time" + }, + "Asia/Tehran": { + "+03:30": "Iran Standard Time", + "+04:30": "Iran Daylight Time" + }, + "Atlantic/Reykjavik": { + "+00:00": "Greenwich Mean Time" + }, + "Europe/Rome": { + "+01:00": "Central European Standard Time", + "+02:00": "Central European Summer Time" + }, + "Europe/Jersey": { + "+00:00": "Greenwich Mean Time", + "+01:00": "GMT+01:00" + }, + "America/Jamaica": { + "-05:00": "Eastern Standard Time" + }, + "Asia/Amman": { + "+02:00": "Eastern European Standard Time", + "+03:00": "Eastern European Summer Time" + }, + "Asia/Tokyo": { + "+09:00": "Japan Standard Time" + }, + "Africa/Nairobi": { + "+03:00": "East Africa Time" + }, + "Asia/Bishkek": { + "+06:00": "Kyrgyzstan Time" + }, + "Asia/Phnom_Penh": { + "+07:00": "Indochina Time" + }, + "Pacific/Tarawa": { + "+12:00": "Gilbert Islands Time" + }, + "Pacific/Enderbury": { + "+13:00": "Phoenix Islands Time" + }, + "Pacific/Kiritimati": { + "+14:00": "Line Islands Time" + }, + "Indian/Comoro": { + "+03:00": "East Africa Time" + }, + "America/St_Kitts": { + "-04:00": "Atlantic Standard Time" + }, + "Asia/Pyongyang": { + "+08:30": "Pyongyang Time" + }, + "Asia/Seoul": { + "+09:00": "Korean Standard Time" + }, + "Asia/Kuwait": { + "+03:00": "Arabian Standard Time" + }, + "America/Cayman": { + "-05:00": "Eastern Standard Time" + }, + "Asia/Almaty": { + "+06:00": "East Kazakhstan Time" + }, + "Asia/Qyzylorda": { + "+06:00": "East Kazakhstan Time" + }, + "Asia/Aqtobe": { + "+05:00": "West Kazakhstan Time" + }, + "Asia/Aqtau": { + "+05:00": "West Kazakhstan Time" + }, + "Asia/Atyrau": { + "+05:00": "West Kazakhstan Time" + }, + "Asia/Oral": { + "+05:00": "West Kazakhstan Time" + }, + "Asia/Vientiane": { + "+07:00": "Indochina Time" + }, + "Asia/Beirut": { + "+02:00": "Eastern European Standard Time", + "+03:00": "Eastern European Summer Time" + }, + "America/St_Lucia": { + "-04:00": "Atlantic Standard Time" + }, + "Europe/Vaduz": { + "+01:00": "Central European Standard Time", + "+02:00": "Central European Summer Time" + }, + "Asia/Colombo": { + "+05:30": "India Standard Time" + }, + "Africa/Monrovia": { + "+00:00": "Greenwich Mean Time" + }, + "Africa/Maseru": { + "+02:00": "South Africa Standard Time" + }, + "Europe/Vilnius": { + "+02:00": "Eastern European Standard Time", + "+03:00": "Eastern European Summer Time" + }, + "Europe/Luxembourg": { + "+01:00": "Central European Standard Time", + "+02:00": "Central European Summer Time" + }, + "Europe/Riga": { + "+02:00": "Eastern European Standard Time", + "+03:00": "Eastern European Summer Time" + }, + "Africa/Tripoli": { + "+02:00": "Eastern European Standard Time" + }, + "Africa/Casablanca": { + "+00:00": "Western European Standard Time", + "+01:00": "Western European Summer Time" + }, + "Europe/Monaco": { + "+01:00": "Central European Standard Time", + "+02:00": "Central European Summer Time" + }, + "Europe/Chisinau": { + "+02:00": "Eastern European Standard Time", + "+03:00": "Eastern European Summer Time" + }, + "Europe/Podgorica": { + "+01:00": "Central European Standard Time", + "+02:00": "Central European Summer Time" + }, + "America/Marigot": { + "-04:00": "Atlantic Standard Time" + }, + "Indian/Antananarivo": { + "+03:00": "East Africa Time" + }, + "Pacific/Majuro": { + "+12:00": "Marshall Islands Time" + }, + "Pacific/Kwajalein": { + "+12:00": "Marshall Islands Time" + }, + "Europe/Skopje": { + "+01:00": "Central European Standard Time", + "+02:00": "Central European Summer Time" + }, + "Africa/Bamako": { + "+00:00": "Greenwich Mean Time" + }, + "Asia/Yangon": { + "+06:30": "Myanmar Time" + }, + "Asia/Ulaanbaatar": { + "+08:00": "Ulaanbaatar Standard Time" + }, + "Asia/Hovd": { + "+07:00": "Hovd Standard Time" + }, + "Asia/Choibalsan": { + "+08:00": "Choibalsan Standard Time" + }, + "Asia/Macau": { + "+08:00": "China Standard Time" + }, + "Pacific/Saipan": { + "+10:00": "Chamorro Standard Time" + }, + "America/Martinique": { + "-04:00": "Atlantic Standard Time" + }, + "Africa/Nouakchott": { + "+00:00": "Greenwich Mean Time" + }, + "America/Montserrat": { + "-04:00": "Atlantic Standard Time" + }, + "Europe/Malta": { + "+01:00": "Central European Standard Time", + "+02:00": "Central European Summer Time" + }, + "Indian/Mauritius": { + "+04:00": "Mauritius Standard Time" + }, + "Indian/Maldives": { + "+05:00": "Maldives Time" + }, + "Africa/Blantyre": { + "+02:00": "Central Africa Time" + }, + "America/Mexico_City": { + "-06:00": "Central Standard Time", + "-05:00": "Central Daylight Time" + }, + "America/Cancun": { + "-05:00": "Eastern Standard Time" + }, + "America/Merida": { + "-06:00": "Central Standard Time", + "-05:00": "Central Daylight Time" + }, + "America/Monterrey": { + "-06:00": "Central Standard Time", + "-05:00": "Central Daylight Time" + }, + "America/Matamoros": { + "-06:00": "Central Standard Time", + "-05:00": "Central Daylight Time" + }, + "America/Mazatlan": { + "-07:00": "Mexican Pacific Standard Time", + "-06:00": "Mexican Pacific Daylight Time" + }, + "America/Chihuahua": { + "-07:00": "Mexican Pacific Standard Time", + "-06:00": "Mexican Pacific Daylight Time" + }, + "America/Ojinaga": { + "-07:00": "Mountain Standard Time", + "-06:00": "Mountain Daylight Time" + }, + "America/Hermosillo": { + "-07:00": "Mexican Pacific Standard Time" + }, + "America/Tijuana": { + "-08:00": "Pacific Standard Time", + "-07:00": "Pacific Daylight Time" + }, + "America/Bahia_Banderas": { + "-06:00": "Central Standard Time", + "-05:00": "Central Daylight Time" + }, + "Asia/Kuala_Lumpur": { + "+08:00": "Malaysia Time" + }, + "Asia/Kuching": { + "+08:00": "Malaysia Time" + }, + "Africa/Maputo": { + "+02:00": "Central Africa Time" + }, + "Africa/Windhoek": { + "+02:00": "Central Africa Time" + }, + "Pacific/Noumea": { + "+11:00": "New Caledonia Standard Time" + }, + "Africa/Niamey": { + "+01:00": "West Africa Standard Time" + }, + "Pacific/Norfolk": { + "+11:00": "Norfolk Island Time" + }, + "Africa/Lagos": { + "+01:00": "West Africa Standard Time" + }, + "America/Managua": { + "-06:00": "Central Standard Time" + }, + "Europe/Amsterdam": { + "+01:00": "Central European Standard Time", + "+02:00": "Central European Summer Time" + }, + "Europe/Oslo": { + "+01:00": "Central European Standard Time", + "+02:00": "Central European Summer Time" + }, + "Asia/Kathmandu": { + "+05:45": "Nepal Time" + }, + "Pacific/Nauru": { + "+12:00": "Nauru Time" + }, + "Pacific/Niue": { + "-11:00": "Niue Time" + }, + "Pacific/Auckland": { + "+13:00": "New Zealand Daylight Time", + "+12:00": "New Zealand Standard Time" + }, + "Pacific/Chatham": { + "+13:45": "Chatham Daylight Time", + "+12:45": "Chatham Standard Time" + }, + "Asia/Muscat": { + "+04:00": "Gulf Standard Time" + }, + "America/Panama": { + "-05:00": "Eastern Standard Time" + }, + "America/Lima": { + "-05:00": "Peru Standard Time" + }, + "Pacific/Tahiti": { + "-10:00": "Tahiti Time" + }, + "Pacific/Marquesas": { + "-09:30": "Marquesas Time" + }, + "Pacific/Gambier": { + "-09:00": "Gambier Time" + }, + "Pacific/Port_Moresby": { + "+10:00": "Papua New Guinea Time" + }, + "Pacific/Bougainville": { + "+11:00": "GMT+11:00" + }, + "Asia/Manila": { + "+08:00": "Philippine Standard Time" + }, + "Asia/Karachi": { + "+05:00": "Pakistan Standard Time" + }, + "Europe/Warsaw": { + "+01:00": "Central European Standard Time", + "+02:00": "Central European Summer Time" + }, + "America/Miquelon": { + "-03:00": "St. Pierre & Miquelon Standard Time", + "-02:00": "St. Pierre & Miquelon Daylight Time" + }, + "Pacific/Pitcairn": { + "-08:00": "Pitcairn Time" + }, + "America/Puerto_Rico": { + "-04:00": "Atlantic Standard Time" + }, + "Asia/Gaza": { + "+02:00": "Eastern European Standard Time", + "+03:00": "Eastern European Summer Time" + }, + "Asia/Hebron": { + "+02:00": "Eastern European Standard Time", + "+03:00": "Eastern European Summer Time" + }, + "Europe/Lisbon": { + "+00:00": "Western European Standard Time", + "+01:00": "Western European Summer Time" + }, + "Atlantic/Madeira": { + "+00:00": "Western European Standard Time", + "+01:00": "Western European Summer Time" + }, + "Atlantic/Azores": { + "-01:00": "Azores Standard Time", + "+00:00": "Azores Summer Time" + }, + "Pacific/Palau": { + "+09:00": "Palau Time" + }, + "America/Asuncion": { + "-03:00": "Paraguay Summer Time", + "-04:00": "Paraguay Standard Time" + }, + "Asia/Qatar": { + "+03:00": "Arabian Standard Time" + }, + "Indian/Reunion": { + "+04:00": "RĂ©union Time" + }, + "Europe/Bucharest": { + "+02:00": "Eastern European Standard Time", + "+03:00": "Eastern European Summer Time" + }, + "Europe/Belgrade": { + "+01:00": "Central European Standard Time", + "+02:00": "Central European Summer Time" + }, + "Europe/Kaliningrad": { + "+02:00": "Eastern European Standard Time" + }, + "Europe/Moscow": { + "+03:00": "Moscow Standard Time" + }, + "Europe/Simferopol": { + "+03:00": "Moscow Standard Time" + }, + "Europe/Volgograd": { + "+03:00": "Moscow Standard Time" + }, + "Europe/Kirov": { + "+03:00": "GMT+03:00" + }, + "Europe/Astrakhan": { + "+04:00": "GMT+04:00" + }, + "Europe/Saratov": { + "+04:00": "GMT+04:00" + }, + "Europe/Ulyanovsk": { + "+04:00": "GMT+04:00" + }, + "Europe/Samara": { + "+04:00": "Samara Standard Time" + }, + "Asia/Yekaterinburg": { + "+05:00": "Yekaterinburg Standard Time" + }, + "Asia/Omsk": { + "+06:00": "Omsk Standard Time" + }, + "Asia/Novosibirsk": { + "+07:00": "Novosibirsk Standard Time" + }, + "Asia/Barnaul": { + "+07:00": "GMT+07:00" + }, + "Asia/Tomsk": { + "+07:00": "GMT+07:00" + }, + "Asia/Novokuznetsk": { + "+07:00": "Krasnoyarsk Standard Time" + }, + "Asia/Krasnoyarsk": { + "+07:00": "Krasnoyarsk Standard Time" + }, + "Asia/Irkutsk": { + "+08:00": "Irkutsk Standard Time" + }, + "Asia/Chita": { + "+09:00": "Yakutsk Standard Time" + }, + "Asia/Yakutsk": { + "+09:00": "Yakutsk Standard Time" + }, + "Asia/Khandyga": { + "+09:00": "Yakutsk Standard Time" + }, + "Asia/Vladivostok": { + "+10:00": "Vladivostok Standard Time" + }, + "Asia/Ust-Nera": { + "+10:00": "Vladivostok Standard Time" + }, + "Asia/Magadan": { + "+11:00": "Magadan Standard Time" + }, + "Asia/Sakhalin": { + "+11:00": "Sakhalin Standard Time" + }, + "Asia/Srednekolymsk": { + "+11:00": "GMT+11:00" + }, + "Asia/Kamchatka": { + "+12:00": "Petropavlovsk-Kamchatski Standard Time" + }, + "Asia/Anadyr": { + "+12:00": "Anadyr Standard Time" + }, + "Africa/Kigali": { + "+02:00": "Central Africa Time" + }, + "Asia/Riyadh": { + "+03:00": "Arabian Standard Time" + }, + "Pacific/Guadalcanal": { + "+11:00": "Solomon Islands Time" + }, + "Indian/Mahe": { + "+04:00": "Seychelles Time" + }, + "Africa/Khartoum": { + "+02:00": "Central Africa Time" + }, + "Europe/Stockholm": { + "+01:00": "Central European Standard Time", + "+02:00": "Central European Summer Time" + }, + "Asia/Singapore": { + "+08:00": "Singapore Standard Time" + }, + "Atlantic/St_Helena": { + "+00:00": "Greenwich Mean Time" + }, + "Europe/Ljubljana": { + "+01:00": "Central European Standard Time", + "+02:00": "Central European Summer Time" + }, + "Arctic/Longyearbyen": { + "+01:00": "Central European Standard Time", + "+02:00": "Central European Summer Time" + }, + "Europe/Bratislava": { + "+01:00": "Central European Standard Time", + "+02:00": "Central European Summer Time" + }, + "Africa/Freetown": { + "+00:00": "Greenwich Mean Time" + }, + "Europe/San_Marino": { + "+01:00": "Central European Standard Time", + "+02:00": "Central European Summer Time" + }, + "Africa/Dakar": { + "+00:00": "Greenwich Mean Time" + }, + "Africa/Mogadishu": { + "+03:00": "East Africa Time" + }, + "America/Paramaribo": { + "-03:00": "Suriname Time" + }, + "Africa/Juba": { + "+03:00": "East Africa Time" + }, + "Africa/Sao_Tome": { + "+00:00": "Greenwich Mean Time", + "+01:00": "West Africa Standard Time" + }, + "America/El_Salvador": { + "-06:00": "Central Standard Time" + }, + "America/Lower_Princes": { + "-04:00": "Atlantic Standard Time" + }, + "Asia/Damascus": { + "+02:00": "Eastern European Standard Time", + "+03:00": "Eastern European Summer Time" + }, + "Africa/Mbabane": { + "+02:00": "South Africa Standard Time" + }, + "America/Grand_Turk": { + "-04:00": "Eastern Daylight Time", + "-05:00": "Eastern Standard Time" + }, + "Africa/Ndjamena": { + "+01:00": "West Africa Standard Time" + }, + "Indian/Kerguelen": { + "+05:00": "French Southern & Antarctic Time" + }, + "Africa/Lome": { + "+00:00": "Greenwich Mean Time" + }, + "Asia/Bangkok": { + "+07:00": "Indochina Time" + }, + "Asia/Dushanbe": { + "+05:00": "Tajikistan Time" + }, + "Pacific/Fakaofo": { + "+13:00": "Tokelau Time" + }, + "Asia/Dili": { + "+09:00": "East Timor Time" + }, + "Asia/Ashgabat": { + "+05:00": "Turkmenistan Standard Time" + }, + "Africa/Tunis": { + "+01:00": "Central European Standard Time" + }, + "Pacific/Tongatapu": { + "+13:00": "Tonga Standard Time" + }, + "Europe/Istanbul": { + "+03:00": "GMT+03:00" + }, + "America/Port_of_Spain": { + "-04:00": "Atlantic Standard Time" + }, + "Pacific/Funafuti": { + "+12:00": "Tuvalu Time" + }, + "Asia/Taipei": { + "+08:00": "Taipei Standard Time" + }, + "Africa/Dar_es_Salaam": { + "+03:00": "East Africa Time" + }, + "Europe/Kiev": { + "+02:00": "Eastern European Standard Time", + "+03:00": "Eastern European Summer Time" + }, + "Europe/Uzhgorod": { + "+02:00": "Eastern European Standard Time", + "+03:00": "Eastern European Summer Time" + }, + "Europe/Zaporozhye": { + "+02:00": "Eastern European Standard Time", + "+03:00": "Eastern European Summer Time" + }, + "Africa/Kampala": { + "+03:00": "East Africa Time" + }, + "Pacific/Midway": { + "-11:00": "Samoa Standard Time" + }, + "Pacific/Wake": { + "+12:00": "Wake Island Time" + }, + "America/New_York": { + "-05:00": "Eastern Standard Time", + "-04:00": "Eastern Daylight Time" + }, + "America/Detroit": { + "-05:00": "Eastern Standard Time", + "-04:00": "Eastern Daylight Time" + }, + "America/Kentucky/Louisville": { + "-05:00": "Eastern Standard Time", + "-04:00": "Eastern Daylight Time" + }, + "America/Kentucky/Monticello": { + "-05:00": "Eastern Standard Time", + "-04:00": "Eastern Daylight Time" + }, + "America/Indiana/Indianapolis": { + "-05:00": "Eastern Standard Time", + "-04:00": "Eastern Daylight Time" + }, + "America/Indiana/Vincennes": { + "-05:00": "Eastern Standard Time", + "-04:00": "Eastern Daylight Time" + }, + "America/Indiana/Winamac": { + "-05:00": "Eastern Standard Time", + "-04:00": "Eastern Daylight Time" + }, + "America/Indiana/Marengo": { + "-05:00": "Eastern Standard Time", + "-04:00": "Eastern Daylight Time" + }, + "America/Indiana/Petersburg": { + "-05:00": "Eastern Standard Time", + "-04:00": "Eastern Daylight Time" + }, + "America/Indiana/Vevay": { + "-05:00": "Eastern Standard Time", + "-04:00": "Eastern Daylight Time" + }, + "America/Chicago": { + "-06:00": "Central Standard Time", + "-05:00": "Central Daylight Time" + }, + "America/Indiana/Tell_City": { + "-06:00": "Central Standard Time", + "-05:00": "Central Daylight Time" + }, + "America/Indiana/Knox": { + "-06:00": "Central Standard Time", + "-05:00": "Central Daylight Time" + }, + "America/Menominee": { + "-06:00": "Central Standard Time", + "-05:00": "Central Daylight Time" + }, + "America/North_Dakota/Center": { + "-06:00": "Central Standard Time", + "-05:00": "Central Daylight Time" + }, + "America/North_Dakota/New_Salem": { + "-06:00": "Central Standard Time", + "-05:00": "Central Daylight Time" + }, + "America/North_Dakota/Beulah": { + "-06:00": "Central Standard Time", + "-05:00": "Central Daylight Time" + }, + "America/Denver": { + "-07:00": "Mountain Standard Time", + "-06:00": "Mountain Daylight Time" + }, + "America/Boise": { + "-07:00": "Mountain Standard Time", + "-06:00": "Mountain Daylight Time" + }, + "America/Phoenix": { + "-07:00": "Mountain Standard Time" + }, + "America/Los_Angeles": { + "-08:00": "Pacific Standard Time", + "-07:00": "Pacific Daylight Time" + }, + "America/Anchorage": { + "-09:00": "Alaska Standard Time", + "-08:00": "Alaska Daylight Time" + }, + "America/Juneau": { + "-09:00": "Alaska Standard Time", + "-08:00": "Alaska Daylight Time" + }, + "America/Sitka": { + "-09:00": "Alaska Standard Time", + "-08:00": "Alaska Daylight Time" + }, + "America/Metlakatla": { + "-09:00": "Alaska Standard Time", + "-08:00": "Alaska Daylight Time" + }, + "America/Yakutat": { + "-09:00": "Alaska Standard Time", + "-08:00": "Alaska Daylight Time" + }, + "America/Nome": { + "-09:00": "Alaska Standard Time", + "-08:00": "Alaska Daylight Time" + }, + "America/Adak": { + "-10:00": "Hawaii-Aleutian Standard Time", + "-09:00": "Hawaii-Aleutian Daylight Time" + }, + "Pacific/Honolulu": { + "-10:00": "Hawaii-Aleutian Standard Time" + }, + "America/Montevideo": { + "-03:00": "Uruguay Standard Time" + }, + "Asia/Samarkand": { + "+05:00": "Uzbekistan Standard Time" + }, + "Asia/Tashkent": { + "+05:00": "Uzbekistan Standard Time" + }, + "Europe/Vatican": { + "+01:00": "Central European Standard Time", + "+02:00": "Central European Summer Time" + }, + "America/St_Vincent": { + "-04:00": "Atlantic Standard Time" + }, + "America/Caracas": { + "-04:00": "Venezuela Time" + }, + "America/Tortola": { + "-04:00": "Atlantic Standard Time" + }, + "America/St_Thomas": { + "-04:00": "Atlantic Standard Time" + }, + "Asia/Ho_Chi_Minh": { + "+07:00": "Indochina Time" + }, + "Pacific/Efate": { + "+11:00": "Vanuatu Standard Time" + }, + "Pacific/Wallis": { + "+12:00": "Wallis & Futuna Time" + }, + "Pacific/Apia": { + "+14:00": "Apia Daylight Time", + "+13:00": "Apia Standard Time" + }, + "Asia/Aden": { + "+03:00": "Arabian Standard Time" + }, + "Indian/Mayotte": { + "+03:00": "East Africa Time" + }, + "Africa/Johannesburg": { + "+02:00": "South Africa Standard Time" + }, + "Africa/Lusaka": { + "+02:00": "Central Africa Time" + }, + "Africa/Harare": { + "+02:00": "Central Africa Time" + }, + "UTC": { + "+00:00": "Coordinated Universal Time" + }, + "GMT": { + "+00:00": "Coordinated Universal Time" + } +}; diff --git a/polyfill/package-lock.json b/polyfill/package-lock.json new file mode 100644 index 0000000000..459fb0d801 --- /dev/null +++ b/polyfill/package-lock.json @@ -0,0 +1,387 @@ +{ + "name": "temporal", + "version": "1.0.0", + "lockfileVersion": 1, + "requires": true, + "dependencies": { + "@types/estree": { + "version": "0.0.39", + "resolved": "https://registry.npmjs.org/@types/estree/-/estree-0.0.39.tgz", + "integrity": "sha512-EYNwp3bU+98cpU4lAWYYL7Zz+2gryWH1qbdDTidVd6hkiR6weksdbMadyXKXNPEkQFhXM+hVO9ZygomHXp+AIw==", + "dev": true + }, + "@types/node": { + "version": "10.1.3", + "resolved": "https://registry.npmjs.org/@types/node/-/node-10.1.3.tgz", + "integrity": "sha512-GiCx7dRvta0hbxXoJFAUxz+CKX6bZSCKjM5slq2vPp/5zwK01T4ibYZkGr6EN4F2QmxDQR76/ZHg6q+7iFWCWw==", + "dev": true + }, + "balanced-match": { + "version": "1.0.0", + "resolved": "http://artprod.dev.bloomberg.com/artifactory/api/npm/npm-repos/balanced-match/-/balanced-match-1.0.0.tgz?dl=https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz", + "integrity": "sha1-ibTRmasr7kneFk6gK4nORi1xt2c=", + "dev": true + }, + "brace-expansion": { + "version": "1.1.11", + "resolved": "http://artprod.dev.bloomberg.com/artifactory/api/npm/npm-repos/brace-expansion/-/brace-expansion-1.1.11.tgz?dl=https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", + "integrity": "sha1-PH/L9SnYcibz0vUrlm/1Jx60Qd0=", + "dev": true, + "requires": { + "balanced-match": "^1.0.0", + "concat-map": "0.0.1" + } + }, + "builtin-modules": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/builtin-modules/-/builtin-modules-2.0.0.tgz", + "integrity": "sha512-3U5kUA5VPsRUA3nofm/BXX7GVHKfxz0hOBAPxXrIvHzlDRkQVqEn6yi8QJegxl4LzOHLdvb7XF5dVawa/VVYBg==", + "dev": true + }, + "commenting": { + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/commenting/-/commenting-1.0.5.tgz", + "integrity": "sha512-U7qGbcDLSNpOcV3RQRKHp7hFpy9WUmfawbkPdS4R2RhrSu4dOF85QQpx/Zjcv7uLF6tWSUKEKUIkxknPCrVjwg==", + "dev": true + }, + "concat-map": { + "version": "0.0.1", + "resolved": "http://artprod.dev.bloomberg.com/artifactory/api/npm/npm-repos/concat-map/-/concat-map-0.0.1.tgz?dl=https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", + "integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=", + "dev": true + }, + "deep-equal": { + "version": "1.0.1", + "resolved": "http://artprod.dev.bloomberg.com/artifactory/api/npm/npm-repos/deep-equal/-/deep-equal-1.0.1.tgz?dl=https://registry.npmjs.org/deep-equal/-/deep-equal-1.0.1.tgz", + "integrity": "sha1-9dJgKStmDghO/0zbyfCK0yR0SLU=", + "dev": true + }, + "define-properties": { + "version": "1.1.2", + "resolved": "http://artprod.dev.bloomberg.com/artifactory/api/npm/npm-repos/define-properties/-/define-properties-1.1.2.tgz?dl=https://registry.npmjs.org/define-properties/-/define-properties-1.1.2.tgz", + "integrity": "sha1-g6c/L+pWmJj7c3GTyPhzyvbUXJQ=", + "dev": true, + "requires": { + "foreach": "^2.0.5", + "object-keys": "^1.0.8" + } + }, + "defined": { + "version": "1.0.0", + "resolved": "http://artprod.dev.bloomberg.com/artifactory/api/npm/npm-repos/defined/-/defined-1.0.0.tgz?dl=https://registry.npmjs.org/defined/-/defined-1.0.0.tgz", + "integrity": "sha1-yY2bzvdWdBiOEQlpFRGZ45sfppM=", + "dev": true + }, + "es-abstract": { + "version": "1.12.0", + "resolved": "http://artprod.dev.bloomberg.com/artifactory/api/npm/npm-repos/es-abstract/-/es-abstract-1.12.0.tgz?dl=https://registry.npmjs.org/es-abstract/-/es-abstract-1.12.0.tgz", + "integrity": "sha1-nbvdJ8aFbwABQhyhh4LXhr+KYWU=", + "dev": true, + "requires": { + "es-to-primitive": "^1.1.1", + "function-bind": "^1.1.1", + "has": "^1.0.1", + "is-callable": "^1.1.3", + "is-regex": "^1.0.4" + } + }, + "es-to-primitive": { + "version": "1.1.1", + "resolved": "http://artprod.dev.bloomberg.com/artifactory/api/npm/npm-repos/es-to-primitive/-/es-to-primitive-1.1.1.tgz?dl=https://registry.npmjs.org/es-to-primitive/-/es-to-primitive-1.1.1.tgz", + "integrity": "sha1-RTVSSKiJeQNLZ5Lhm7gfK3l13Q0=", + "dev": true, + "requires": { + "is-callable": "^1.1.1", + "is-date-object": "^1.0.1", + "is-symbol": "^1.0.1" + } + }, + "for-each": { + "version": "0.3.3", + "resolved": "http://artprod.dev.bloomberg.com/artifactory/api/npm/npm-repos/for-each/-/for-each-0.3.3.tgz?dl=https://registry.npmjs.org/for-each/-/for-each-0.3.3.tgz", + "integrity": "sha1-abRH6IoKXTLD5whPPxcQA0shN24=", + "dev": true, + "requires": { + "is-callable": "^1.1.3" + } + }, + "foreach": { + "version": "2.0.5", + "resolved": "http://artprod.dev.bloomberg.com/artifactory/api/npm/npm-repos/foreach/-/foreach-2.0.5.tgz?dl=https://registry.npmjs.org/foreach/-/foreach-2.0.5.tgz", + "integrity": "sha1-C+4AUBiusmDQo6865ljdATbsG5k=", + "dev": true + }, + "fs.realpath": { + "version": "1.0.0", + "resolved": "http://artprod.dev.bloomberg.com/artifactory/api/npm/npm-repos/fs.realpath/-/fs.realpath-1.0.0.tgz?dl=https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", + "integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8=", + "dev": true + }, + "function-bind": { + "version": "1.1.1", + "resolved": "http://artprod.dev.bloomberg.com/artifactory/api/npm/npm-repos/function-bind/-/function-bind-1.1.1.tgz?dl=https://registry.npmjs.org/function-bind/-/function-bind-1.1.1.tgz", + "integrity": "sha1-pWiZ0+o8m6uHS7l3O3xe3pL0iV0=", + "dev": true + }, + "glob": { + "version": "7.1.2", + "resolved": "http://artprod.dev.bloomberg.com/artifactory/api/npm/npm-repos/glob/-/glob-7.1.2.tgz?dl=https://registry.npmjs.org/glob/-/glob-7.1.2.tgz", + "integrity": "sha1-wZyd+aAocC1nhhI4SmVSQExjbRU=", + "dev": true, + "requires": { + "fs.realpath": "^1.0.0", + "inflight": "^1.0.4", + "inherits": "2", + "minimatch": "^3.0.4", + "once": "^1.3.0", + "path-is-absolute": "^1.0.0" + } + }, + "has": { + "version": "1.0.3", + "resolved": "http://artprod.dev.bloomberg.com/artifactory/api/npm/npm-repos/has/-/has-1.0.3.tgz?dl=https://registry.npmjs.org/has/-/has-1.0.3.tgz", + "integrity": "sha1-ci18v8H2qoJB8W3YFOAR4fQeh5Y=", + "dev": true, + "requires": { + "function-bind": "^1.1.1" + } + }, + "inflight": { + "version": "1.0.6", + "resolved": "http://artprod.dev.bloomberg.com/artifactory/api/npm/npm-repos/inflight/-/inflight-1.0.6.tgz?dl=https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz", + "integrity": "sha1-Sb1jMdfQLQwJvJEKEHW6gWW1bfk=", + "dev": true, + "requires": { + "once": "^1.3.0", + "wrappy": "1" + } + }, + "inherits": { + "version": "2.0.3", + "resolved": "http://artprod.dev.bloomberg.com/artifactory/api/npm/npm-repos/inherits/-/inherits-2.0.3.tgz?dl=https://registry.npmjs.org/inherits/-/inherits-2.0.3.tgz", + "integrity": "sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4=", + "dev": true + }, + "is-callable": { + "version": "1.1.4", + "resolved": "http://artprod.dev.bloomberg.com/artifactory/api/npm/npm-repos/is-callable/-/is-callable-1.1.4.tgz?dl=https://registry.npmjs.org/is-callable/-/is-callable-1.1.4.tgz", + "integrity": "sha1-HhrfIZ4e62hNaR+dagX/DTCiTXU=", + "dev": true + }, + "is-date-object": { + "version": "1.0.1", + "resolved": "http://artprod.dev.bloomberg.com/artifactory/api/npm/npm-repos/is-date-object/-/is-date-object-1.0.1.tgz?dl=https://registry.npmjs.org/is-date-object/-/is-date-object-1.0.1.tgz", + "integrity": "sha1-mqIOtq7rv/d/vTPnTKAbM1gdOhY=", + "dev": true + }, + "is-module": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/is-module/-/is-module-1.0.0.tgz", + "integrity": "sha1-Mlj7afeMFNW4FdZkM2tM/7ZEFZE=", + "dev": true + }, + "is-regex": { + "version": "1.0.4", + "resolved": "http://artprod.dev.bloomberg.com/artifactory/api/npm/npm-repos/is-regex/-/is-regex-1.0.4.tgz?dl=https://registry.npmjs.org/is-regex/-/is-regex-1.0.4.tgz", + "integrity": "sha1-VRdIm1RwkbCTDglWVM7SXul+lJE=", + "dev": true, + "requires": { + "has": "^1.0.1" + } + }, + "is-symbol": { + "version": "1.0.1", + "resolved": "http://artprod.dev.bloomberg.com/artifactory/api/npm/npm-repos/is-symbol/-/is-symbol-1.0.1.tgz?dl=https://registry.npmjs.org/is-symbol/-/is-symbol-1.0.1.tgz", + "integrity": "sha1-PMWfAAJRlLarLjjbrmaJJWtmBXI=", + "dev": true + }, + "lodash": { + "version": "4.17.5", + "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.5.tgz", + "integrity": "sha512-svL3uiZf1RwhH+cWrfZn3A4+U58wbP0tGVTLQPbjplZxZ8ROD9VLuNgsRniTlLe7OlSqR79RUehXgpBW/s0IQw==", + "dev": true + }, + "magic-string": { + "version": "0.22.4", + "resolved": "https://registry.npmjs.org/magic-string/-/magic-string-0.22.4.tgz", + "integrity": "sha512-kxBL06p6iO2qPBHsqGK2b3cRwiRGpnmSuVWNhwHcMX7qJOUr1HvricYP1LZOCdkQBUp0jiWg2d6WJwR3vYgByw==", + "dev": true, + "requires": { + "vlq": "^0.2.1" + } + }, + "minimatch": { + "version": "3.0.4", + "resolved": "http://artprod.dev.bloomberg.com/artifactory/api/npm/npm-repos/minimatch/-/minimatch-3.0.4.tgz?dl=https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz", + "integrity": "sha1-UWbihkV/AzBgZL5Ul+jbsMPTIIM=", + "dev": true, + "requires": { + "brace-expansion": "^1.1.7" + } + }, + "minimist": { + "version": "0.0.8", + "resolved": "https://registry.npmjs.org/minimist/-/minimist-0.0.8.tgz", + "integrity": "sha1-hX/Kv8M5fSYluCKCYuhqp6ARsF0=", + "dev": true + }, + "mkdirp": { + "version": "0.5.1", + "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.1.tgz", + "integrity": "sha1-MAV0OOrGz3+MR2fzhkjWaX11yQM=", + "dev": true, + "requires": { + "minimist": "0.0.8" + } + }, + "moment": { + "version": "2.21.0", + "resolved": "https://registry.npmjs.org/moment/-/moment-2.21.0.tgz", + "integrity": "sha512-TCZ36BjURTeFTM/CwRcViQlfkMvL1/vFISuNLO5GkcVm1+QHfbSiNqZuWeMFjj1/3+uAjXswgRk30j1kkLYJBQ==", + "dev": true + }, + "object-inspect": { + "version": "1.6.0", + "resolved": "http://artprod.dev.bloomberg.com/artifactory/api/npm/npm-repos/object-inspect/-/object-inspect-1.6.0.tgz?dl=https://registry.npmjs.org/object-inspect/-/object-inspect-1.6.0.tgz", + "integrity": "sha1-xwtsv3LydKq0w0wMgvUWe/gs8Vs=", + "dev": true + }, + "object-keys": { + "version": "1.0.12", + "resolved": "http://artprod.dev.bloomberg.com/artifactory/api/npm/npm-repos/object-keys/-/object-keys-1.0.12.tgz?dl=https://registry.npmjs.org/object-keys/-/object-keys-1.0.12.tgz", + "integrity": "sha1-CcU4VTd1dTEMymL1W7M0q/97PtI=", + "dev": true + }, + "once": { + "version": "1.4.0", + "resolved": "http://artprod.dev.bloomberg.com/artifactory/api/npm/npm-repos/once/-/once-1.4.0.tgz?dl=https://registry.npmjs.org/once/-/once-1.4.0.tgz", + "integrity": "sha1-WDsap3WWHUsROsF9nFC6753Xa9E=", + "dev": true, + "requires": { + "wrappy": "1" + } + }, + "path-is-absolute": { + "version": "1.0.1", + "resolved": "http://artprod.dev.bloomberg.com/artifactory/api/npm/npm-repos/path-is-absolute/-/path-is-absolute-1.0.1.tgz?dl=https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz", + "integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18=", + "dev": true + }, + "path-parse": { + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/path-parse/-/path-parse-1.0.5.tgz", + "integrity": "sha1-PBrfhx6pzWyUMbbqK9dKD/BVxME=", + "dev": true + }, + "resolve": { + "version": "1.7.1", + "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.7.1.tgz", + "integrity": "sha512-c7rwLofp8g1U+h1KNyHL/jicrKg1Ek4q+Lr33AL65uZTinUZHe30D5HlyN5V9NW0JX1D5dXQ4jqW5l7Sy/kGfw==", + "dev": true, + "requires": { + "path-parse": "^1.0.5" + } + }, + "resumer": { + "version": "0.0.0", + "resolved": "http://artprod.dev.bloomberg.com/artifactory/api/npm/npm-repos/resumer/-/resumer-0.0.0.tgz?dl=https://registry.npmjs.org/resumer/-/resumer-0.0.0.tgz", + "integrity": "sha1-8ej0YeQGS6Oegq883CqMiT0HZ1k=", + "dev": true, + "requires": { + "through": "~2.3.4" + } + }, + "rollup": { + "version": "0.59.4", + "resolved": "https://registry.npmjs.org/rollup/-/rollup-0.59.4.tgz", + "integrity": "sha512-ISiMqq/aJa+57QxX2MRcvLESHdJ7wSavmr6U1euMr+6UgFe6KM+3QANrYy8LQofwhTC1I7BcAdlLnDiaODs1BA==", + "dev": true, + "requires": { + "@types/estree": "0.0.39", + "@types/node": "*" + } + }, + "rollup-plugin-license": { + "version": "0.6.0", + "resolved": "https://registry.npmjs.org/rollup-plugin-license/-/rollup-plugin-license-0.6.0.tgz", + "integrity": "sha512-Ttz65oRtNKcfV5icDkQTixc8ja64ueoXejRJoAtmjXYAWVg0qx+tu5rXmEOXWXmUXeGs0ARUVIAG0p1JK0gACQ==", + "dev": true, + "requires": { + "commenting": "1.0.5", + "lodash": "4.17.5", + "magic-string": "0.22.4", + "mkdirp": "0.5.1", + "moment": "2.21.0" + } + }, + "rollup-plugin-node-resolve": { + "version": "3.3.0", + "resolved": "https://registry.npmjs.org/rollup-plugin-node-resolve/-/rollup-plugin-node-resolve-3.3.0.tgz", + "integrity": "sha512-9zHGr3oUJq6G+X0oRMYlzid9fXicBdiydhwGChdyeNRGPcN/majtegApRKHLR5drboUvEWU+QeUmGTyEZQs3WA==", + "dev": true, + "requires": { + "builtin-modules": "^2.0.0", + "is-module": "^1.0.0", + "resolve": "^1.1.6" + } + }, + "string.prototype.trim": { + "version": "1.1.2", + "resolved": "http://artprod.dev.bloomberg.com/artifactory/api/npm/npm-repos/string.prototype.trim/-/string.prototype.trim-1.1.2.tgz?dl=https://registry.npmjs.org/string.prototype.trim/-/string.prototype.trim-1.1.2.tgz", + "integrity": "sha1-0E3iyJ4Tf019IG8Ia17S+ua+jOo=", + "dev": true, + "requires": { + "define-properties": "^1.1.2", + "es-abstract": "^1.5.0", + "function-bind": "^1.0.2" + } + }, + "tape": { + "version": "4.9.1", + "resolved": "http://artprod.dev.bloomberg.com/artifactory/api/npm/npm-repos/tape/-/tape-4.9.1.tgz?dl=https://registry.npmjs.org/tape/-/tape-4.9.1.tgz", + "integrity": "sha1-EXPXM34EDHb79C7Ib8q+3Js4Bck=", + "dev": true, + "requires": { + "deep-equal": "~1.0.1", + "defined": "~1.0.0", + "for-each": "~0.3.3", + "function-bind": "~1.1.1", + "glob": "~7.1.2", + "has": "~1.0.3", + "inherits": "~2.0.3", + "minimist": "~1.2.0", + "object-inspect": "~1.6.0", + "resolve": "~1.7.1", + "resumer": "~0.0.0", + "string.prototype.trim": "~1.1.2", + "through": "~2.3.8" + }, + "dependencies": { + "minimist": { + "version": "1.2.0", + "resolved": "http://artprod.dev.bloomberg.com/artifactory/api/npm/npm-repos/minimist/-/minimist-1.2.0.tgz?dl=https://registry.npmjs.org/minimist/-/minimist-1.2.0.tgz", + "integrity": "sha1-o1AIsg9BOD7sH7kU9M1d95omQoQ=", + "dev": true + } + } + }, + "through": { + "version": "2.3.8", + "resolved": "http://artprod.dev.bloomberg.com/artifactory/api/npm/npm-repos/through/-/through-2.3.8.tgz?dl=https://registry.npmjs.org/through/-/through-2.3.8.tgz", + "integrity": "sha1-DdTJ/6q8NXlgsbckEV1+Doai4fU=", + "dev": true + }, + "vlq": { + "version": "0.2.3", + "resolved": "https://registry.npmjs.org/vlq/-/vlq-0.2.3.tgz", + "integrity": "sha512-DRibZL6DsNhIgYQ+wNdWDL2SL3bKPlVrRiBqV5yuMm++op8W4kGFtaQfCs4KEJn0wBZcHVHJ3eoywX8983k1ow==", + "dev": true + }, + "wrappy": { + "version": "1.0.2", + "resolved": "http://artprod.dev.bloomberg.com/artifactory/api/npm/npm-repos/wrappy/-/wrappy-1.0.2.tgz?dl=https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", + "integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=", + "dev": true + } + } +} diff --git a/polyfill/package.json b/polyfill/package.json new file mode 100644 index 0000000000..2969515323 --- /dev/null +++ b/polyfill/package.json @@ -0,0 +1,36 @@ +{ + "name": "temporal", + "version": "1.0.0", + "description": "TC39 Temporal Proposal Polyfill", + "main": "index.js", + "module": "lib/index.mjs", + "directories": { + "lib": "lib", + "test": "test" + }, + "scripts": { + "test:bigint": "for FILE in $(find test/temporal -type f -name '*.js' | grep -v 'test/node.js'); do node -r ./test/node.js $FILE; if [ $? = 0 ]; then echo 'OK ' $FILE; else echo 'FAIL ' $FILE; fi; done", + "test:compat": "tape test/compat/**/*.js", + "test": "npm run test:compat && npm run test:bigint", + "prepare": "npm run build", + "build": "rollup -c rollup.config.js" + }, + "repository": { + "type": "git", + "url": "https://bbgithub.dev.bloomberg.com/javascript-guild/temporal-polyfill.git" + }, + "keywords": [ + "TC39", + "Polyfill", + "Temporal" + ], + "author": "Philipp Dunkel ", + "license": "MIT", + "dependencies": {}, + "devDependencies": { + "rollup": "^0.59.1", + "rollup-plugin-license": "^0.6.0", + "rollup-plugin-node-resolve": "^3.3.0", + "tape": "^4.9.1" + } +} diff --git a/polyfill/rollup.config.js b/polyfill/rollup.config.js new file mode 100644 index 0000000000..7ddfb3db07 --- /dev/null +++ b/polyfill/rollup.config.js @@ -0,0 +1,24 @@ +import nodeResolve from 'rollup-plugin-node-resolve'; +import license from 'rollup-plugin-license'; +import { join } from 'path'; + +export default { + input: 'lib/index.mjs', + plugins: [ + nodeResolve({ + jsnext: true + }), + license({ + banner: { + file: join(__dirname, 'LICENSE'), + encoding: 'utf-8' + } + }) + ], + output: { + file: 'index.js', + name: 'temporal', + format: 'umd', + sourcemap: true + } +}; diff --git a/polyfill/test/compat/civildate.js b/polyfill/test/compat/civildate.js new file mode 100644 index 0000000000..a41741720c --- /dev/null +++ b/polyfill/test/compat/civildate.js @@ -0,0 +1,52 @@ +const test = require('tape'); +const { CivilDate } = require('../../'); + +test('CivilDate', ({ test, end })=>{ + test('construct', ({ equal, end })=>{ + const instance = new CivilDate(1976, 11, 18); + + equal(typeof instance, 'object'); + equal(instance instanceof CivilDate, true); + equal(instance.year, 1976); + equal(instance.month, 11); + equal(instance.day, 18); + equal(instance.hour, undefined); + equal(instance.minute, undefined); + equal(instance.second, undefined); + equal(instance.millisecond, undefined); + equal(instance.nanosecond, undefined); + equal(instance.toString(), '1976-11-18'); + + end(); + }); + + test('parse', ({ equal, end })=>{ + const one = CivilDate.parse('1976-11-18T15:23:30.450000100+01:00[Europe/Vienna]'); + equal(one instanceof CivilDate, true); + equal(one.year, 1976); + equal(one.month, 11); + equal(one.day, 18); + + const two = CivilDate.parse('1976-11-18T15:23:30.450000100[Europe/Vienna]'); + equal(two instanceof CivilDate, true); + equal(two.year, 1976); + equal(two.month, 11); + equal(two.day, 18); + + const three = CivilDate.parse('1976-11-18T15:23:30.450000100+01:00'); + equal(three instanceof CivilDate, true); + equal(three.year, 1976); + equal(three.month, 11); + equal(three.day, 18); + + const four = CivilDate.parse('1976-11-18T15:23:30.450000100'); + equal(four instanceof CivilDate, true); + equal(four.year, 1976); + equal(four.month, 11); + equal(four.day, 18); + + end(); + }); + + end(); +}); diff --git a/polyfill/test/compat/civildatetime.js b/polyfill/test/compat/civildatetime.js new file mode 100644 index 0000000000..6d8ed54e64 --- /dev/null +++ b/polyfill/test/compat/civildatetime.js @@ -0,0 +1,109 @@ +const test = require('tape'); +const { CivilDateTime } = require('../../'); + +test('CivilDateTime', ({ test, end })=>{ + test('simple', ({ equal, end })=>{ + const instance = new CivilDateTime(1976, 11, 18, 15, 23, 30); + + equal('1976-11-18T15:23:30.000000000', instance.toString()); + equal('1976-11-18T15:23:30.000000000+01:00[Europe/Berlin]', instance.withZone('Europe/Berlin').toString()); + + const anniversary = instance.plus({ years: 3 }); + equal('1979-11-18T15:23:30.000000000', anniversary.toString()); + equal('1979-11-18T15:23:30.000000000+01:00[Europe/Berlin]', anniversary.withZone('Europe/Berlin').toString()); + + const runup = anniversary.plus({ months: -1 }); + equal('1979-10-18T15:23:30.000000000', runup.toString()); + equal('1979-10-18T15:23:30.000000000+01:00[Europe/Berlin]', runup.withZone('Europe/Berlin').toString()); + + const thirty = runup.plus({ days: 30 }); + equal('1979-11-17T15:23:30.000000000', thirty.toString()); + equal('1979-11-17T15:23:30.000000000+01:00[Europe/Berlin]', thirty.withZone('Europe/Berlin').toString()); + + const preptime = anniversary.plus({ hours: -5, minutes: 37, seconds: 30, milliseconds: 4, nanoseconds: -3 }); + equal('1979-11-18T11:01:00.003999997', preptime.toString()); + equal('1979-11-18T11:01:00.003999997+01:00[Europe/Berlin]', preptime.withZone('Europe/Berlin').toString()); + + const daybreak = anniversary.with({ hour: 0, minute: 0, second: 0 }); + equal('1979-11-18T00:00:00.000000000', daybreak.toString()); + equal('1979-11-18T00:00:00.000000000+01:00[Europe/Berlin]', daybreak.withZone('Europe/Berlin').toString()); + + const nightfall = anniversary.with({ hour: 23, minute: 59, second: 59, millisecond: 1000, nanosecond: -1 }); + equal('1979-11-18T23:59:59.999999999', nightfall.toString()); + equal('1979-11-18T23:59:59.999999999+01:00[Europe/Berlin]', nightfall.withZone('Europe/Berlin').toString()); + + const year = (new Date()).getFullYear() + const birthday = instance.with({ year }); + equal(`${year}-11-18T15:23:30.000000000`, birthday.toString()); + equal(`${year}-11-18T15:23:30.000000000+01:00[Europe/Berlin]`, birthday.withZone('Europe/Berlin').toString()); + + end(); + }); + + test('construct', ({ equal, end })=>{ + const instance = new CivilDateTime(1976, 11, 18, 15, 23, 30, 450, 12345); + + equal(typeof instance, 'object'); + equal(instance instanceof CivilDateTime, true); + equal(instance.year, 1976); + equal(instance.month, 11); + equal(instance.day, 18); + equal(instance.hour, 15); + equal(instance.minute, 23); + equal(instance.second, 30); + equal(instance.millisecond, 450); + equal(instance.nanosecond, 12345); + equal(instance.toString(), '1976-11-18T15:23:30.450012345'); + + end(); + }); + + test('parse', ({ equal, end })=>{ + const one = CivilDateTime.parse('1976-11-18T15:23:30.450000100+01:00[Europe/Vienna]'); + equal(one instanceof CivilDateTime, true); + equal(one.year, 1976); + equal(one.month, 11); + equal(one.day, 18); + equal(one.hour, 15); + equal(one.minute, 23); + equal(one.second, 30); + equal(one.millisecond, 450); + equal(one.nanosecond, 100); + + const two = CivilDateTime.parse('1976-11-18T15:23:30.450000100[Europe/Vienna]'); + equal(two instanceof CivilDateTime, true); + equal(two.year, 1976); + equal(two.month, 11); + equal(two.day, 18); + equal(two.hour, 15); + equal(two.minute, 23); + equal(two.second, 30); + equal(two.millisecond, 450); + equal(two.nanosecond, 100); + + const three = CivilDateTime.parse('1976-11-18T15:23:30.450000100+01:00'); + equal(three instanceof CivilDateTime, true); + equal(three.year, 1976); + equal(three.month, 11); + equal(three.day, 18); + equal(three.hour, 15); + equal(three.minute, 23); + equal(three.second, 30); + equal(three.millisecond, 450); + equal(three.nanosecond, 100); + + const four = CivilDateTime.parse('1976-11-18T15:23:30.450000100'); + equal(four.year, 1976); + equal(four.month, 11); + equal(four.day, 18); + equal(four.hour, 15); + equal(four.minute, 23); + equal(four.second, 30); + equal(four.millisecond, 450); + equal(four.nanosecond, 100); + + end(); + }); + + end(); +}); diff --git a/polyfill/test/compat/civiltime.js b/polyfill/test/compat/civiltime.js new file mode 100644 index 0000000000..2eab072abf --- /dev/null +++ b/polyfill/test/compat/civiltime.js @@ -0,0 +1,60 @@ +const test = require('tape'); +const { CivilTime } = require('../../'); + +test('CivilTime', ({ test, end })=>{ + test('construct', ({ equal, end })=>{ + const instance = new CivilTime(15, 23, 30, 450, 12345); + + equal(typeof instance, 'object'); + equal(instance instanceof CivilTime, true); + equal(instance.year, undefined); + equal(instance.month, undefined); + equal(instance.day, undefined); + equal(instance.hour, 15); + equal(instance.minute, 23); + equal(instance.second, 30); + equal(instance.millisecond, 450); + equal(instance.nanosecond, 12345); + equal(instance.toString(), '15:23:30.450012345'); + + end(); + }); + + test('parse', ({ equal, end })=>{ + const one = CivilTime.parse('1976-11-18T15:23:30.450000100+01:00[Europe/Vienna]'); + equal(one instanceof CivilTime, true); + equal(one.hour, 15); + equal(one.minute, 23); + equal(one.second, 30); + equal(one.millisecond, 450); + equal(one.nanosecond, 100); + + const two = CivilTime.parse('1976-11-18T15:23:30.450000100[Europe/Vienna]'); + equal(two instanceof CivilTime, true); + equal(two.hour, 15); + equal(two.minute, 23); + equal(two.second, 30); + equal(two.millisecond, 450); + equal(two.nanosecond, 100); + + const three = CivilTime.parse('1976-11-18T15:23:30.450000100+01:00'); + equal(three instanceof CivilTime, true); + equal(three.hour, 15); + equal(three.minute, 23); + equal(three.second, 30); + equal(three.millisecond, 450); + equal(three.nanosecond, 100); + + const four = CivilTime.parse('1976-11-18T15:23:30.450000100'); + equal(four instanceof CivilTime, true); + equal(four.hour, 15); + equal(four.minute, 23); + equal(four.second, 30); + equal(four.millisecond, 450); + equal(four.nanosecond, 100); + + end(); + }); + + end(); +}); diff --git a/polyfill/test/compat/instant.js b/polyfill/test/compat/instant.js new file mode 100644 index 0000000000..d8287f61a5 --- /dev/null +++ b/polyfill/test/compat/instant.js @@ -0,0 +1,54 @@ +const test = require('tape'); +const { Instant } = require('../../'); + +test('Instant', ({ test, end})=>{ + test('simple', ({ equal, end })=>{ + const instant = Instant.fromDate(0); + + equal('1970-01-01T00:00:00.000000000+00:00[UTC]', instant.toString()); + + const now = new Date(); + const nowi = Instant.fromDate(now); + equal(now.toISOString().replace('Z','000000+00:00[UTC]'), nowi.toString()); + end(); + }); + + test('construct', ({ equal, end })=>{ + const instance = Instant.fromDate(217178610450); + + equal(typeof instance, 'object'); + equal(instance instanceof Instant, true); + equal(instance.milliseconds, 217178610450); + equal(instance.nanoseconds, 0); + equal(instance.toString(), '1976-11-18T15:23:30.450000000+00:00[UTC]'); + + end(); + }); + + test('parse', ({ equal, end })=>{ + const one = Instant.parse('1976-11-18T15:23:30.450000100+01:00[Europe/Vienna]'); + equal(one instanceof Instant, true); + equal(one.milliseconds, 217175010450); + equal(one.nanoseconds, 100); + + + const two = Instant.parse('1976-11-18T15:23:30.450000100[Europe/Vienna]'); + equal(two instanceof Instant, true); + equal(two.milliseconds, 217175010450); + equal(two.nanoseconds, 100); + + const three = Instant.parse('1976-11-18T15:23:30.450000100+01:00'); + equal(three instanceof Instant, true); + equal(three.milliseconds, 217175010450); + equal(three.nanoseconds, 100); + + const four = Instant.parse('1976-11-18T15:23:30.450000100'); + equal(four instanceof Instant, true); + equal(four.milliseconds, 217178610450); + equal(four.nanoseconds, 100); + + end(); + }); + + end(); +}); diff --git a/polyfill/test/compat/zonedinstant.js b/polyfill/test/compat/zonedinstant.js new file mode 100644 index 0000000000..10575eec95 --- /dev/null +++ b/polyfill/test/compat/zonedinstant.js @@ -0,0 +1,51 @@ +const test = require('tape'); +const { Instant, ZonedInstant } = require('../../'); + +test('ZonedInstant', ({ test, end})=>{ + test('simple', ({ equal, end })=>{ + + end(); + }); + + test('construct', ({ equal, end })=>{ + const instant = Instant.fromDate(217175010450); + const instance = new ZonedInstant(instant, 'Europe/Vienna'); + + equal(typeof instance, 'object'); + equal(instance instanceof ZonedInstant, true); + equal(instance.milliseconds, 217175010450); + equal(instance.nanoseconds, 0); + equal(instance.toString(), '1976-11-18T15:23:30.450000000+01:00[Europe/Vienna]'); + end(); + }); + + test('parse', ({ equal, end })=>{ + const one = ZonedInstant.parse('1976-11-18T15:23:30.450000100+01:00[Europe/Vienna]'); + equal(one instanceof ZonedInstant, true); + equal(one.milliseconds, 217175010450); + equal(one.nanoseconds, 100); + equal(one.timeZone, 'Europe/Vienna'); + + const two = ZonedInstant.parse('1976-11-18T15:23:30.450000100[Europe/Vienna]'); + equal(two instanceof ZonedInstant, true); + equal(two.milliseconds, 217175010450); + equal(two.nanoseconds, 100); + equal(two.timeZone, 'Europe/Vienna'); + + const three = ZonedInstant.parse('1976-11-18T15:23:30.450000100+01:00'); + equal(three instanceof ZonedInstant, true); + equal(three.milliseconds, 217175010450); + equal(three.nanoseconds, 100); + equal(three.timeZone, 'Europe/Andorra'); + + const four = ZonedInstant.parse('1976-11-18T15:23:30.450000100'); + equal(four instanceof ZonedInstant, true); + equal(four.milliseconds, 217178610450); + equal(four.nanoseconds, 100); + equal(four.timeZone, 'Europe/London'); + + end(); + }); + + end(); +}); diff --git a/polyfill/test/demo.html b/polyfill/test/demo.html new file mode 100644 index 0000000000..10c8da16e1 --- /dev/null +++ b/polyfill/test/demo.html @@ -0,0 +1,86 @@ + + + World Clock + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Time
Automatic Update to Current Time
+ + \ No newline at end of file diff --git a/polyfill/test/node.js b/polyfill/test/node.js new file mode 100644 index 0000000000..90556ca650 --- /dev/null +++ b/polyfill/test/node.js @@ -0,0 +1,21 @@ + +// Setup Global Environment to run TC39 tests via +// node -r ./test/node.js test/.js + +const assert = require('assert'); +global.assert = (value, message)=>assert(value, message); +global.assert.sameValue = (actual, expected, message)=>assert.strictEqual(actual, expected, message); +global.assert.notSameValue = (actual, expected, message)=>assert.notStrictEqual(actual, expected, message); +global.assert.deepEqual = (actual, expected, message)=>assert.strictDeepEqual(actual, expected, message); +global.assert.notDeepEqual = (actual, expected, message)=>assert.notDeepStrictEqual(actual, expected, message); + +global.assert.throws = (expectedErrorConstructor, fn, message)=>{ + try { + fn(); + } catch(err) { + assert(err.constructor === expectedErrorConstructor, message); + return; + } + assert(false, message); +}; +global.temporal = require('../index.js'); diff --git a/polyfill/test/temporal/CivilDate/constructor.js b/polyfill/test/temporal/CivilDate/constructor.js new file mode 100644 index 0000000000..644c53c5c6 --- /dev/null +++ b/polyfill/test/temporal/CivilDate/constructor.js @@ -0,0 +1,23 @@ +// Copyright (C) 2018 Bloomberg LP. All rights reserved. +// This code is governed by the license found in the LICENSE file. + +/*--- +description: > + Basic Tests for CivilDate +author: Philipp Dunkel +esid: pending +---*/ + +const instance = new temporal.CivilDate(1976, 11, 18); + +assert.sameValue(typeof instance, 'object'); +assert.sameValue(instance instanceof temporal.CivilDate, true); +assert.sameValue(instance.year, 1976); +assert.sameValue(instance.month, 11); +assert.sameValue(instance.day, 18); +assert.sameValue(instance.hour, undefined); +assert.sameValue(instance.minute, undefined); +assert.sameValue(instance.second, undefined); +assert.sameValue(instance.millisecond, undefined); +assert.sameValue(instance.nanosecond, undefined); +assert.sameValue(instance.toString(), '1976-11-18'); diff --git a/polyfill/test/temporal/CivilDate/parse.js b/polyfill/test/temporal/CivilDate/parse.js new file mode 100644 index 0000000000..009c24e903 --- /dev/null +++ b/polyfill/test/temporal/CivilDate/parse.js @@ -0,0 +1,33 @@ +// Copyright (C) 2018 Bloomberg LP. All rights reserved. +// This code is governed by the license found in the LICENSE file. + +/*--- +description: > + Parse Tests for CivilDate +author: Philipp Dunkel +esid: pending +---*/ + +const one = temporal.CivilDate.parse('1976-11-18T15:23:30.450000100+01:00[Europe/Vienna]'); +assert.sameValue(one instanceof temporal.CivilDate, true); +assert.sameValue(one.year, 1976); +assert.sameValue(one.month, 11); +assert.sameValue(one.day, 18); + +const two = temporal.CivilDate.parse('1976-11-18T15:23:30.450000100[Europe/Vienna]'); +assert.sameValue(two instanceof temporal.CivilDate, true); +assert.sameValue(two.year, 1976); +assert.sameValue(two.month, 11); +assert.sameValue(two.day, 18); + +const three = temporal.CivilDate.parse('1976-11-18T15:23:30.450000100+01:00'); +assert.sameValue(three instanceof temporal.CivilDate, true); +assert.sameValue(three.year, 1976); +assert.sameValue(three.month, 11); +assert.sameValue(three.day, 18); + +const four = temporal.CivilDate.parse('1976-11-18T15:23:30.450000100'); +assert.sameValue(four instanceof temporal.CivilDate, true); +assert.sameValue(four.year, 1976); +assert.sameValue(four.month, 11); +assert.sameValue(four.day, 18); diff --git a/polyfill/test/temporal/CivilDateTime/basic.js b/polyfill/test/temporal/CivilDateTime/basic.js new file mode 100644 index 0000000000..f78f4dd375 --- /dev/null +++ b/polyfill/test/temporal/CivilDateTime/basic.js @@ -0,0 +1,43 @@ +// Copyright (C) 2018 Bloomberg LP. All rights reserved. +// This code is governed by the license found in the LICENSE file. + +/*--- +description: > + Basic Tests for CivilDateTime +author: Philipp Dunkel +esid: pending +---*/ + +const instance = new temporal.CivilDateTime(1976, 11, 18, 15, 23, 30); + +assert.sameValue('1976-11-18T15:23:30.000000000', instance.toString()); +assert.sameValue('1976-11-18T15:23:30.000000000+01:00[Europe/Berlin]', instance.withZone('Europe/Berlin').toString()); + +const anniversary = instance.plus({ years: 3 }); +assert.sameValue('1979-11-18T15:23:30.000000000', anniversary.toString()); +assert.sameValue('1979-11-18T15:23:30.000000000+01:00[Europe/Berlin]', anniversary.withZone('Europe/Berlin').toString()); + +const runup = anniversary.plus({ months: -1 }); +assert.sameValue('1979-10-18T15:23:30.000000000', runup.toString()); +assert.sameValue('1979-10-18T15:23:30.000000000+01:00[Europe/Berlin]', runup.withZone('Europe/Berlin').toString()); + +const thirty = runup.plus({ days: 30 }); +assert.sameValue('1979-11-17T15:23:30.000000000', thirty.toString()); +assert.sameValue('1979-11-17T15:23:30.000000000+01:00[Europe/Berlin]', thirty.withZone('Europe/Berlin').toString()); + +const preptime = anniversary.plus({ hours: -5, minutes: 37, seconds: 30, milliseconds: 4, nanoseconds: -3 }); +assert.sameValue('1979-11-18T11:01:00.003999997', preptime.toString()); +assert.sameValue('1979-11-18T11:01:00.003999997+01:00[Europe/Berlin]', preptime.withZone('Europe/Berlin').toString()); + +const daybreak = anniversary.with({ hour: 0, minute: 0, second: 0 }); +assert.sameValue('1979-11-18T00:00:00.000000000', daybreak.toString()); +assert.sameValue('1979-11-18T00:00:00.000000000+01:00[Europe/Berlin]', daybreak.withZone('Europe/Berlin').toString()); + +const nightfall = anniversary.with({ hour: 23, minute: 59, second: 59, millisecond: 1000, nanosecond: -1 }); +assert.sameValue('1979-11-18T23:59:59.999999999', nightfall.toString()); +assert.sameValue('1979-11-18T23:59:59.999999999+01:00[Europe/Berlin]', nightfall.withZone('Europe/Berlin').toString()); + +const year = (new Date()).getFullYear() +const birthday = instance.with({ year }); +assert.sameValue(`${year}-11-18T15:23:30.000000000`, birthday.toString()); +assert.sameValue(`${year}-11-18T15:23:30.000000000+01:00[Europe/Berlin]`, birthday.withZone('Europe/Berlin').toString()); diff --git a/polyfill/test/temporal/CivilDateTime/constructor.js b/polyfill/test/temporal/CivilDateTime/constructor.js new file mode 100644 index 0000000000..7ee4eac3d2 --- /dev/null +++ b/polyfill/test/temporal/CivilDateTime/constructor.js @@ -0,0 +1,23 @@ +// Copyright (C) 2018 Bloomberg LP. All rights reserved. +// This code is governed by the license found in the LICENSE file. + +/*--- +description: > + Basic Tests for CivilDateTime +author: Philipp Dunkel +esid: pending +---*/ + +const instance = new temporal.CivilDateTime(1976, 11, 18, 15, 23, 30, 450, 12345); + +assert.sameValue(typeof instance, 'object'); +assert.sameValue(instance instanceof temporal.CivilDateTime, true); +assert.sameValue(instance.year, 1976); +assert.sameValue(instance.month, 11); +assert.sameValue(instance.day, 18); +assert.sameValue(instance.hour, 15); +assert.sameValue(instance.minute, 23); +assert.sameValue(instance.second, 30); +assert.sameValue(instance.millisecond, 450); +assert.sameValue(instance.nanosecond, 12345); +assert.sameValue(instance.toString(), '1976-11-18T15:23:30.450012345'); diff --git a/polyfill/test/temporal/CivilDateTime/parse.js b/polyfill/test/temporal/CivilDateTime/parse.js new file mode 100644 index 0000000000..f4069a422f --- /dev/null +++ b/polyfill/test/temporal/CivilDateTime/parse.js @@ -0,0 +1,52 @@ +// Copyright (C) 2018 Bloomberg LP. All rights reserved. +// This code is governed by the license found in the LICENSE file. + +/*--- +description: > + Parse Tests for CivilDateTime (This assumes TZ=Europe/London) +author: Philipp Dunkel +esid: pending +---*/ + +const one = temporal.CivilDateTime.parse('1976-11-18T15:23:30.450000100+01:00[Europe/Vienna]'); +assert.sameValue(one instanceof temporal.CivilDateTime, true); +assert.sameValue(one.year, 1976); +assert.sameValue(one.month, 11); +assert.sameValue(one.day, 18); +assert.sameValue(one.hour, 15); +assert.sameValue(one.minute, 23); +assert.sameValue(one.second, 30); +assert.sameValue(one.millisecond, 450); +assert.sameValue(one.nanosecond, 100); + +const two = temporal.CivilDateTime.parse('1976-11-18T15:23:30.450000100[Europe/Vienna]'); +assert.sameValue(two instanceof temporal.CivilDateTime, true); +assert.sameValue(two.year, 1976); +assert.sameValue(two.month, 11); +assert.sameValue(two.day, 18); +assert.sameValue(two.hour, 15); +assert.sameValue(two.minute, 23); +assert.sameValue(two.second, 30); +assert.sameValue(two.millisecond, 450); +assert.sameValue(two.nanosecond, 100); + +const three = temporal.CivilDateTime.parse('1976-11-18T15:23:30.450000100+01:00'); +assert.sameValue(three instanceof temporal.CivilDateTime, true); +assert.sameValue(three.year, 1976); +assert.sameValue(three.month, 11); +assert.sameValue(three.day, 18); +assert.sameValue(three.hour, 15); +assert.sameValue(three.minute, 23); +assert.sameValue(three.second, 30); +assert.sameValue(three.millisecond, 450); +assert.sameValue(three.nanosecond, 100); + +const four = temporal.CivilDateTime.parse('1976-11-18T15:23:30.450000100'); +assert.sameValue(four.year, 1976); +assert.sameValue(four.month, 11); +assert.sameValue(four.day, 18); +assert.sameValue(four.hour, 15); +assert.sameValue(four.minute, 23); +assert.sameValue(four.second, 30); +assert.sameValue(four.millisecond, 450); +assert.sameValue(four.nanosecond, 100); diff --git a/polyfill/test/temporal/CivilTime/constructor.js b/polyfill/test/temporal/CivilTime/constructor.js new file mode 100644 index 0000000000..f81e8c72e7 --- /dev/null +++ b/polyfill/test/temporal/CivilTime/constructor.js @@ -0,0 +1,23 @@ +// Copyright (C) 2018 Bloomberg LP. All rights reserved. +// This code is governed by the license found in the LICENSE file. + +/*--- +description: > + Basic Tests for CivilTime +author: Philipp Dunkel +esid: pending +---*/ + +const instance = new temporal.CivilTime(15, 23, 30, 450, 12345); + +assert.sameValue(typeof instance, 'object'); +assert.sameValue(instance instanceof temporal.CivilTime, true); +assert.sameValue(instance.year, undefined); +assert.sameValue(instance.month, undefined); +assert.sameValue(instance.day, undefined); +assert.sameValue(instance.hour, 15); +assert.sameValue(instance.minute, 23); +assert.sameValue(instance.second, 30); +assert.sameValue(instance.millisecond, 450); +assert.sameValue(instance.nanosecond, 12345); +assert.sameValue(instance.toString(), '15:23:30.450012345'); diff --git a/polyfill/test/temporal/CivilTime/parse.js b/polyfill/test/temporal/CivilTime/parse.js new file mode 100644 index 0000000000..db573d687b --- /dev/null +++ b/polyfill/test/temporal/CivilTime/parse.js @@ -0,0 +1,41 @@ +// Copyright (C) 2018 Bloomberg LP. All rights reserved. +// This code is governed by the license found in the LICENSE file. + +/*--- +description: > + Parse Tests for CivilTime (This assumes TZ=Europe/London) +author: Philipp Dunkel +esid: pending +---*/ + +const one = temporal.CivilTime.parse('1976-11-18T15:23:30.450000100+01:00[Europe/Vienna]'); +assert.sameValue(one instanceof temporal.CivilTime, true); +assert.sameValue(one.hour, 15); +assert.sameValue(one.minute, 23); +assert.sameValue(one.second, 30); +assert.sameValue(one.millisecond, 450); +assert.sameValue(one.nanosecond, 100); + +const two = temporal.CivilTime.parse('1976-11-18T15:23:30.450000100[Europe/Vienna]'); +assert.sameValue(two instanceof temporal.CivilTime, true); +assert.sameValue(two.hour, 15); +assert.sameValue(two.minute, 23); +assert.sameValue(two.second, 30); +assert.sameValue(two.millisecond, 450); +assert.sameValue(two.nanosecond, 100); + +const three = temporal.CivilTime.parse('1976-11-18T15:23:30.450000100+01:00'); +assert.sameValue(three instanceof temporal.CivilTime, true); +assert.sameValue(three.hour, 15); +assert.sameValue(three.minute, 23); +assert.sameValue(three.second, 30); +assert.sameValue(three.millisecond, 450); +assert.sameValue(three.nanosecond, 100); + +const four = temporal.CivilTime.parse('1976-11-18T15:23:30.450000100'); +assert.sameValue(four instanceof temporal.CivilTime, true); +assert.sameValue(four.hour, 15); +assert.sameValue(four.minute, 23); +assert.sameValue(four.second, 30); +assert.sameValue(four.millisecond, 450); +assert.sameValue(four.nanosecond, 100); diff --git a/polyfill/test/temporal/Instant/basic.js b/polyfill/test/temporal/Instant/basic.js new file mode 100644 index 0000000000..42a375e979 --- /dev/null +++ b/polyfill/test/temporal/Instant/basic.js @@ -0,0 +1,17 @@ +// Copyright (C) 2018 Bloomberg LP. All rights reserved. +// This code is governed by the license found in the LICENSE file. + +/*--- +description: > + Basic Tests for Instant +author: Philipp Dunkel +esid: pending +---*/ + +const instant = new temporal.Instant(0n); + +assert.sameValue('1970-01-01T00:00:00.000000000+00:00[UTC]', instant.toString()); + +const now = new Date(); +const nowi = new temporal.Instant(BigInt(now.valueOf()) * BigInt(1e6)); +assert.sameValue(now.toISOString().replace('Z','000000+00:00[UTC]'), nowi.toString()); diff --git a/polyfill/test/temporal/Instant/constructor.js b/polyfill/test/temporal/Instant/constructor.js new file mode 100644 index 0000000000..7b1a83a8ce --- /dev/null +++ b/polyfill/test/temporal/Instant/constructor.js @@ -0,0 +1,17 @@ +// Copyright (C) 2018 Bloomberg LP. All rights reserved. +// This code is governed by the license found in the LICENSE file. + +/*--- +description: > + Basic Tests for Instant +author: Philipp Dunkel +esid: pending +---*/ + +const instance = new temporal.Instant(217178610450000100n); + +assert.sameValue(typeof instance, 'object'); +assert.sameValue(instance instanceof temporal.Instant, true); +assert.sameValue(instance.milliseconds, 217178610450); +assert.sameValue(instance.nanoseconds, 100); +assert.sameValue(instance.toString(), '1976-11-18T15:23:30.450000100+00:00[UTC]'); diff --git a/polyfill/test/temporal/Instant/parse.js b/polyfill/test/temporal/Instant/parse.js new file mode 100644 index 0000000000..49e064c4e8 --- /dev/null +++ b/polyfill/test/temporal/Instant/parse.js @@ -0,0 +1,30 @@ +// Copyright (C) 2018 Bloomberg LP. All rights reserved. +// This code is governed by the license found in the LICENSE file. + +/*--- +description: > + Parse Tests for ZonedInstant (This assumes TZ=Europe/London) +author: Philipp Dunkel +esid: pending +---*/ + +const one = temporal.Instant.parse('1976-11-18T15:23:30.450000100+01:00[Europe/Vienna]'); +assert.sameValue(one instanceof temporal.Instant, true); +assert.sameValue(one.milliseconds, 217175010450); +assert.sameValue(one.nanoseconds, 100); + + +const two = temporal.Instant.parse('1976-11-18T15:23:30.450000100[Europe/Vienna]'); +assert.sameValue(two instanceof temporal.Instant, true); +assert.sameValue(two.milliseconds, 217175010450); +assert.sameValue(two.nanoseconds, 100); + +const three = temporal.Instant.parse('1976-11-18T15:23:30.450000100+01:00'); +assert.sameValue(three instanceof temporal.Instant, true); +assert.sameValue(three.milliseconds, 217175010450); +assert.sameValue(three.nanoseconds, 100); + +const four = temporal.Instant.parse('1976-11-18T15:23:30.450000100'); +assert.sameValue(four instanceof temporal.Instant, true); +assert.sameValue(four.milliseconds, 217178610450); +assert.sameValue(four.nanoseconds, 100); diff --git a/polyfill/test/temporal/ZonedInstant/constructor.js b/polyfill/test/temporal/ZonedInstant/constructor.js new file mode 100644 index 0000000000..3f0e2e5b35 --- /dev/null +++ b/polyfill/test/temporal/ZonedInstant/constructor.js @@ -0,0 +1,18 @@ +// Copyright (C) 2018 Bloomberg LP. All rights reserved. +// This code is governed by the license found in the LICENSE file. + +/*--- +description: > + Basic Tests for ZonedInstant +author: Philipp Dunkel +esid: pending +---*/ + +const instant = new temporal.Instant(217175010450000100n); +const instance = new temporal.ZonedInstant(instant, 'Europe/Vienna'); + +assert.sameValue(typeof instance, 'object'); +assert.sameValue(instance instanceof temporal.ZonedInstant, true); +assert.sameValue(instance.milliseconds, 217175010450); +assert.sameValue(instance.nanoseconds, 100); +assert.sameValue(instance.toString(), '1976-11-18T15:23:30.450000100+01:00[Europe/Vienna]'); diff --git a/polyfill/test/temporal/ZonedInstant/parse.js b/polyfill/test/temporal/ZonedInstant/parse.js new file mode 100644 index 0000000000..4c9cde6fe7 --- /dev/null +++ b/polyfill/test/temporal/ZonedInstant/parse.js @@ -0,0 +1,33 @@ +// Copyright (C) 2018 Bloomberg LP. All rights reserved. +// This code is governed by the license found in the LICENSE file. + +/*--- +description: > + Parse Tests for ZonedInstant (This assumes TZ=Europe/London) +author: Philipp Dunkel +esid: pending +---*/ + +const one = temporal.ZonedInstant.parse('1976-11-18T15:23:30.450000100+01:00[Europe/Vienna]'); +assert.sameValue(one instanceof temporal.ZonedInstant, true); +assert.sameValue(one.milliseconds, 217175010450); +assert.sameValue(one.nanoseconds, 100); +assert.sameValue(one.timeZone, 'Europe/Vienna'); + +const two = temporal.ZonedInstant.parse('1976-11-18T15:23:30.450000100[Europe/Vienna]'); +assert.sameValue(two instanceof temporal.ZonedInstant, true); +assert.sameValue(two.milliseconds, 217175010450); +assert.sameValue(two.nanoseconds, 100); +assert.sameValue(two.timeZone, 'Europe/Vienna'); + +const three = temporal.ZonedInstant.parse('1976-11-18T15:23:30.450000100+01:00'); +assert.sameValue(three instanceof temporal.ZonedInstant, true); +assert.sameValue(three.milliseconds, 217175010450); +assert.sameValue(three.nanoseconds, 100); +assert.sameValue(three.timeZone, 'Europe/Andorra'); + +const four = temporal.ZonedInstant.parse('1976-11-18T15:23:30.450000100'); +assert.sameValue(four instanceof temporal.ZonedInstant, true); +assert.sameValue(four.milliseconds, 217178610450); +assert.sameValue(four.nanoseconds, 100); +assert.sameValue(four.timeZone, 'Europe/London'); diff --git a/polyfill/util/extract.js b/polyfill/util/extract.js new file mode 100644 index 0000000000..b49dc0f861 --- /dev/null +++ b/polyfill/util/extract.js @@ -0,0 +1,92 @@ +/* +** Copyright (C) 2018 Bloomberg LP. All rights reserved. +** This code is governed by the license found in the LICENSE file. +** +** This is meant to extract TimeZone Information from the zoneinfo db +** It does not extract full information, only the names and descriptions +** for different timezones +**/ + +const fs = require('fs'); + +const zoneinfo = fs.readFileSync('/usr/share/zoneinfo/zone.tab', 'utf-8').split(/\r?\n/).filter(l=>l.trim() && !/^\s*#/.test(l)); + +const dates = (()=>{ + const dates = [] + for (let month = 0; month < 12; month++) { + for (let day = 1; day < 32; day++) { + dates.push(new Date(2018, month, day, 0, 0, 0)); + } + } + return dates; +})(); +// [ +// new Date(2018, 0, 15, 0, 0, 0), +// new Date(2018, 1, 15, 0, 0, 0), +// new Date(2018, 2, 15, 0, 0, 0), +// new Date(2018, 3, 15, 0, 0, 0), +// new Date(2018, 4, 15, 0, 0, 0), +// new Date(2018, 5, 15, 0, 0, 0), +// new Date(2018, 6, 15, 0, 0, 0), +// new Date(2018, 7, 15, 0, 0, 0), +// new Date(2018, 8, 15, 0, 0, 0), +// new Date(2018, 9, 15, 0, 0, 0), +// new Date(2018, 10, 15, 0, 0, 0), +// new Date(2018, 11, 15, 0, 0, 0), +// ]; + +const zones = {}; +zoneinfo.forEach((line)=>{ + const [ country, coords, zone, ...comments ] = line.split(/\s+/); + try { + const data = zones[zone] = info(zone); + } catch(err) { + console.error(`Ignore: ${zone} ${err.message}`); + } +}); +[ + 'UTC', + 'GMT' +].forEach((zone)=>{ + try { + const data = zones[zone] = info(zone); + } catch(err) { + console.error(`Ignore: ${zone} ${err.message}`); + } +}); + +console.log('export const zones = ' + JSON.stringify(zones, undefined, ' ') + ';'); + +function info(zone) { + const fmt = new Intl.DateTimeFormat('en-us', { + year: 'numeric', + month: 'numeric', + day: 'numeric', + hour: 'numeric', + minute: 'numeric', + second: 'numeric', + hour12: false, + timeZone: zone, + timeZoneName: 'long' + }); + + const data = {}; + dates.forEach(date=>{ + const parts = fmt.formatToParts(date).reduce((agg, itm)=>{ + if (itm.type !== 'literal') { agg[itm.type] = itm.value; } + return agg; + }, {}); + + const ts = date.getTime(); + const zts = Date.UTC(parts.year, parts.month - 1, parts.day, parts.hour, parts.minute, parts.second); + + const diff = Math.abs(ts - zts) / 60000; + const sign = ts > zts ? '-' : '+'; + const hour = ('00' + Math.floor(diff / 60)).slice(-2); + const minute = ('00' + Math.floor(diff % 60)).slice(-2); + const offset = `${sign}${hour}:${minute}`; + + data[offset] = parts.timeZoneName; + }); + return data; +}