From e27599fa02b1e6bca2e4d33e87e4947a485476fd Mon Sep 17 00:00:00 2001 From: Marnus Weststrate Date: Sat, 30 Mar 2024 08:03:16 +0000 Subject: [PATCH 01/10] Rename to toZonedTime and fromZonedTime --- CHANGELOG.md | 5 + README.md | 60 ++- package.json | 57 ++- src/esm/fp/index.js | 8 +- src/esm/index.js | 4 +- src/format/test.js | 8 +- src/formatInTimeZone/index.js | 4 +- .../index.d.ts | 4 +- .../index.js | 6 +- .../index.js.flow | 0 src/fp/fromZonedTimeWithOptions/index.d.ts | 4 + .../index.js | 6 +- .../index.js.flow | 0 src/fp/index.js | 8 +- src/fp/index.js.flow | 8 +- .../toZonedTime}/index.d.ts | 4 +- .../{utcToZonedTime => toZonedTime}/index.js | 6 +- .../index.js.flow | 0 src/fp/toZonedTimeWithOptions/index.d.ts | 4 + .../index.js | 6 +- .../index.js.flow | 0 src/fp/utcToZonedTimeWithOptions/index.d.ts | 4 - src/fp/zonedTimeToUtcWithOptions/index.d.ts | 4 - .../index.d.ts | 4 +- .../index.js | 6 +- .../index.js.flow | 0 src/{zonedTimeToUtc => fromZonedTime}/test.js | 78 ++-- src/index.js | 4 +- src/index.js.flow | 6 +- .../zonedTimeToUtc => toZonedTime}/index.d.ts | 4 +- src/{utcToZonedTime => toZonedTime}/index.js | 6 +- .../index.js.flow | 0 src/{utcToZonedTime => toZonedTime}/test.js | 38 +- typings.d.ts | 364 +++++++++--------- 34 files changed, 373 insertions(+), 347 deletions(-) rename src/fp/{utcToZonedTime => fromZonedTime}/index.d.ts (57%) rename src/fp/{zonedTimeToUtc => fromZonedTime}/index.js (55%) rename src/fp/{utcToZonedTime => fromZonedTime}/index.js.flow (100%) create mode 100644 src/fp/fromZonedTimeWithOptions/index.d.ts rename src/fp/{zonedTimeToUtcWithOptions => fromZonedTimeWithOptions}/index.js (50%) rename src/fp/{utcToZonedTimeWithOptions => fromZonedTimeWithOptions}/index.js.flow (100%) rename src/{utcToZonedTime => fp/toZonedTime}/index.d.ts (58%) rename src/fp/{utcToZonedTime => toZonedTime}/index.js (55%) rename src/fp/{zonedTimeToUtc => toZonedTime}/index.js.flow (100%) create mode 100644 src/fp/toZonedTimeWithOptions/index.d.ts rename src/fp/{utcToZonedTimeWithOptions => toZonedTimeWithOptions}/index.js (50%) rename src/fp/{zonedTimeToUtcWithOptions => toZonedTimeWithOptions}/index.js.flow (100%) delete mode 100644 src/fp/utcToZonedTimeWithOptions/index.d.ts delete mode 100644 src/fp/zonedTimeToUtcWithOptions/index.d.ts rename src/{zonedTimeToUtc => fromZonedTime}/index.d.ts (58%) rename src/{zonedTimeToUtc => fromZonedTime}/index.js (91%) rename src/{utcToZonedTime => fromZonedTime}/index.js.flow (100%) rename src/{zonedTimeToUtc => fromZonedTime}/test.js (76%) rename src/{fp/zonedTimeToUtc => toZonedTime}/index.d.ts (57%) rename src/{utcToZonedTime => toZonedTime}/index.js (90%) rename src/{zonedTimeToUtc => toZonedTime}/index.js.flow (100%) rename src/{utcToZonedTime => toZonedTime}/test.js (78%) diff --git a/CHANGELOG.md b/CHANGELOG.md index b7c60e0..4d297a8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +### v3.0.0 + +- [BREAKING CHANGE] Rename `utcToZonedTime` to `toZonedTime` +- [BREAKING CHANGE] Rename `zonedTimeToUtc` to `fromZonedTime` + ### v3.0.0-beta.3 (28 March 2024) - [BUGFIX] Fix `date-fns` imports for `fp` by copying the `convertToFP` function diff --git a/README.md b/README.md index 798eb95..e97739b 100644 --- a/README.md +++ b/README.md @@ -34,8 +34,8 @@ This is because an ESM project cannot use ESM imports from a library that doesn' - [`formatInTimeZone`](#formatintimezone) - Formats a date in the provided time zone, regardless of the system time zone - [Time zone offset helpers](#time-zone-offset-helpers) - - [`zonedTimeToUtc`](#zonedtimetoutc) - Given a date and any time zone, returns a `Date` with the equivalent UTC time - - [`utcToZonedTime`](#utctozonedtime) - Get a date/time representing local time in a given time zone from the UTC date + - [`fromZonedTime`](#zonedtimetoutc) - Given a date and any time zone, returns a `Date` with the equivalent UTC time + - [`toZonedTime`](#utctozonedtime) - Get a date/time representing local time in a given time zone from the UTC date - [`getTimezoneOffset`](#gettimezoneoffset) - Gets the offset in milliseconds between the time zone and UTC time - [Low-level formatting helpers](#low-level-formatting-helpers) - [`format`](#format) - Extends `date-fns/format` with support for all time zone tokens, @@ -111,13 +111,14 @@ To discuss the usage of the time zone helpers let's assume we're writing a syste administrators set up events which will start at a specific time in the venue's local time, and this local time should be shown when accessing the site from anywhere in the world. -### `zonedTimeToUtc` +### `fromZonedTime` -Given a date and any time zone, returns a `Date` with the equivalent UTC time. -An invalid date string or time zone will result in an `Invalid Date`. +Given a date and any time zone, returns the equivalent `Date` in the current system time zone +and the equivalent UTC time internally. An invalid date string or time zone will result in +an `Invalid Date`. ```ts -zonedTimeToUtc(date: Date|Number|String, timeZone: String): Date +fromZonedTime(date: Date|Number|String, timeZone: String): Date ``` Say a user is asked to input the date/time and time zone of an event. A date/time picker will @@ -127,23 +128,24 @@ select input might provide the actual IANA time zone name. In order to work with this info effectively it is necessary to find the equivalent UTC time: ```javascript -import { zonedTimeToUtc } from 'date-fns-tz' +import { fromZonedTime } from 'date-fns-tz' const date = getDatePickerValue() // e.g. 2014-06-25 10:00:00 (picked in any time zone) const timeZone = getTimeZoneValue() // e.g. America/Los_Angeles -const utcDate = zonedTimeToUtc(date, timeZone) // In June 10am in Los Angeles is 5pm UTC +const utcDate = fromZonedTime(date, timeZone) // In June 10am in Los Angeles is 5pm UTC postToServer(utcDate.toISOString(), timeZone) // post 2014-06-25T17:00:00.000Z, America/Los_Angeles ``` -### `utcToZonedTime` +### `toZonedTime` -Returns a `Date` which will format as the local time of any time zone from a specific UTC time. -An invalid date string or time zone will result in an `Invalid Date`. +Returns a `Date` which will format as the local time of any time zone from a specific UTC time +or date in the current system time zone. An invalid date string or time zone will result in +an `Invalid Date`. ```js -utcToZonedTime(date: Date|Number|String, timeZone: String): Date +toZonedTime(date: Date|Number|String, timeZone: String): Date ``` Say the server provided a UTC date/time and a time zone which should be used as initial values @@ -151,11 +153,11 @@ for the above form. The date/time picker will take a Date input which will be in local time zone, but the date value must be that of the target time zone. ```javascript -import { utcToZonedTime } from 'date-fns-tz' +import { toZonedTime } from 'date-fns-tz' const { isoDate, timeZone } = fetchInitialValues() // 2014-06-25T10:00:00.000Z, America/New_York -const date = utcToZonedTime(isoDate, timeZone) // In June 10am UTC is 6am in New York (-04:00) +const date = toZonedTime(isoDate, timeZone) // In June 10am UTC is 6am in New York (-04:00) renderDatePicker(date) // 2014-06-25 06:00:00 (in the system time zone) renderTimeZoneSelect(timeZone) // America/New_York @@ -216,21 +218,21 @@ time zone is provided _and included in the output_, i.e. with time zone tokens i string, it will also throw a `RangeError`. To format a date showing time for a specific time zone other than the system time zone, the -`format` function can be combined with `utcToZonedTime`. This is what `formatInTimeZone` does +`format` function can be combined with `toZonedTime`. This is what `formatInTimeZone` does internally. _To clarify, the `format` function will never change the underlying date, it must be changed to a zoned time before passing it to `format`._ In most cases there is no need to use `format` rather than `formatInTimeZone`. The only time -this makes sense is when `utcToZonedTime` has been applied to a date once, and you want to +this makes sense is when `toZonedTime` has been applied to a date once, and you want to format it multiple times to different outputs. ```javascript -import { format, utcToZonedTime } from 'date-fns-tz' +import { format, toZonedTime } from 'date-fns-tz' const date = new Date('2014-10-25T10:46:20Z') -const nyDate = utcToZonedTime(date, 'America/New_York') -const parisDate = utcToZonedTime(date, 'Europe/Paris') +const nyDate = toZonedTime(date, 'America/New_York') +const parisDate = toZonedTime(date, 'Europe/Paris') format(nyDate, 'yyyy-MM-dd HH:mm:ssXXX', { timeZone: 'America/New_York' }) // 2014-10-25 06:46:20-04:00 format(nyDate, 'yyyy-MM-dd HH:mm:ss zzz', { timeZone: 'America/New_York' }) // 2014-10-25 06:46:20 EST @@ -263,7 +265,7 @@ import { toDate, format } from 'date-fns-tz' // Offsets in the date string work as usual and take precedence const parsedDate = toDate('2014-10-25T13:46:20+04:00') -const parisDate = utcToZonedTime(parsedDate, 'Europe/Paris') +const parisDate = toZonedTime(parsedDate, 'Europe/Paris') format(parisDate, 'yyyy-MM-dd HH:mm:ssxxx', { timeZone: 'Europe/Paris' }) // 2014-10-25 11:46:20+02:00 // Since toDate simply clones a Date instance, the timeZone option is effectively ignored in this case @@ -273,32 +275,26 @@ assert(date.valueOf() === clonedDate.valueOf()) // When there is no offset in the date string the timeZone property is used const parsedDate = toDate('2014-10-25T13:46:20', { timeZone: 'Asia/Bangkok' }) -const bangkokDate = utcToZonedTime(parsedDate, 'Asia/Bangkok') +const bangkokDate = toZonedTime(parsedDate, 'Asia/Bangkok') format(bangkokDate, 'yyyy-MM-dd HH:mm:ssxxx', { timeZone: 'Asia/Bangkok' }) // 2014-10-25 13:46:20+07:00 ``` ## Usage with Android -This library works with React Native, however the `Intl` API is not available by default on Android. +This library works with React Native on iOS, and on Android with Hermes which supports +`Intl` by default. -In projects that do not use Hermes, make this change to `android/app/build.gradle`: +In Android projects that do not use Hermes, make this change in `android/app/build.gradle`: ```diff - def jscFlavor = 'org.webkit:android-jsc:+' + def jscFlavor = 'org.webkit:android-jsc-intl:+' ``` -React Native does not currently support `Intl` on Android with -Hermes ([facebook/hermes#23](https://github.com/facebook/hermes/issues/23)). The best bet -seems to be using the [polyfills by Format.JS](https://formatjs.io/docs/polyfills/intl-datetimeformat). - ## Usage with Node.js -Node.js supports the `Intl` API and ships with full ICU data included in the binary from v13, -i.e. this library will just work. - -Node.js v12, which reaches end of life on 30 April 2022, requires running with -[full ICU data provided at runtime](https://nodejs.org/docs/latest-v12.x/api/intl.html#intl_providing_icu_data_at_runtime). +Node.js supports the `Intl` API and ships with full ICU data included in the binary since v13, +so this library works by default. ## Credit diff --git a/package.json b/package.json index f36cc80..caee551 100644 --- a/package.json +++ b/package.json @@ -50,15 +50,15 @@ "import": "./esm/toDate/index.js", "require": "./toDate/index.js" }, - "./utcToZonedTime": { - "types": "./utcToZonedTime/index.d.ts", - "import": "./esm/utcToZonedTime/index.js", - "require": "./utcToZonedTime/index.js" + "./toZonedTime": { + "types": "./toZonedTime/index.d.ts", + "import": "./esm/toZonedTime/index.js", + "require": "./toZonedTime/index.js" }, - "./zonedTimeToUtc": { - "types": "./zonedTimeToUtc/index.d.ts", - "import": "./esm/zonedTimeToUtc/index.js", - "require": "./zonedTimeToUtc/index.js" + "./fromZonedTime": { + "types": "./fromZonedTime/index.d.ts", + "import": "./esm/fromZonedTime/index.js", + "require": "./fromZonedTime/index.js" }, "./fp": { "types": "./fp/index.d.ts", @@ -75,6 +75,26 @@ "import": "./esm/fp/formatInTimeZone/index.js", "require": "./fp/formatInTimeZone/index.js" }, + "./fp/formatInTimeZoneWithOptions": { + "types": "./fp/formatInTimeZoneWithOptions/index.d.ts", + "import": "./esm/fp/formatInTimeZoneWithOptions/index.js", + "require": "./fp/formatInTimeZoneWithOptions/index.js" + }, + "./fp/formatWithOptions": { + "types": "./fp/formatWithOptions/index.d.ts", + "import": "./esm/fp/formatWithOptions/index.js", + "require": "./fp/formatWithOptions/index.js" + }, + "./fp/fromZonedTime": { + "types": "./fp/fromZonedTime/index.d.ts", + "import": "./esm/fp/fromZonedTime/index.js", + "require": "./fp/fromZonedTime/index.js" + }, + "./fp/fromZonedTimeWithOptions": { + "types": "./fp/fromZonedTimeWithOptions/index.d.ts", + "import": "./esm/fp/fromZonedTimeWithOptions/index.js", + "require": "./fp/fromZonedTimeWithOptions/index.js" + }, "./fp/getTimezoneOffset": { "types": "./fp/getTimezoneOffset/index.d.ts", "import": "./esm/fp/getTimezoneOffset/index.js", @@ -85,15 +105,20 @@ "import": "./esm/fp/toDate/index.js", "require": "./fp/toDate/index.js" }, - "./fp/utcToZonedTime": { - "types": "./fp/utcToZonedTime/index.d.ts", - "import": "./esm/fp/utcToZonedTime/index.js", - "require": "./fp/utcToZonedTime/index.js" + "./fp/toDateWithOptions": { + "types": "./fp/toDateWithOptions/index.d.ts", + "import": "./esm/fp/toDateWithOptions/index.js", + "require": "./fp/toDateWithOptions/index.js" + }, + "./fp/toZonedTime": { + "types": "./fp/toZonedTime/index.d.ts", + "import": "./esm/fp/toZonedTime/index.js", + "require": "./fp/toZonedTime/index.js" }, - "./fp/zonedTimeToUtc": { - "types": "./fp/zonedTimeToUtc/index.d.ts", - "import": "./esm/fp/zonedTimeToUtc/index.js", - "require": "./fp/zonedTimeToUtc/index.js" + "./fp/toZonedTimeWithOptions": { + "types": "./fp/toZonedTimeWithOptions/index.d.ts", + "import": "./esm/fp/toZonedTimeWithOptions/index.js", + "require": "./fp/toZonedTimeWithOptions/index.js" } }, "scripts": { diff --git a/src/esm/fp/index.js b/src/esm/fp/index.js index f59557a..bbcddfa 100644 --- a/src/esm/fp/index.js +++ b/src/esm/fp/index.js @@ -4,10 +4,10 @@ export { default as format } from './format/index.js' export { default as formatInTimeZone } from './formatInTimeZone/index.js' export { default as formatInTimeZoneWithOptions } from './formatInTimeZoneWithOptions/index.js' export { default as formatWithOptions } from './formatWithOptions/index.js' +export { default as fromZonedTime } from './fromZonedTime/index.js' +export { default as fromZonedTimeWithOptions } from './fromZonedTimeWithOptions/index.js' export { default as getTimezoneOffset } from './getTimezoneOffset/index.js' export { default as toDate } from './toDate/index.js' export { default as toDateWithOptions } from './toDateWithOptions/index.js' -export { default as utcToZonedTime } from './utcToZonedTime/index.js' -export { default as utcToZonedTimeWithOptions } from './utcToZonedTimeWithOptions/index.js' -export { default as zonedTimeToUtc } from './zonedTimeToUtc/index.js' -export { default as zonedTimeToUtcWithOptions } from './zonedTimeToUtcWithOptions/index.js' +export { default as toZonedTime } from './toZonedTime/index.js' +export { default as toZonedTimeWithOptions } from './toZonedTimeWithOptions/index.js' diff --git a/src/esm/index.js b/src/esm/index.js index 2f73dd1..649cce3 100644 --- a/src/esm/index.js +++ b/src/esm/index.js @@ -2,7 +2,7 @@ export { default as format } from './format/index.js' export { default as formatInTimeZone } from './formatInTimeZone/index.js' +export { default as fromZonedTime } from './fromZonedTime/index.js' export { default as getTimezoneOffset } from './getTimezoneOffset/index.js' export { default as toDate } from './toDate/index.js' -export { default as utcToZonedTime } from './utcToZonedTime/index.js' -export { default as zonedTimeToUtc } from './zonedTimeToUtc/index.js' +export { default as toZonedTime } from './toZonedTime/index.js' diff --git a/src/format/test.js b/src/format/test.js index bea23ea..e5f5f04 100644 --- a/src/format/test.js +++ b/src/format/test.js @@ -4,7 +4,7 @@ import assert from 'power-assert' import format from '.' import { enGB } from 'date-fns/locale/en-GB' -import utcToZonedTime from '../utcToZonedTime' +import toZonedTime from '../toZonedTime' describe('format', function () { var date = new Date(1986, 3 /* Apr */, 4, 10, 32, 55, 123) @@ -672,7 +672,7 @@ describe('format', function () { it('handles quoted text next to a time zone token', function () { var date = '1986-04-04T10:32:55.123Z' var timeZone = 'Europe/Paris' - var result = format(utcToZonedTime(date, timeZone), "dd.MM.yyyy HH:mm 'UTC'xxx", { timeZone }) + var result = format(toZonedTime(date, timeZone), "dd.MM.yyyy HH:mm 'UTC'xxx", { timeZone }) assert(result === '04.04.1986 12:32 UTC+02:00') }) @@ -680,7 +680,7 @@ describe('format', function () { it('https://github.com/marnusw/date-fns-tz/issues/138', () => { const date = new Date('2020-10-31T21:37:02.233-05:00') const timeZone = 'America/Chicago' - const offsetDate = utcToZonedTime(date, timeZone) + const offsetDate = toZonedTime(date, timeZone) const result = format(offsetDate, "yyyy-MM-dd h:mmaaaaa'm' xxx XXX OOO zzz", { timeZone }) assert.equal(result, '2020-10-31 9:37pm -05:00 -05:00 GMT-5 CDT') }) @@ -688,7 +688,7 @@ describe('format', function () { it('https://github.com/marnusw/date-fns-tz/issues/168', () => { const timeZone = 'Europe/Stockholm' const dateInUTC = Date.UTC(1888, 11, 1, 1, 0, 14, 0) - const offsetDate = utcToZonedTime(dateInUTC, timeZone) + const offsetDate = toZonedTime(dateInUTC, timeZone) const result = format(offsetDate, "yyyy-MM-dd'T'HH:mm:ss.SSSxxx", { timeZone }) assert.equal(result, '1888-12-01T01:53:42.000+00:53') }) diff --git a/src/formatInTimeZone/index.js b/src/formatInTimeZone/index.js index 3d9f7bf..060b2a7 100644 --- a/src/formatInTimeZone/index.js +++ b/src/formatInTimeZone/index.js @@ -1,5 +1,5 @@ import format from '../format/index.js' -import utcToZonedTime from '../utcToZonedTime/index.js' +import toZonedTime from '../toZonedTime/index.js' import cloneDeep from 'lodash.clonedeep' /** @@ -28,5 +28,5 @@ export default function formatInTimeZone(date, timeZone, formatStr, options) { var extendedOptions = cloneDeep(options || {}) extendedOptions.timeZone = timeZone extendedOptions.originalDate = date - return format(utcToZonedTime(date, timeZone), formatStr, extendedOptions) + return format(toZonedTime(date, timeZone), formatStr, extendedOptions) } diff --git a/src/fp/utcToZonedTime/index.d.ts b/src/fp/fromZonedTime/index.d.ts similarity index 57% rename from src/fp/utcToZonedTime/index.d.ts rename to src/fp/fromZonedTime/index.d.ts index 7594dc3..4decfc7 100644 --- a/src/fp/utcToZonedTime/index.d.ts +++ b/src/fp/fromZonedTime/index.d.ts @@ -1,4 +1,4 @@ // This file is generated automatically by `scripts/build/typings.js`. Please, don't change it. -import { utcToZonedTime } from 'date-fns-tz/fp' -export = utcToZonedTime +import { fromZonedTime } from 'date-fns-tz/fp' +export = fromZonedTime diff --git a/src/fp/zonedTimeToUtc/index.js b/src/fp/fromZonedTime/index.js similarity index 55% rename from src/fp/zonedTimeToUtc/index.js rename to src/fp/fromZonedTime/index.js index 9fa2d2c..a060eb0 100644 --- a/src/fp/zonedTimeToUtc/index.js +++ b/src/fp/fromZonedTime/index.js @@ -1,8 +1,8 @@ // This file is generated automatically by `scripts/build/fp.js`. Please, don't change it. -import fn from '../../zonedTimeToUtc/index.js' +import fn from '../../fromZonedTime/index.js' import { convertToFP } from '../_lib/convertToFP' -var zonedTimeToUtc = convertToFP(fn, 2) +var fromZonedTime = convertToFP(fn, 2) -export default zonedTimeToUtc +export default fromZonedTime diff --git a/src/fp/utcToZonedTime/index.js.flow b/src/fp/fromZonedTime/index.js.flow similarity index 100% rename from src/fp/utcToZonedTime/index.js.flow rename to src/fp/fromZonedTime/index.js.flow diff --git a/src/fp/fromZonedTimeWithOptions/index.d.ts b/src/fp/fromZonedTimeWithOptions/index.d.ts new file mode 100644 index 0000000..8b65709 --- /dev/null +++ b/src/fp/fromZonedTimeWithOptions/index.d.ts @@ -0,0 +1,4 @@ +// This file is generated automatically by `scripts/build/typings.js`. Please, don't change it. + +import { fromZonedTimeWithOptions } from 'date-fns-tz/fp' +export = fromZonedTimeWithOptions diff --git a/src/fp/zonedTimeToUtcWithOptions/index.js b/src/fp/fromZonedTimeWithOptions/index.js similarity index 50% rename from src/fp/zonedTimeToUtcWithOptions/index.js rename to src/fp/fromZonedTimeWithOptions/index.js index 2688eef..8e8d1b0 100644 --- a/src/fp/zonedTimeToUtcWithOptions/index.js +++ b/src/fp/fromZonedTimeWithOptions/index.js @@ -1,8 +1,8 @@ // This file is generated automatically by `scripts/build/fp.js`. Please, don't change it. -import fn from '../../zonedTimeToUtc/index.js' +import fn from '../../fromZonedTime/index.js' import { convertToFP } from '../_lib/convertToFP' -var zonedTimeToUtcWithOptions = convertToFP(fn, 3) +var fromZonedTimeWithOptions = convertToFP(fn, 3) -export default zonedTimeToUtcWithOptions +export default fromZonedTimeWithOptions diff --git a/src/fp/utcToZonedTimeWithOptions/index.js.flow b/src/fp/fromZonedTimeWithOptions/index.js.flow similarity index 100% rename from src/fp/utcToZonedTimeWithOptions/index.js.flow rename to src/fp/fromZonedTimeWithOptions/index.js.flow diff --git a/src/fp/index.js b/src/fp/index.js index fbc3dbc..3a86187 100644 --- a/src/fp/index.js +++ b/src/fp/index.js @@ -5,11 +5,11 @@ module.exports = { formatInTimeZone: require('./formatInTimeZone/index.js'), formatInTimeZoneWithOptions: require('./formatInTimeZoneWithOptions/index.js'), formatWithOptions: require('./formatWithOptions/index.js'), + fromZonedTime: require('./fromZonedTime/index.js'), + fromZonedTimeWithOptions: require('./fromZonedTimeWithOptions/index.js'), getTimezoneOffset: require('./getTimezoneOffset/index.js'), toDate: require('./toDate/index.js'), toDateWithOptions: require('./toDateWithOptions/index.js'), - utcToZonedTime: require('./utcToZonedTime/index.js'), - utcToZonedTimeWithOptions: require('./utcToZonedTimeWithOptions/index.js'), - zonedTimeToUtc: require('./zonedTimeToUtc/index.js'), - zonedTimeToUtcWithOptions: require('./zonedTimeToUtcWithOptions/index.js'), + toZonedTime: require('./toZonedTime/index.js'), + toZonedTimeWithOptions: require('./toZonedTimeWithOptions/index.js'), } diff --git a/src/fp/index.js.flow b/src/fp/index.js.flow index 56498da..b741c5d 100644 --- a/src/fp/index.js.flow +++ b/src/fp/index.js.flow @@ -53,11 +53,11 @@ declare module.exports: { string >, formatWithOptions: CurriedFn3, + fromZonedTime: CurriedFn2, + fromZonedTimeWithOptions: CurriedFn3, getTimezoneOffset: CurriedFn2, toDate: CurriedFn1, toDateWithOptions: CurriedFn2, - utcToZonedTime: CurriedFn2, - utcToZonedTimeWithOptions: CurriedFn3, - zonedTimeToUtc: CurriedFn2, - zonedTimeToUtcWithOptions: CurriedFn3, + toZonedTime: CurriedFn2, + toZonedTimeWithOptions: CurriedFn3, } diff --git a/src/utcToZonedTime/index.d.ts b/src/fp/toZonedTime/index.d.ts similarity index 58% rename from src/utcToZonedTime/index.d.ts rename to src/fp/toZonedTime/index.d.ts index 1012703..4a6dd20 100644 --- a/src/utcToZonedTime/index.d.ts +++ b/src/fp/toZonedTime/index.d.ts @@ -1,4 +1,4 @@ // This file is generated automatically by `scripts/build/typings.js`. Please, don't change it. -import { utcToZonedTime } from 'date-fns-tz' -export = utcToZonedTime +import { toZonedTime } from 'date-fns-tz/fp' +export = toZonedTime diff --git a/src/fp/utcToZonedTime/index.js b/src/fp/toZonedTime/index.js similarity index 55% rename from src/fp/utcToZonedTime/index.js rename to src/fp/toZonedTime/index.js index 1b970f3..0d2a5a0 100644 --- a/src/fp/utcToZonedTime/index.js +++ b/src/fp/toZonedTime/index.js @@ -1,8 +1,8 @@ // This file is generated automatically by `scripts/build/fp.js`. Please, don't change it. -import fn from '../../utcToZonedTime/index.js' +import fn from '../../toZonedTime/index.js' import { convertToFP } from '../_lib/convertToFP' -var utcToZonedTime = convertToFP(fn, 2) +var toZonedTime = convertToFP(fn, 2) -export default utcToZonedTime +export default toZonedTime diff --git a/src/fp/zonedTimeToUtc/index.js.flow b/src/fp/toZonedTime/index.js.flow similarity index 100% rename from src/fp/zonedTimeToUtc/index.js.flow rename to src/fp/toZonedTime/index.js.flow diff --git a/src/fp/toZonedTimeWithOptions/index.d.ts b/src/fp/toZonedTimeWithOptions/index.d.ts new file mode 100644 index 0000000..20dd09a --- /dev/null +++ b/src/fp/toZonedTimeWithOptions/index.d.ts @@ -0,0 +1,4 @@ +// This file is generated automatically by `scripts/build/typings.js`. Please, don't change it. + +import { toZonedTimeWithOptions } from 'date-fns-tz/fp' +export = toZonedTimeWithOptions diff --git a/src/fp/utcToZonedTimeWithOptions/index.js b/src/fp/toZonedTimeWithOptions/index.js similarity index 50% rename from src/fp/utcToZonedTimeWithOptions/index.js rename to src/fp/toZonedTimeWithOptions/index.js index 5b6a34e..2d56b78 100644 --- a/src/fp/utcToZonedTimeWithOptions/index.js +++ b/src/fp/toZonedTimeWithOptions/index.js @@ -1,8 +1,8 @@ // This file is generated automatically by `scripts/build/fp.js`. Please, don't change it. -import fn from '../../utcToZonedTime/index.js' +import fn from '../../toZonedTime/index.js' import { convertToFP } from '../_lib/convertToFP' -var utcToZonedTimeWithOptions = convertToFP(fn, 3) +var toZonedTimeWithOptions = convertToFP(fn, 3) -export default utcToZonedTimeWithOptions +export default toZonedTimeWithOptions diff --git a/src/fp/zonedTimeToUtcWithOptions/index.js.flow b/src/fp/toZonedTimeWithOptions/index.js.flow similarity index 100% rename from src/fp/zonedTimeToUtcWithOptions/index.js.flow rename to src/fp/toZonedTimeWithOptions/index.js.flow diff --git a/src/fp/utcToZonedTimeWithOptions/index.d.ts b/src/fp/utcToZonedTimeWithOptions/index.d.ts deleted file mode 100644 index b29bb0e..0000000 --- a/src/fp/utcToZonedTimeWithOptions/index.d.ts +++ /dev/null @@ -1,4 +0,0 @@ -// This file is generated automatically by `scripts/build/typings.js`. Please, don't change it. - -import { utcToZonedTimeWithOptions } from 'date-fns-tz/fp' -export = utcToZonedTimeWithOptions diff --git a/src/fp/zonedTimeToUtcWithOptions/index.d.ts b/src/fp/zonedTimeToUtcWithOptions/index.d.ts deleted file mode 100644 index 4b2456d..0000000 --- a/src/fp/zonedTimeToUtcWithOptions/index.d.ts +++ /dev/null @@ -1,4 +0,0 @@ -// This file is generated automatically by `scripts/build/typings.js`. Please, don't change it. - -import { zonedTimeToUtcWithOptions } from 'date-fns-tz/fp' -export = zonedTimeToUtcWithOptions diff --git a/src/zonedTimeToUtc/index.d.ts b/src/fromZonedTime/index.d.ts similarity index 58% rename from src/zonedTimeToUtc/index.d.ts rename to src/fromZonedTime/index.d.ts index 935e206..842f962 100644 --- a/src/zonedTimeToUtc/index.d.ts +++ b/src/fromZonedTime/index.d.ts @@ -1,4 +1,4 @@ // This file is generated automatically by `scripts/build/typings.js`. Please, don't change it. -import { zonedTimeToUtc } from 'date-fns-tz' -export = zonedTimeToUtc +import { fromZonedTime } from 'date-fns-tz' +export = fromZonedTime diff --git a/src/zonedTimeToUtc/index.js b/src/fromZonedTime/index.js similarity index 91% rename from src/zonedTimeToUtc/index.js rename to src/fromZonedTime/index.js index c2ac4e5..f0b51f8 100644 --- a/src/zonedTimeToUtc/index.js +++ b/src/fromZonedTime/index.js @@ -5,7 +5,7 @@ import newDateUTC from '../_lib/newDateUTC/index.js' import cloneDeep from 'lodash.clonedeep' /** - * @name zonedTimeToUtc + * @name fromZonedTime * @category Time Zone Helpers * @summary Get the UTC date/time from a date representing local time in a given time zone * @@ -25,10 +25,10 @@ import cloneDeep from 'lodash.clonedeep' * * @example * // In June 10am in Los Angeles is 5pm UTC - * const result = zonedTimeToUtc(new Date(2014, 5, 25, 10, 0, 0), 'America/Los_Angeles') + * const result = fromZonedTime(new Date(2014, 5, 25, 10, 0, 0), 'America/Los_Angeles') * //=> 2014-06-25T17:00:00.000Z */ -export default function zonedTimeToUtc(date, timeZone, options) { +export default function fromZonedTime(date, timeZone, options) { if (typeof date === 'string' && !date.match(tzPattern)) { var extendedOptions = cloneDeep(options || {}) extendedOptions.timeZone = timeZone diff --git a/src/utcToZonedTime/index.js.flow b/src/fromZonedTime/index.js.flow similarity index 100% rename from src/utcToZonedTime/index.js.flow rename to src/fromZonedTime/index.js.flow diff --git a/src/zonedTimeToUtc/test.js b/src/fromZonedTime/test.js similarity index 76% rename from src/zonedTimeToUtc/test.js rename to src/fromZonedTime/test.js index df10a56..60877c1 100644 --- a/src/zonedTimeToUtc/test.js +++ b/src/fromZonedTime/test.js @@ -1,47 +1,47 @@ import assert from 'power-assert' import format from '../format' -import utcToZonedTime from '../utcToZonedTime' -import zonedTimeToUtc from '.' +import toZonedTime from '../toZonedTime' +import fromZonedTime from '.' -describe('zonedTimeToUtc', function () { +describe('fromZonedTime', function () { it('returns the UTC time of the date in the time zone for a date input and IANA tz', function () { - var result = zonedTimeToUtc(new Date(2014, 5, 25, 10, 0, 0, 123), 'America/Los_Angeles') + var result = fromZonedTime(new Date(2014, 5, 25, 10, 0, 0, 123), 'America/Los_Angeles') assert.deepEqual(result.toISOString(), '2014-06-25T17:00:00.123Z') }) it('returns the UTC time of the date in the time zone for a string and IANA tz', function () { - var result = zonedTimeToUtc('2014-06-25T10:00:00.123', 'America/Los_Angeles') + var result = fromZonedTime('2014-06-25T10:00:00.123', 'America/Los_Angeles') assert.deepEqual(result.toISOString(), '2014-06-25T17:00:00.123Z') }) it('returns the UTC time of the date near DST changeover with IANA tz', function () { - var result = zonedTimeToUtc('2020-10-03T17:00:00.000', 'Australia/Melbourne') + var result = fromZonedTime('2020-10-03T17:00:00.000', 'Australia/Melbourne') assert.deepEqual(result.toISOString(), '2020-10-03T07:00:00.000Z') }) it('returns the UTC time of an ISO8601 string with an IANA tz', function () { let input = new Date(2021, 11, 4, 15, 0, 15, 0) - let result = zonedTimeToUtc(input.toISOString(), 'America/New_York') + let result = fromZonedTime(input.toISOString(), 'America/New_York') assert.deepEqual(result.toISOString(), '2021-12-04T20:00:15.000Z') }) it('returns the UTC time of the date for a UTC input', function () { - var result = zonedTimeToUtc(new Date(2014, 5, 25, 10, 0, 0, 123), 'UTC') + var result = fromZonedTime(new Date(2014, 5, 25, 10, 0, 0, 123), 'UTC') assert.deepEqual(result.toISOString(), '2014-06-25T10:00:00.123Z') }) it('returns the UTC time of the date in the time zone for a date input and tz offset', function () { - var result = zonedTimeToUtc(new Date(2014, 5, 25, 10, 0, 0, 123), '+0400') + var result = fromZonedTime(new Date(2014, 5, 25, 10, 0, 0, 123), '+0400') assert.deepEqual(result.toISOString(), '2014-06-25T06:00:00.123Z') }) it('returns the UTC time of the date in the time zone for a string and tz offset', function () { - var result = zonedTimeToUtc('2014-06-25T10:00:00.123', '-02:00') + var result = fromZonedTime('2014-06-25T10:00:00.123', '-02:00') assert.deepEqual(result.toISOString(), '2014-06-25T12:00:00.123Z') }) it('returns the UTC time of the date for the Z tz', function () { - var result = zonedTimeToUtc(new Date(2014, 5, 25, 10, 0, 0, 123), 'Z') + var result = fromZonedTime(new Date(2014, 5, 25, 10, 0, 0, 123), 'Z') assert.deepEqual(result.toISOString(), '2014-06-25T10:00:00.123Z') }) @@ -49,18 +49,18 @@ describe('zonedTimeToUtc', function () { var input = new Date(0) input.setFullYear(99, 0, 1) input.setHours(10, 0, 0, 0) - var result = zonedTimeToUtc(input, 'Europe/Berlin') + var result = fromZonedTime(input, 'Europe/Berlin') assert.deepEqual(result.toISOString(), '0099-01-01T09:06:32.000Z') }) it('works with years < 100 (string input)', function () { - var result = zonedTimeToUtc('0099-01-01', 'Europe/Berlin') + var result = fromZonedTime('0099-01-01', 'Europe/Berlin') assert.deepEqual(result.toISOString(), '0098-12-31T23:06:32.000Z') }) describe('near DST changeover (AEST to AEDT)', function () { it('zoned time one day before', function () { - var result = zonedTimeToUtc( + var result = fromZonedTime( new Date('2020-10-03T17:00:00.000'), 'Australia/Melbourne' // +10 hours ) @@ -69,7 +69,7 @@ describe('zonedTimeToUtc', function () { }) it('zoned time less than one day before', function () { - var result = zonedTimeToUtc( + var result = fromZonedTime( new Date('2020-10-03T21:00:00.000'), 'Australia/Melbourne' // +10 hours ) @@ -78,7 +78,7 @@ describe('zonedTimeToUtc', function () { }) it('zoned time some time before', function () { - var result = zonedTimeToUtc( + var result = fromZonedTime( new Date('2020-10-03T23:45:00.000'), 'Australia/Melbourne' // +10 hours ) @@ -87,7 +87,7 @@ describe('zonedTimeToUtc', function () { }) it('zoned time at the stroke of midnight before', function () { - var result = zonedTimeToUtc( + var result = fromZonedTime( new Date('2020-10-04T00:00:00.000'), 'Australia/Melbourne' // +10 hours ) @@ -96,7 +96,7 @@ describe('zonedTimeToUtc', function () { }) it('zoned time 1 hour 15 minutes before', function () { - var result = zonedTimeToUtc( + var result = fromZonedTime( new Date('2020-10-04T00:45:00.000'), 'Australia/Melbourne' // +10 hours ) @@ -105,7 +105,7 @@ describe('zonedTimeToUtc', function () { }) it('zoned time 15 minutes before', function () { - var result = zonedTimeToUtc( + var result = fromZonedTime( new Date('2020-10-04T01:45:00.000'), 'Australia/Melbourne' // +10 hours ) @@ -114,7 +114,7 @@ describe('zonedTimeToUtc', function () { }) it('zoned time 15 minutes after', function () { - var result = zonedTimeToUtc( + var result = fromZonedTime( new Date('2020-10-04T03:15:00.000'), 'Australia/Melbourne' // +11 hours ) @@ -123,7 +123,7 @@ describe('zonedTimeToUtc', function () { }) it('zoned time 1 hour 15 minutes after', function () { - var result = zonedTimeToUtc( + var result = fromZonedTime( new Date('2020-10-04T04:15:00.000'), 'Australia/Melbourne' // +11 hours ) @@ -132,7 +132,7 @@ describe('zonedTimeToUtc', function () { }) it('zoned time one day after', function () { - var result = zonedTimeToUtc( + var result = fromZonedTime( new Date('2020-10-04T11:00:00.000'), 'Australia/Melbourne' // +11 hours ) @@ -141,14 +141,14 @@ describe('zonedTimeToUtc', function () { }) it('accepts the Etc/GMT+n time zone format', function () { - var result1 = zonedTimeToUtc('2019-11-26T10:00:00', 'America/Chicago') - var result2 = zonedTimeToUtc('2019-11-26T10:00:00', 'Etc/GMT+6') + var result1 = fromZonedTime('2019-11-26T10:00:00', 'America/Chicago') + var result2 = fromZonedTime('2019-11-26T10:00:00', 'Etc/GMT+6') assert.deepEqual(result1, result2) }) it('finds first time after clock jumps back: -ve UTC offset', function () { - var result = zonedTimeToUtc('2023-11-05T02:00:00', 'America/New_York') + var result = fromZonedTime('2023-11-05T02:00:00', 'America/New_York') // UTC 05:59 is NY 01:59 GMT -4 // UTC 06:00 is NY 01:00 GMT -5 // therefore the first time NY local 02:00 is struck is UTC 07:00 @@ -156,7 +156,7 @@ describe('zonedTimeToUtc', function () { }) it('finds first time after clock jumps back: +ve UTC offset', function () { - var result = zonedTimeToUtc('2023-04-02T03:00:00', 'Australia/Sydney') + var result = fromZonedTime('2023-04-02T03:00:00', 'Australia/Sydney') // UTC 15:59 is SYD 02:59 GMT +11 // UTC 16:00 is SYD 02:00 GMT +10 // therefore the first time SYD local 03:00 is struck is UTC 17:00 @@ -166,7 +166,7 @@ describe('zonedTimeToUtc', function () { // todo Results differ for time zones before and after UTC it.skip('handles times that repeat when clock jump back: -ve UTC offset', function () { // at 02:00 local clock jumps back 1 hour so 01:00 occurs twice - var result = zonedTimeToUtc('2023-11-05T01:00:00', 'America/New_York') + var result = fromZonedTime('2023-11-05T01:00:00', 'America/New_York') // UTC 05:00 is NY 01:00 GMT -4 // UTC 06:00 is NY 01:00 GMT -5 // this implementation picks the later occurrence of 01:00 @ UTC 06:00 @@ -175,7 +175,7 @@ describe('zonedTimeToUtc', function () { it('handles times that repeat when clock jump back: +ve UTC offset', function () { // at 03:00 local clock jumps back 1 hour so 02:00 occurs twice - var result = zonedTimeToUtc('2023-04-02T02:00:00', 'Australia/Sydney') + var result = fromZonedTime('2023-04-02T02:00:00', 'Australia/Sydney') // UTC 15:00 is SYD 02:00 GMT +11 // UTC 16:00 is SYD 02:00 GMT +10 // this implementation picks the later occurrence of 02:00 @ UTC 16:00 @@ -185,7 +185,7 @@ describe('zonedTimeToUtc', function () { // utc: 2023-09-30T16:00:00.000Z SYD: 03:00 GMT+11 it('handles times that dont exist with clock jump forward: -ve UTC offset', function () { // at 02:00 local clock will immediately jump forward to 03:00 - var result = zonedTimeToUtc('2023-03-12T02:00:00', 'America/New_York') + var result = fromZonedTime('2023-03-12T02:00:00', 'America/New_York') // UTC 06:59 is NY 01:59 GMT -5 // UTC 07:00 is NY 03:00 GMT -4 // !! this is an error - should either throw error OR return UTC 07:00 @@ -195,7 +195,7 @@ describe('zonedTimeToUtc', function () { it('handles times that dont exist with clock jump forward: +ve UTC offset', function () { // at 02:00 local clock will immediately jump forward to 03:00 - var result = zonedTimeToUtc('2023-10-01T02:00:00', 'Australia/Sydney') + var result = fromZonedTime('2023-10-01T02:00:00', 'Australia/Sydney') // UTC 15:59 is SYD 01:59 GMT +10 // UTC 16:00 is SYD 03:00 GMT +11 // !! this is an error - should either throw error OR return UTC 16:00 @@ -204,58 +204,58 @@ describe('zonedTimeToUtc', function () { }) }) - describe('zonedTimeToUtc and utcToZonedTime are inverse functions', function () { + describe('fromZonedTime and toZonedTime are inverse functions', function () { it('date strings without a time zone specifier', function () { var timeZone = 'America/Chicago' var input = '2019-11-26T10:00:00' - var result = utcToZonedTime(zonedTimeToUtc(input, timeZone), timeZone) + var result = toZonedTime(fromZonedTime(input, timeZone), timeZone) assert.deepEqual(format(result, "yyyy-MM-dd'T'HH:mm:ss"), input) }) it('a Date instance', function () { var timeZone = 'Etc/GMT+6' var input = new Date('2019-11-26T10:00:00Z') - var result = utcToZonedTime(zonedTimeToUtc(input, timeZone), timeZone) + var result = toZonedTime(fromZonedTime(input, timeZone), timeZone) assert.deepEqual(result, input) }) it('date string with Z time zone specifier', function () { var timeZone = 'Europe/Paris' var input = '2019-11-26T10:00:00Z' - var result = utcToZonedTime(zonedTimeToUtc(input, timeZone), timeZone) + var result = toZonedTime(fromZonedTime(input, timeZone), timeZone) assert.deepEqual(result, new Date('2019-11-26T10:00:00Z')) }) it('date string with a positive time zone offset specifier', function () { var timeZone = 'Australia/Melbourne' var input = '2019-11-26T10:00:00+02:00' - var result = utcToZonedTime(zonedTimeToUtc(input, timeZone), timeZone) + var result = toZonedTime(fromZonedTime(input, timeZone), timeZone) assert.deepEqual(result, new Date('2019-11-26T10:00:00+02:00')) }) it('when the time zone is UTC', function () { var timeZone = 'UTC' var input = '2019-11-26T10:00:00Z' - var result = utcToZonedTime(zonedTimeToUtc(input, timeZone), timeZone) + var result = toZonedTime(fromZonedTime(input, timeZone), timeZone) assert.deepEqual(result, new Date('2019-11-26T10:00:00Z')) }) }) describe('invalid date and time zone handling', function () { it('returns an invalid date when the date string is invalid without tz info', function () { - var result = zonedTimeToUtc('2020-01-01T25:00:00.000', 'Europe/London') + var result = fromZonedTime('2020-01-01T25:00:00.000', 'Europe/London') assert(result instanceof Date) assert(isNaN(result)) }) it('returns an invalid date when the date string is invalid with tz info', function () { - var result = zonedTimeToUtc('2020-01-01T25:00:00.000Z', 'Europe/London') + var result = fromZonedTime('2020-01-01T25:00:00.000Z', 'Europe/London') assert(result instanceof Date) assert(isNaN(result)) }) it('returns an invalid date when the time zone is invalid', function () { - var result = zonedTimeToUtc('2020-01-01T12:00:00.000Z', 'bad/timezone') + var result = fromZonedTime('2020-01-01T12:00:00.000Z', 'bad/timezone') assert(result instanceof Date) assert(isNaN(result)) }) diff --git a/src/index.js b/src/index.js index a5ddc97..2f231c6 100644 --- a/src/index.js +++ b/src/index.js @@ -3,8 +3,8 @@ module.exports = { format: require('./format/index.js'), formatInTimeZone: require('./formatInTimeZone/index.js'), + fromZonedTime: require('./fromZonedTime/index.js'), getTimezoneOffset: require('./getTimezoneOffset/index.js'), toDate: require('./toDate/index.js'), - utcToZonedTime: require('./utcToZonedTime/index.js'), - zonedTimeToUtc: require('./zonedTimeToUtc/index.js'), + toZonedTime: require('./toZonedTime/index.js'), } diff --git a/src/index.js.flow b/src/index.js.flow index 2b35878..de9a79b 100644 --- a/src/index.js.flow +++ b/src/index.js.flow @@ -27,11 +27,11 @@ declare module.exports: { options?: OptionsWithTZ ) => string, + fromZonedTime: (date: Date | string | number, timeZone: string, options?: OptionsWithTZ) => Date, + getTimezoneOffset: (timeZone: string, date?: Date | number) => number, toDate: (argument: Date | string | number, options?: OptionsWithTZ) => Date, - utcToZonedTime: (date: Date | string | number, timeZone: string, options?: OptionsWithTZ) => Date, - - zonedTimeToUtc: (date: Date | string | number, timeZone: string, options?: OptionsWithTZ) => Date, + toZonedTime: (date: Date | string | number, timeZone: string, options?: OptionsWithTZ) => Date, } diff --git a/src/fp/zonedTimeToUtc/index.d.ts b/src/toZonedTime/index.d.ts similarity index 57% rename from src/fp/zonedTimeToUtc/index.d.ts rename to src/toZonedTime/index.d.ts index 1e9b8e7..f92f5bb 100644 --- a/src/fp/zonedTimeToUtc/index.d.ts +++ b/src/toZonedTime/index.d.ts @@ -1,4 +1,4 @@ // This file is generated automatically by `scripts/build/typings.js`. Please, don't change it. -import { zonedTimeToUtc } from 'date-fns-tz/fp' -export = zonedTimeToUtc +import { toZonedTime } from 'date-fns-tz' +export = toZonedTime diff --git a/src/utcToZonedTime/index.js b/src/toZonedTime/index.js similarity index 90% rename from src/utcToZonedTime/index.js rename to src/toZonedTime/index.js index 9bded9e..eb4d99d 100644 --- a/src/utcToZonedTime/index.js +++ b/src/toZonedTime/index.js @@ -2,7 +2,7 @@ import tzParseTimezone from '../_lib/tzParseTimezone/index.js' import toDate from '../toDate/index.js' /** - * @name utcToZonedTime + * @name toZonedTime * @category Time Zone Helpers * @summary Get a date/time representing local time in a given time zone from the UTC date * @@ -22,10 +22,10 @@ import toDate from '../toDate/index.js' * * @example * // In June 10am UTC is 6am in New York (-04:00) - * const result = utcToZonedTime('2014-06-25T10:00:00.000Z', 'America/New_York') + * const result = toZonedTime('2014-06-25T10:00:00.000Z', 'America/New_York') * //=> Jun 25 2014 06:00:00 */ -export default function utcToZonedTime(dirtyDate, timeZone, options) { +export default function toZonedTime(dirtyDate, timeZone, options) { var date = toDate(dirtyDate, options) var offsetMilliseconds = tzParseTimezone(timeZone, date, true) diff --git a/src/zonedTimeToUtc/index.js.flow b/src/toZonedTime/index.js.flow similarity index 100% rename from src/zonedTimeToUtc/index.js.flow rename to src/toZonedTime/index.js.flow diff --git a/src/utcToZonedTime/test.js b/src/toZonedTime/test.js similarity index 78% rename from src/utcToZonedTime/test.js rename to src/toZonedTime/test.js index d8df9c3..8beb6ca 100644 --- a/src/utcToZonedTime/test.js +++ b/src/toZonedTime/test.js @@ -1,41 +1,41 @@ import assert from 'power-assert' import { format } from 'date-fns/format' -import utcToZonedTime from '.' +import toZonedTime from '.' import newDateUTC from '../_lib/newDateUTC' -describe('utcToZonedTime', function () { +describe('toZonedTime', function () { it('returns the equivalent date at the time zone for a date string and IANA tz', function () { - var result = utcToZonedTime('2014-06-25T10:00:00.123Z', 'America/New_York') + var result = toZonedTime('2014-06-25T10:00:00.123Z', 'America/New_York') assert.equal(format(result, "yyyy-MM-dd'T'HH:mm:ss.SSS"), '2014-06-25T06:00:00.123') }) it('returns the equivalent date at the time zone for a date instance and IANA tz', function () { - var result = utcToZonedTime(new Date('2014-06-25T10:00:00.123Z'), 'Europe/Paris') + var result = toZonedTime(new Date('2014-06-25T10:00:00.123Z'), 'Europe/Paris') assert.equal(format(result, "yyyy-MM-dd'T'HH:mm:ss.SSS"), '2014-06-25T12:00:00.123') }) it('returns the same date/time for UTC', function () { - var result = utcToZonedTime('2014-06-25T10:00:00.123Z', 'UTC') + var result = toZonedTime('2014-06-25T10:00:00.123Z', 'UTC') assert.equal(format(result, "yyyy-MM-dd'T'HH:mm:ss.SSS"), '2014-06-25T10:00:00.123') }) it('returns the equivalent date at the time zone for a date string and tz offset', function () { - var result = utcToZonedTime('2014-06-25T10:00:00.123Z', '-04:00') + var result = toZonedTime('2014-06-25T10:00:00.123Z', '-04:00') assert.equal(format(result, "yyyy-MM-dd'T'HH:mm:ss.SSS"), '2014-06-25T06:00:00.123') }) it('returns the equivalent date at the time zone for a date instance and tz offset', function () { - var result = utcToZonedTime(new Date('2014-06-25T10:00:00.123Z'), '+0200') + var result = toZonedTime(new Date('2014-06-25T10:00:00.123Z'), '+0200') assert.equal(format(result, "yyyy-MM-dd'T'HH:mm:ss.SSS"), '2014-06-25T12:00:00.123') }) it('returns the same date/time for Z', function () { - var result = utcToZonedTime('2014-06-25T10:00:00.123Z', 'Z') + var result = toZonedTime('2014-06-25T10:00:00.123Z', 'Z') assert.equal(format(result, "yyyy-MM-dd'T'HH:mm:ss.SSS"), '2014-06-25T10:00:00.123') }) it('does not wrap to the following day when the result is midnight', function () { - var result = utcToZonedTime( + var result = toZonedTime( new Date('Thu Jan 23 2020 05:00:00 GMT+0000 (Greenwich Mean Time)'), 'America/New_York' // -5 hours ) @@ -44,7 +44,7 @@ describe('utcToZonedTime', function () { it('returns the correct date/time during time change', function () { // zoned time one day behind - var resultPDT = utcToZonedTime( + var resultPDT = toZonedTime( new Date('Sun Nov 1 2020 06:45:00 GMT-0000 (Greenwich Mean Time)'), 'America/Los_Angeles' // -7 hours ) @@ -52,7 +52,7 @@ describe('utcToZonedTime', function () { assert.equal(format(resultPDT, "yyyy-MM-dd'T'HH:mm:ss.SSS"), '2020-10-31T23:45:00.000') // 15 mins before time switch - resultPDT = utcToZonedTime( + resultPDT = toZonedTime( new Date('Sun Nov 1 2020 08:45:00 GMT-0000 (Greenwich Mean Time)'), 'America/Los_Angeles' // -7 hours ) @@ -60,7 +60,7 @@ describe('utcToZonedTime', function () { assert.equal(format(resultPDT, "yyyy-MM-dd'T'HH:mm:ss.SSS"), '2020-11-01T01:45:00.000') // 15 mins after time switch - var resultPST = utcToZonedTime( + var resultPST = toZonedTime( new Date('Sun Nov 1 2020 09:45:00 GMT-0000 (Greenwich Mean Time)'), 'America/Los_Angeles' // -8 hours ) @@ -70,12 +70,12 @@ describe('utcToZonedTime', function () { it('works in specific time zones', function () { var timeZone = 'America/Vancouver' - var result = utcToZonedTime('2020-03-08T19:00:00.000Z', timeZone) + var result = toZonedTime('2020-03-08T19:00:00.000Z', timeZone) assert.equal(format(result, 'yyyy-MM-dd hh:mm:ss.SSS'), '2020-03-08 12:00:00.000') }) it('https://github.com/marnusw/date-fns-tz/issues/53', function () { - const f = (date) => format(utcToZonedTime(new Date(date), 'UTC'), 'yyyy-MM-dd HH:mm:ss.SSS') + const f = (date) => format(toZonedTime(new Date(date), 'UTC'), 'yyyy-MM-dd HH:mm:ss.SSS') assert.equal(f('2020-02-19T18:59:59.999-0500'), '2020-02-19 23:59:59.999') // assert.equal(f('2020-02-19T19:00:00.000-0500'), '2020-02-20 00:00:00.000') assert.equal(f('2020-02-19T19:59:59.999-0500'), '2020-02-20 00:59:59.999') @@ -85,7 +85,7 @@ describe('utcToZonedTime', function () { describe('year < 100', () => { it('works with string input', () => { var timeZone = 'Europe/Berlin' - var result = utcToZonedTime('0021-03-08T19:00:00.000Z', timeZone) + var result = toZonedTime('0021-03-08T19:00:00.000Z', timeZone) /* time zone for Europe/Berlin is UTC +0:53:28 for dates before 1800 see https://www.timeanddate.com/time/zone/germany/berlin?syear=1800 @@ -97,7 +97,7 @@ describe('utcToZonedTime', function () { var input = newDateUTC(21, 2, 8, 19, 0, 0, 0, 0) var timeZone = 'Europe/Berlin' - var result = utcToZonedTime(input, timeZone) + var result = toZonedTime(input, timeZone) /* time zone for Europe/Berlin is UTC +0:53:28 for dates before 1800 see https://www.timeanddate.com/time/zone/germany/berlin?syear=1800 @@ -108,19 +108,19 @@ describe('utcToZonedTime', function () { describe('invalid date and time zone handling', function () { it('returns an invalid date when the date string is invalid without tz info', function () { - var result = utcToZonedTime('2020-03-08T25:00:00.000', 'bad/timeZone') + var result = toZonedTime('2020-03-08T25:00:00.000', 'bad/timeZone') assert(result instanceof Date) assert(isNaN(result)) }) it('returns an invalid date when the date string is invalid with tz info', function () { - var result = utcToZonedTime('2020-03-08T25:00:00.000Z', 'bad/timeZone') + var result = toZonedTime('2020-03-08T25:00:00.000Z', 'bad/timeZone') assert(result instanceof Date) assert(isNaN(result)) }) it('returns an invalid date when the time zone is invalid', function () { - var result = utcToZonedTime('2020-03-08T19:00:00.000Z', 'bad/timeZone') + var result = toZonedTime('2020-03-08T19:00:00.000Z', 'bad/timeZone') assert(result instanceof Date) assert(isNaN(result)) }) diff --git a/typings.d.ts b/typings.d.ts index 17dfbb5..893bddd 100644 --- a/typings.d.ts +++ b/typings.d.ts @@ -58,25 +58,25 @@ declare module 'date-fns-tz' { ): string namespace formatInTimeZone {} + function fromZonedTime( + date: Date | string | number, + timeZone: string, + options?: OptionsWithTZ + ): Date + namespace fromZonedTime {} + function getTimezoneOffset(timeZone: string, date?: Date | number): number namespace getTimezoneOffset {} function toDate(argument: Date | string | number, options?: OptionsWithTZ): Date namespace toDate {} - function utcToZonedTime( + function toZonedTime( date: Date | string | number, timeZone: string, options?: OptionsWithTZ ): Date - namespace utcToZonedTime {} - - function zonedTimeToUtc( - date: Date | string | number, - timeZone: string, - options?: OptionsWithTZ - ): Date - namespace zonedTimeToUtc {} + namespace toZonedTime {} } declare module 'date-fns-tz/format' { @@ -89,6 +89,11 @@ declare module 'date-fns-tz/formatInTimeZone' { export = formatInTimeZone } +declare module 'date-fns-tz/fromZonedTime' { + import { fromZonedTime } from 'date-fns-tz' + export = fromZonedTime +} + declare module 'date-fns-tz/getTimezoneOffset' { import { getTimezoneOffset } from 'date-fns-tz' export = getTimezoneOffset @@ -99,14 +104,9 @@ declare module 'date-fns-tz/toDate' { export = toDate } -declare module 'date-fns-tz/utcToZonedTime' { - import { utcToZonedTime } from 'date-fns-tz' - export = utcToZonedTime -} - -declare module 'date-fns-tz/zonedTimeToUtc' { - import { zonedTimeToUtc } from 'date-fns-tz' - export = zonedTimeToUtc +declare module 'date-fns-tz/toZonedTime' { + import { toZonedTime } from 'date-fns-tz' + export = toZonedTime } declare module 'date-fns-tz/format/index' { @@ -119,6 +119,11 @@ declare module 'date-fns-tz/formatInTimeZone/index' { export = formatInTimeZone } +declare module 'date-fns-tz/fromZonedTime/index' { + import { fromZonedTime } from 'date-fns-tz' + export = fromZonedTime +} + declare module 'date-fns-tz/getTimezoneOffset/index' { import { getTimezoneOffset } from 'date-fns-tz' export = getTimezoneOffset @@ -129,14 +134,9 @@ declare module 'date-fns-tz/toDate/index' { export = toDate } -declare module 'date-fns-tz/utcToZonedTime/index' { - import { utcToZonedTime } from 'date-fns-tz' - export = utcToZonedTime -} - -declare module 'date-fns-tz/zonedTimeToUtc/index' { - import { zonedTimeToUtc } from 'date-fns-tz' - export = zonedTimeToUtc +declare module 'date-fns-tz/toZonedTime/index' { + import { toZonedTime } from 'date-fns-tz' + export = toZonedTime } declare module 'date-fns-tz/format/index.js' { @@ -149,6 +149,11 @@ declare module 'date-fns-tz/formatInTimeZone/index.js' { export = formatInTimeZone } +declare module 'date-fns-tz/fromZonedTime/index.js' { + import { fromZonedTime } from 'date-fns-tz' + export = fromZonedTime +} + declare module 'date-fns-tz/getTimezoneOffset/index.js' { import { getTimezoneOffset } from 'date-fns-tz' export = getTimezoneOffset @@ -159,14 +164,9 @@ declare module 'date-fns-tz/toDate/index.js' { export = toDate } -declare module 'date-fns-tz/utcToZonedTime/index.js' { - import { utcToZonedTime } from 'date-fns-tz' - export = utcToZonedTime -} - -declare module 'date-fns-tz/zonedTimeToUtc/index.js' { - import { zonedTimeToUtc } from 'date-fns-tz' - export = zonedTimeToUtc +declare module 'date-fns-tz/toZonedTime/index.js' { + import { toZonedTime } from 'date-fns-tz' + export = toZonedTime } // FP Functions @@ -192,6 +192,12 @@ declare module 'date-fns-tz/fp' { const formatWithOptions: CurriedFn3 namespace formatWithOptions {} + const fromZonedTime: CurriedFn2 + namespace fromZonedTime {} + + const fromZonedTimeWithOptions: CurriedFn3 + namespace fromZonedTimeWithOptions {} + const getTimezoneOffset: CurriedFn2 namespace getTimezoneOffset {} @@ -201,17 +207,11 @@ declare module 'date-fns-tz/fp' { const toDateWithOptions: CurriedFn2 namespace toDateWithOptions {} - const utcToZonedTime: CurriedFn2 - namespace utcToZonedTime {} - - const utcToZonedTimeWithOptions: CurriedFn3 - namespace utcToZonedTimeWithOptions {} + const toZonedTime: CurriedFn2 + namespace toZonedTime {} - const zonedTimeToUtc: CurriedFn2 - namespace zonedTimeToUtc {} - - const zonedTimeToUtcWithOptions: CurriedFn3 - namespace zonedTimeToUtcWithOptions {} + const toZonedTimeWithOptions: CurriedFn3 + namespace toZonedTimeWithOptions {} } declare module 'date-fns-tz/fp/format' { @@ -234,6 +234,16 @@ declare module 'date-fns-tz/fp/formatWithOptions' { export = formatWithOptions } +declare module 'date-fns-tz/fp/fromZonedTime' { + import { fromZonedTime } from 'date-fns-tz/fp' + export = fromZonedTime +} + +declare module 'date-fns-tz/fp/fromZonedTimeWithOptions' { + import { fromZonedTimeWithOptions } from 'date-fns-tz/fp' + export = fromZonedTimeWithOptions +} + declare module 'date-fns-tz/fp/getTimezoneOffset' { import { getTimezoneOffset } from 'date-fns-tz/fp' export = getTimezoneOffset @@ -249,24 +259,14 @@ declare module 'date-fns-tz/fp/toDateWithOptions' { export = toDateWithOptions } -declare module 'date-fns-tz/fp/utcToZonedTime' { - import { utcToZonedTime } from 'date-fns-tz/fp' - export = utcToZonedTime -} - -declare module 'date-fns-tz/fp/utcToZonedTimeWithOptions' { - import { utcToZonedTimeWithOptions } from 'date-fns-tz/fp' - export = utcToZonedTimeWithOptions +declare module 'date-fns-tz/fp/toZonedTime' { + import { toZonedTime } from 'date-fns-tz/fp' + export = toZonedTime } -declare module 'date-fns-tz/fp/zonedTimeToUtc' { - import { zonedTimeToUtc } from 'date-fns-tz/fp' - export = zonedTimeToUtc -} - -declare module 'date-fns-tz/fp/zonedTimeToUtcWithOptions' { - import { zonedTimeToUtcWithOptions } from 'date-fns-tz/fp' - export = zonedTimeToUtcWithOptions +declare module 'date-fns-tz/fp/toZonedTimeWithOptions' { + import { toZonedTimeWithOptions } from 'date-fns-tz/fp' + export = toZonedTimeWithOptions } declare module 'date-fns-tz/fp/format/index' { @@ -289,6 +289,16 @@ declare module 'date-fns-tz/fp/formatWithOptions/index' { export = formatWithOptions } +declare module 'date-fns-tz/fp/fromZonedTime/index' { + import { fromZonedTime } from 'date-fns-tz/fp' + export = fromZonedTime +} + +declare module 'date-fns-tz/fp/fromZonedTimeWithOptions/index' { + import { fromZonedTimeWithOptions } from 'date-fns-tz/fp' + export = fromZonedTimeWithOptions +} + declare module 'date-fns-tz/fp/getTimezoneOffset/index' { import { getTimezoneOffset } from 'date-fns-tz/fp' export = getTimezoneOffset @@ -304,24 +314,14 @@ declare module 'date-fns-tz/fp/toDateWithOptions/index' { export = toDateWithOptions } -declare module 'date-fns-tz/fp/utcToZonedTime/index' { - import { utcToZonedTime } from 'date-fns-tz/fp' - export = utcToZonedTime +declare module 'date-fns-tz/fp/toZonedTime/index' { + import { toZonedTime } from 'date-fns-tz/fp' + export = toZonedTime } -declare module 'date-fns-tz/fp/utcToZonedTimeWithOptions/index' { - import { utcToZonedTimeWithOptions } from 'date-fns-tz/fp' - export = utcToZonedTimeWithOptions -} - -declare module 'date-fns-tz/fp/zonedTimeToUtc/index' { - import { zonedTimeToUtc } from 'date-fns-tz/fp' - export = zonedTimeToUtc -} - -declare module 'date-fns-tz/fp/zonedTimeToUtcWithOptions/index' { - import { zonedTimeToUtcWithOptions } from 'date-fns-tz/fp' - export = zonedTimeToUtcWithOptions +declare module 'date-fns-tz/fp/toZonedTimeWithOptions/index' { + import { toZonedTimeWithOptions } from 'date-fns-tz/fp' + export = toZonedTimeWithOptions } declare module 'date-fns-tz/fp/format/index.js' { @@ -344,6 +344,16 @@ declare module 'date-fns-tz/fp/formatWithOptions/index.js' { export = formatWithOptions } +declare module 'date-fns-tz/fp/fromZonedTime/index.js' { + import { fromZonedTime } from 'date-fns-tz/fp' + export = fromZonedTime +} + +declare module 'date-fns-tz/fp/fromZonedTimeWithOptions/index.js' { + import { fromZonedTimeWithOptions } from 'date-fns-tz/fp' + export = fromZonedTimeWithOptions +} + declare module 'date-fns-tz/fp/getTimezoneOffset/index.js' { import { getTimezoneOffset } from 'date-fns-tz/fp' export = getTimezoneOffset @@ -359,24 +369,14 @@ declare module 'date-fns-tz/fp/toDateWithOptions/index.js' { export = toDateWithOptions } -declare module 'date-fns-tz/fp/utcToZonedTime/index.js' { - import { utcToZonedTime } from 'date-fns-tz/fp' - export = utcToZonedTime -} - -declare module 'date-fns-tz/fp/utcToZonedTimeWithOptions/index.js' { - import { utcToZonedTimeWithOptions } from 'date-fns-tz/fp' - export = utcToZonedTimeWithOptions -} - -declare module 'date-fns-tz/fp/zonedTimeToUtc/index.js' { - import { zonedTimeToUtc } from 'date-fns-tz/fp' - export = zonedTimeToUtc +declare module 'date-fns-tz/fp/toZonedTime/index.js' { + import { toZonedTime } from 'date-fns-tz/fp' + export = toZonedTime } -declare module 'date-fns-tz/fp/zonedTimeToUtcWithOptions/index.js' { - import { zonedTimeToUtcWithOptions } from 'date-fns-tz/fp' - export = zonedTimeToUtcWithOptions +declare module 'date-fns-tz/fp/toZonedTimeWithOptions/index.js' { + import { toZonedTimeWithOptions } from 'date-fns-tz/fp' + export = toZonedTimeWithOptions } // ECMAScript Module Functions @@ -395,25 +395,25 @@ declare module 'date-fns-tz/esm' { ): string namespace formatInTimeZone {} + function fromZonedTime( + date: Date | string | number, + timeZone: string, + options?: OptionsWithTZ + ): Date + namespace fromZonedTime {} + function getTimezoneOffset(timeZone: string, date?: Date | number): number namespace getTimezoneOffset {} function toDate(argument: Date | string | number, options?: OptionsWithTZ): Date namespace toDate {} - function utcToZonedTime( + function toZonedTime( date: Date | string | number, timeZone: string, options?: OptionsWithTZ ): Date - namespace utcToZonedTime {} - - function zonedTimeToUtc( - date: Date | string | number, - timeZone: string, - options?: OptionsWithTZ - ): Date - namespace zonedTimeToUtc {} + namespace toZonedTime {} } declare module 'date-fns-tz/esm/format' { @@ -426,6 +426,11 @@ declare module 'date-fns-tz/esm/formatInTimeZone' { export default formatInTimeZone } +declare module 'date-fns-tz/esm/fromZonedTime' { + import { fromZonedTime } from 'date-fns-tz/esm' + export default fromZonedTime +} + declare module 'date-fns-tz/esm/getTimezoneOffset' { import { getTimezoneOffset } from 'date-fns-tz/esm' export default getTimezoneOffset @@ -436,14 +441,9 @@ declare module 'date-fns-tz/esm/toDate' { export default toDate } -declare module 'date-fns-tz/esm/utcToZonedTime' { - import { utcToZonedTime } from 'date-fns-tz/esm' - export default utcToZonedTime -} - -declare module 'date-fns-tz/esm/zonedTimeToUtc' { - import { zonedTimeToUtc } from 'date-fns-tz/esm' - export default zonedTimeToUtc +declare module 'date-fns-tz/esm/toZonedTime' { + import { toZonedTime } from 'date-fns-tz/esm' + export default toZonedTime } declare module 'date-fns-tz/esm/format/index' { @@ -456,6 +456,11 @@ declare module 'date-fns-tz/esm/formatInTimeZone/index' { export default formatInTimeZone } +declare module 'date-fns-tz/esm/fromZonedTime/index' { + import { fromZonedTime } from 'date-fns-tz/esm' + export default fromZonedTime +} + declare module 'date-fns-tz/esm/getTimezoneOffset/index' { import { getTimezoneOffset } from 'date-fns-tz/esm' export default getTimezoneOffset @@ -466,14 +471,9 @@ declare module 'date-fns-tz/esm/toDate/index' { export default toDate } -declare module 'date-fns-tz/esm/utcToZonedTime/index' { - import { utcToZonedTime } from 'date-fns-tz/esm' - export default utcToZonedTime -} - -declare module 'date-fns-tz/esm/zonedTimeToUtc/index' { - import { zonedTimeToUtc } from 'date-fns-tz/esm' - export default zonedTimeToUtc +declare module 'date-fns-tz/esm/toZonedTime/index' { + import { toZonedTime } from 'date-fns-tz/esm' + export default toZonedTime } declare module 'date-fns-tz/esm/format/index.js' { @@ -486,6 +486,11 @@ declare module 'date-fns-tz/esm/formatInTimeZone/index.js' { export default formatInTimeZone } +declare module 'date-fns-tz/esm/fromZonedTime/index.js' { + import { fromZonedTime } from 'date-fns-tz/esm' + export default fromZonedTime +} + declare module 'date-fns-tz/esm/getTimezoneOffset/index.js' { import { getTimezoneOffset } from 'date-fns-tz/esm' export default getTimezoneOffset @@ -496,14 +501,9 @@ declare module 'date-fns-tz/esm/toDate/index.js' { export default toDate } -declare module 'date-fns-tz/esm/utcToZonedTime/index.js' { - import { utcToZonedTime } from 'date-fns-tz/esm' - export default utcToZonedTime -} - -declare module 'date-fns-tz/esm/zonedTimeToUtc/index.js' { - import { zonedTimeToUtc } from 'date-fns-tz/esm' - export default zonedTimeToUtc +declare module 'date-fns-tz/esm/toZonedTime/index.js' { + import { toZonedTime } from 'date-fns-tz/esm' + export default toZonedTime } // ECMAScript Module FP Functions @@ -529,6 +529,12 @@ declare module 'date-fns-tz/esm/fp' { const formatWithOptions: CurriedFn3 namespace formatWithOptions {} + const fromZonedTime: CurriedFn2 + namespace fromZonedTime {} + + const fromZonedTimeWithOptions: CurriedFn3 + namespace fromZonedTimeWithOptions {} + const getTimezoneOffset: CurriedFn2 namespace getTimezoneOffset {} @@ -538,17 +544,11 @@ declare module 'date-fns-tz/esm/fp' { const toDateWithOptions: CurriedFn2 namespace toDateWithOptions {} - const utcToZonedTime: CurriedFn2 - namespace utcToZonedTime {} - - const utcToZonedTimeWithOptions: CurriedFn3 - namespace utcToZonedTimeWithOptions {} + const toZonedTime: CurriedFn2 + namespace toZonedTime {} - const zonedTimeToUtc: CurriedFn2 - namespace zonedTimeToUtc {} - - const zonedTimeToUtcWithOptions: CurriedFn3 - namespace zonedTimeToUtcWithOptions {} + const toZonedTimeWithOptions: CurriedFn3 + namespace toZonedTimeWithOptions {} } declare module 'date-fns-tz/esm/fp/format' { @@ -571,6 +571,16 @@ declare module 'date-fns-tz/esm/fp/formatWithOptions' { export default formatWithOptions } +declare module 'date-fns-tz/esm/fp/fromZonedTime' { + import { fromZonedTime } from 'date-fns-tz/esm/fp' + export default fromZonedTime +} + +declare module 'date-fns-tz/esm/fp/fromZonedTimeWithOptions' { + import { fromZonedTimeWithOptions } from 'date-fns-tz/esm/fp' + export default fromZonedTimeWithOptions +} + declare module 'date-fns-tz/esm/fp/getTimezoneOffset' { import { getTimezoneOffset } from 'date-fns-tz/esm/fp' export default getTimezoneOffset @@ -586,24 +596,14 @@ declare module 'date-fns-tz/esm/fp/toDateWithOptions' { export default toDateWithOptions } -declare module 'date-fns-tz/esm/fp/utcToZonedTime' { - import { utcToZonedTime } from 'date-fns-tz/esm/fp' - export default utcToZonedTime -} - -declare module 'date-fns-tz/esm/fp/utcToZonedTimeWithOptions' { - import { utcToZonedTimeWithOptions } from 'date-fns-tz/esm/fp' - export default utcToZonedTimeWithOptions +declare module 'date-fns-tz/esm/fp/toZonedTime' { + import { toZonedTime } from 'date-fns-tz/esm/fp' + export default toZonedTime } -declare module 'date-fns-tz/esm/fp/zonedTimeToUtc' { - import { zonedTimeToUtc } from 'date-fns-tz/esm/fp' - export default zonedTimeToUtc -} - -declare module 'date-fns-tz/esm/fp/zonedTimeToUtcWithOptions' { - import { zonedTimeToUtcWithOptions } from 'date-fns-tz/esm/fp' - export default zonedTimeToUtcWithOptions +declare module 'date-fns-tz/esm/fp/toZonedTimeWithOptions' { + import { toZonedTimeWithOptions } from 'date-fns-tz/esm/fp' + export default toZonedTimeWithOptions } declare module 'date-fns-tz/esm/fp/format/index' { @@ -626,6 +626,16 @@ declare module 'date-fns-tz/esm/fp/formatWithOptions/index' { export default formatWithOptions } +declare module 'date-fns-tz/esm/fp/fromZonedTime/index' { + import { fromZonedTime } from 'date-fns-tz/esm/fp' + export default fromZonedTime +} + +declare module 'date-fns-tz/esm/fp/fromZonedTimeWithOptions/index' { + import { fromZonedTimeWithOptions } from 'date-fns-tz/esm/fp' + export default fromZonedTimeWithOptions +} + declare module 'date-fns-tz/esm/fp/getTimezoneOffset/index' { import { getTimezoneOffset } from 'date-fns-tz/esm/fp' export default getTimezoneOffset @@ -641,24 +651,14 @@ declare module 'date-fns-tz/esm/fp/toDateWithOptions/index' { export default toDateWithOptions } -declare module 'date-fns-tz/esm/fp/utcToZonedTime/index' { - import { utcToZonedTime } from 'date-fns-tz/esm/fp' - export default utcToZonedTime +declare module 'date-fns-tz/esm/fp/toZonedTime/index' { + import { toZonedTime } from 'date-fns-tz/esm/fp' + export default toZonedTime } -declare module 'date-fns-tz/esm/fp/utcToZonedTimeWithOptions/index' { - import { utcToZonedTimeWithOptions } from 'date-fns-tz/esm/fp' - export default utcToZonedTimeWithOptions -} - -declare module 'date-fns-tz/esm/fp/zonedTimeToUtc/index' { - import { zonedTimeToUtc } from 'date-fns-tz/esm/fp' - export default zonedTimeToUtc -} - -declare module 'date-fns-tz/esm/fp/zonedTimeToUtcWithOptions/index' { - import { zonedTimeToUtcWithOptions } from 'date-fns-tz/esm/fp' - export default zonedTimeToUtcWithOptions +declare module 'date-fns-tz/esm/fp/toZonedTimeWithOptions/index' { + import { toZonedTimeWithOptions } from 'date-fns-tz/esm/fp' + export default toZonedTimeWithOptions } declare module 'date-fns-tz/esm/fp/format/index.js' { @@ -681,6 +681,16 @@ declare module 'date-fns-tz/esm/fp/formatWithOptions/index.js' { export default formatWithOptions } +declare module 'date-fns-tz/esm/fp/fromZonedTime/index.js' { + import { fromZonedTime } from 'date-fns-tz/esm/fp' + export default fromZonedTime +} + +declare module 'date-fns-tz/esm/fp/fromZonedTimeWithOptions/index.js' { + import { fromZonedTimeWithOptions } from 'date-fns-tz/esm/fp' + export default fromZonedTimeWithOptions +} + declare module 'date-fns-tz/esm/fp/getTimezoneOffset/index.js' { import { getTimezoneOffset } from 'date-fns-tz/esm/fp' export default getTimezoneOffset @@ -696,22 +706,12 @@ declare module 'date-fns-tz/esm/fp/toDateWithOptions/index.js' { export default toDateWithOptions } -declare module 'date-fns-tz/esm/fp/utcToZonedTime/index.js' { - import { utcToZonedTime } from 'date-fns-tz/esm/fp' - export default utcToZonedTime -} - -declare module 'date-fns-tz/esm/fp/utcToZonedTimeWithOptions/index.js' { - import { utcToZonedTimeWithOptions } from 'date-fns-tz/esm/fp' - export default utcToZonedTimeWithOptions -} - -declare module 'date-fns-tz/esm/fp/zonedTimeToUtc/index.js' { - import { zonedTimeToUtc } from 'date-fns-tz/esm/fp' - export default zonedTimeToUtc +declare module 'date-fns-tz/esm/fp/toZonedTime/index.js' { + import { toZonedTime } from 'date-fns-tz/esm/fp' + export default toZonedTime } -declare module 'date-fns-tz/esm/fp/zonedTimeToUtcWithOptions/index.js' { - import { zonedTimeToUtcWithOptions } from 'date-fns-tz/esm/fp' - export default zonedTimeToUtcWithOptions +declare module 'date-fns-tz/esm/fp/toZonedTimeWithOptions/index.js' { + import { toZonedTimeWithOptions } from 'date-fns-tz/esm/fp' + export default toZonedTimeWithOptions } From 7ae003b6eb98390b298ca474fb6afbd524b489d1 Mon Sep 17 00:00:00 2001 From: Marnus Weststrate Date: Sat, 30 Mar 2024 22:10:10 +0000 Subject: [PATCH 02/10] Remove flow support --- .flowconfig | 4 - CHANGELOG.md | 1 + package.json | 1 - scripts/_lib/listFPFns.js | 2 +- scripts/_lib/listFns.js | 2 +- scripts/build/_lib/typings/flow.js | 137 ------------------ scripts/build/_lib/typings/formatBlock.js | 18 --- scripts/build/package.sh | 3 - scripts/build/typings.js | 4 +- src/format/index.js.flow | 20 --- src/format/test.js | 1 - src/formatInTimeZone/index.js.flow | 25 ---- src/fp/_lib/convertToFP/test.js | 1 - src/fp/format/index.js.flow | 24 --- src/fp/formatInTimeZone/index.js.flow | 30 ---- .../formatInTimeZoneWithOptions/index.js.flow | 45 ------ src/fp/formatWithOptions/index.js.flow | 30 ---- src/fp/fromZonedTime/index.js.flow | 24 --- src/fp/fromZonedTimeWithOptions/index.js.flow | 30 ---- src/fp/getTimezoneOffset/index.js.flow | 24 --- src/fp/index.js.flow | 63 -------- src/fp/toDate/index.js.flow | 22 --- src/fp/toDateWithOptions/index.js.flow | 24 --- src/fp/toZonedTime/index.js.flow | 24 --- src/fp/toZonedTimeWithOptions/index.js.flow | 30 ---- src/fromZonedTime/index.js.flow | 24 --- src/getTimezoneOffset/index.js.flow | 20 --- src/index.js.flow | 37 ----- src/toDate/index.js.flow | 20 --- src/toZonedTime/index.js.flow | 24 --- yarn.lock | 10 -- 31 files changed, 4 insertions(+), 720 deletions(-) delete mode 100644 .flowconfig delete mode 100644 scripts/build/_lib/typings/flow.js delete mode 100644 src/format/index.js.flow delete mode 100644 src/formatInTimeZone/index.js.flow delete mode 100644 src/fp/format/index.js.flow delete mode 100644 src/fp/formatInTimeZone/index.js.flow delete mode 100644 src/fp/formatInTimeZoneWithOptions/index.js.flow delete mode 100644 src/fp/formatWithOptions/index.js.flow delete mode 100644 src/fp/fromZonedTime/index.js.flow delete mode 100644 src/fp/fromZonedTimeWithOptions/index.js.flow delete mode 100644 src/fp/getTimezoneOffset/index.js.flow delete mode 100644 src/fp/index.js.flow delete mode 100644 src/fp/toDate/index.js.flow delete mode 100644 src/fp/toDateWithOptions/index.js.flow delete mode 100644 src/fp/toZonedTime/index.js.flow delete mode 100644 src/fp/toZonedTimeWithOptions/index.js.flow delete mode 100644 src/fromZonedTime/index.js.flow delete mode 100644 src/getTimezoneOffset/index.js.flow delete mode 100644 src/index.js.flow delete mode 100644 src/toDate/index.js.flow delete mode 100644 src/toZonedTime/index.js.flow diff --git a/.flowconfig b/.flowconfig deleted file mode 100644 index aa9fec0..0000000 --- a/.flowconfig +++ /dev/null @@ -1,4 +0,0 @@ -[ignore] -.*examples* -[options] -suppress_comment= \\(.\\|\n\\)*\\$ExpectedMistake diff --git a/CHANGELOG.md b/CHANGELOG.md index 4d297a8..1a550d1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ - [BREAKING CHANGE] Rename `utcToZonedTime` to `toZonedTime` - [BREAKING CHANGE] Rename `zonedTimeToUtc` to `fromZonedTime` +- [BREAKING CHANGE] Remove `flow` support ### v3.0.0-beta.3 (28 March 2024) diff --git a/package.json b/package.json index caee551..4de5f7d 100644 --- a/package.json +++ b/package.json @@ -165,7 +165,6 @@ "date-fns": "^3.0.6", "eslint": "^7.11.0", "eslint-config-prettier": "^7.2.0", - "flow-bin": "^0.143.1", "fs-promise": "^2.0.3", "husky": "^4.3.0", "jsdoc-to-markdown": "^7.0.1", diff --git a/scripts/_lib/listFPFns.js b/scripts/_lib/listFPFns.js index e34d8b2..7d39672 100644 --- a/scripts/_lib/listFPFns.js +++ b/scripts/_lib/listFPFns.js @@ -3,7 +3,7 @@ const fs = require('fs') module.exports = listFPFns -const ignoredFiles = ['index.js', 'test.js', 'index.js.flow', 'package.json'] +const ignoredFiles = ['index.js', 'test.js', 'package.json'] function listFPFns() { const files = fs.readdirSync(path.join(process.cwd(), 'src', 'fp')) diff --git a/scripts/_lib/listFns.js b/scripts/_lib/listFns.js index 44d4271..9b70f83 100644 --- a/scripts/_lib/listFns.js +++ b/scripts/_lib/listFns.js @@ -3,7 +3,7 @@ const fs = require('fs') module.exports = listFns -const ignoredFiles = ['locale', 'esm', 'fp', 'index.js', 'test.js', 'index.js.flow', 'package.json'] +const ignoredFiles = ['locale', 'esm', 'fp', 'index.js', 'test.js', 'package.json'] function listFns() { const files = fs.readdirSync(path.join(process.cwd(), 'src')) diff --git a/scripts/build/_lib/typings/flow.js b/scripts/build/_lib/typings/flow.js deleted file mode 100644 index 68b2076..0000000 --- a/scripts/build/_lib/typings/flow.js +++ /dev/null @@ -1,137 +0,0 @@ -const fs = require('fs') -const path = require('path') -const prettier = require('../prettier') - -const { getParams, getType, getFPFnType } = require('./common') - -const { addSeparator, formatBlock, formatFlowFile } = require('./formatBlock') - -/** - * Return curried function type aliases for a specific FP function arity. - * @param {Number} [arity=4] - */ -const getFlowFPTypeAliases = (arity = 4) => - [ - 'type CurriedFn1 = (a: A) => R', - - formatBlock` - type CurriedFn2 = (a: A) => CurriedFn1 - | (a: A, b: B) => R - `, - - formatBlock` - type CurriedFn3 = (a: A) => CurriedFn2 - | (a: A, b: B) => CurriedFn1 - | (a: A, b: B, c: C) => R - `, - - formatBlock` - type CurriedFn4 = (a: A) => CurriedFn3 - | (a: A, b: B) => CurriedFn2 - | (a: A, b: B, c: C) => CurriedFn1 - | (a: A, b: B, c: C, d: D) => R - `, - ].slice(0, arity) - -function getFlowTypeAlias(type) { - const { title, properties } = type - return `type ${title} = ${getParams(properties)}` -} - -function generateFlowFnTyping(fn, aliasDeclarations) { - const { title, args, content } = fn - - const params = getParams(args, { leftBorder: '(', rightBorder: ')' }) - const returns = getType(content.returns[0].type.names) - - const moduleDeclaration = `declare module.exports: ${params} => ${returns}` - - const typingFile = formatFlowFile` - ${addSeparator(aliasDeclarations, '\n')} - - ${moduleDeclaration} - ` - - writeFile(`src/${title}/index.js.flow`, typingFile) -} - -function generateFlowFnIndexTyping(fns, aliasDeclarations) { - const fnsDeclarations = fns.map(({ title, args, content }) => { - const params = getParams(args, { leftBorder: '(', rightBorder: ')' }) - const returns = getType(content.returns[0].type.names) - return `${title}: ${params} => ${returns}` - }) - - const typingFile = formatFlowFile` - ${addSeparator(aliasDeclarations, '\n')} - - declare module.exports: { - ${addSeparator(fnsDeclarations, ',\n')} - } - ` - - writeFile(`src/index.js.flow`, typingFile) -} - -function generateFlowFPFnTyping(fn, aliasDeclarations) { - const { title, args, content } = fn - - const type = getFPFnType(args, content.returns[0].type.names) - - const typingFile = formatFlowFile` - ${addSeparator(aliasDeclarations, '\n')} - - ${addSeparator(getFlowFPTypeAliases(args.length), '\n')} - - declare module.exports: ${type} - ` - - writeFile(`src/fp/${title}/index.js.flow`, typingFile) -} - -function generateFlowFPFnIndexTyping(fns, aliasDeclarations) { - const fnsDeclarations = fns.map( - ({ title, args, content }) => `${title}: ${getFPFnType(args, content.returns[0].type.names)}` - ) - - const typingFile = formatFlowFile` - ${addSeparator(aliasDeclarations, '\n')} - - ${addSeparator(getFlowFPTypeAliases(), '\n')} - - declare module.exports: { - ${addSeparator(fnsDeclarations, ',')} - } - ` - - writeFile(`src/fp/index.js.flow`, typingFile) -} - -function generateFlowTypings(fns, aliases) { - const aliasDeclarations = aliases.map(getFlowTypeAlias) - - fns.forEach((fn) => { - if (fn.isFPFn) { - generateFlowFPFnTyping(fn, aliasDeclarations) - } else { - generateFlowFnTyping(fn, aliasDeclarations) - } - }) - - generateFlowFnIndexTyping( - fns.filter(({ isFPFn }) => !isFPFn), - aliasDeclarations - ) - generateFlowFPFnIndexTyping( - fns.filter(({ isFPFn }) => isFPFn), - aliasDeclarations - ) -} - -function writeFile(relativePath, content) { - return fs.writeFileSync(path.resolve(process.cwd(), relativePath), prettier(content, 'flow')) -} - -module.exports = { - generateFlowTypings, -} diff --git a/scripts/build/_lib/typings/formatBlock.js b/scripts/build/_lib/typings/formatBlock.js index 53828c7..036a164 100644 --- a/scripts/build/_lib/typings/formatBlock.js +++ b/scripts/build/_lib/typings/formatBlock.js @@ -1,4 +1,3 @@ -const flowHeader = '// @flow' const generatedAutomaticallyMessage = "// This file is generated automatically by `scripts/build/typings.js`. Please, don't change it." @@ -100,22 +99,6 @@ const formatBlock = (rawStrings, ...substitutions) => { return result } -/** - * Tag function that formats a Flow file by putting the correct indentation, header and footer to it - * @param {String[]} rawStrings - * @param {...String} substitutions - * @returns {String} formatted file content - */ -const formatFlowFile = (...args) => - flowHeader + - '\n' + - generatedAutomaticallyMessage + - '\n\n' + - "import type { Day, FirstWeekContainsDate, Locale, LocaleUnit, RoundingMethod } from 'date-fns'\n" + - '\n\n' + - formatBlock(...args) + - '\n' - /** * Tag function that formats a TypeScript file by putting the correct indentation, header and footer to it * @param {String[]} rawStrings @@ -128,6 +111,5 @@ const formatTypeScriptFile = (...args) => module.exports = { addSeparator, formatBlock, - formatFlowFile, formatTypeScriptFile, } diff --git a/scripts/build/package.sh b/scripts/build/package.sh index 2135462..1b68c42 100755 --- a/scripts/build/package.sh +++ b/scripts/build/package.sh @@ -38,9 +38,6 @@ do cp -r "./src/$fnDir" "$dir/esm/" done -# Copy global flow typing -cp ./src/index.js.flow "$dir/esm/index.js.flow" - # Copy esm indices cp ./src/esm/index.js "$dir/esm/index.js" cp ./src/esm/fp/index.js "$dir/esm/fp/index.js" diff --git a/scripts/build/typings.js b/scripts/build/typings.js index ee3481b..0f781b0 100755 --- a/scripts/build/typings.js +++ b/scripts/build/typings.js @@ -2,7 +2,7 @@ /** * @file - * The script generates Flow and TypeScript typing files. + * The script generates TypeScript typing files. * * It's a part of the build process. */ @@ -11,7 +11,6 @@ const path = require('path') const jsDocs = require(path.resolve(process.cwd(), 'tmp/docs.json')) const { generateTypeScriptTypings } = require('./_lib/typings/typeScript') -const { generateFlowTypings } = require('./_lib/typings/flow') const fns = Object.keys(jsDocs) .map((category) => jsDocs[category]) @@ -22,4 +21,3 @@ const fns = Object.keys(jsDocs) const aliases = jsDocs['Types'] generateTypeScriptTypings(fns, aliases, []) -generateFlowTypings(fns, aliases) diff --git a/src/format/index.js.flow b/src/format/index.js.flow deleted file mode 100644 index 65766ac..0000000 --- a/src/format/index.js.flow +++ /dev/null @@ -1,20 +0,0 @@ -// @flow -// This file is generated automatically by `scripts/build/typings.js`. Please, don't change it. - -import type { Day, FirstWeekContainsDate, Locale, LocaleUnit, RoundingMethod } from 'date-fns' - -type OptionsWithTZ = { - weekStartsOn?: Day, - firstWeekContainsDate?: FirstWeekContainsDate, - additionalDigits?: 0 | 1 | 2, - timeZone?: string, - originalDate?: Date | number, - locale?: Locale, - includeSeconds?: boolean, - addSuffix?: boolean, - unit?: LocaleUnit, - roundingMethod?: RoundingMethod, - awareOfUnicodeTokens?: boolean, -} - -declare module.exports: (date: Date | number, format: string, options?: OptionsWithTZ) => string diff --git a/src/format/test.js b/src/format/test.js index e5f5f04..59e68ba 100644 --- a/src/format/test.js +++ b/src/format/test.js @@ -1,4 +1,3 @@ -// @flow /* eslint-env mocha */ import assert from 'power-assert' diff --git a/src/formatInTimeZone/index.js.flow b/src/formatInTimeZone/index.js.flow deleted file mode 100644 index 5e588c1..0000000 --- a/src/formatInTimeZone/index.js.flow +++ /dev/null @@ -1,25 +0,0 @@ -// @flow -// This file is generated automatically by `scripts/build/typings.js`. Please, don't change it. - -import type { Day, FirstWeekContainsDate, Locale, LocaleUnit, RoundingMethod } from 'date-fns' - -type OptionsWithTZ = { - weekStartsOn?: Day, - firstWeekContainsDate?: FirstWeekContainsDate, - additionalDigits?: 0 | 1 | 2, - timeZone?: string, - originalDate?: Date | number, - locale?: Locale, - includeSeconds?: boolean, - addSuffix?: boolean, - unit?: LocaleUnit, - roundingMethod?: RoundingMethod, - awareOfUnicodeTokens?: boolean, -} - -declare module.exports: ( - date: Date | string | number, - timeZone: string, - formatStr: string, - options?: OptionsWithTZ -) => string diff --git a/src/fp/_lib/convertToFP/test.js b/src/fp/_lib/convertToFP/test.js index 8e03be3..6ee1b81 100644 --- a/src/fp/_lib/convertToFP/test.js +++ b/src/fp/_lib/convertToFP/test.js @@ -1,4 +1,3 @@ -// @flow /* eslint-env mocha */ import assert from 'power-assert' import { convertToFP } from '.' diff --git a/src/fp/format/index.js.flow b/src/fp/format/index.js.flow deleted file mode 100644 index 4ee3b88..0000000 --- a/src/fp/format/index.js.flow +++ /dev/null @@ -1,24 +0,0 @@ -// @flow -// This file is generated automatically by `scripts/build/typings.js`. Please, don't change it. - -import type { Day, FirstWeekContainsDate, Locale, LocaleUnit, RoundingMethod } from 'date-fns' - -type OptionsWithTZ = { - weekStartsOn?: Day, - firstWeekContainsDate?: FirstWeekContainsDate, - additionalDigits?: 0 | 1 | 2, - timeZone?: string, - originalDate?: Date | number, - locale?: Locale, - includeSeconds?: boolean, - addSuffix?: boolean, - unit?: LocaleUnit, - roundingMethod?: RoundingMethod, - awareOfUnicodeTokens?: boolean, -} - -type CurriedFn1 = (a: A) => R - -type CurriedFn2 = (a: A) => CurriedFn1 | ((a: A, b: B) => R) - -declare module.exports: CurriedFn2 diff --git a/src/fp/formatInTimeZone/index.js.flow b/src/fp/formatInTimeZone/index.js.flow deleted file mode 100644 index 609f2b3..0000000 --- a/src/fp/formatInTimeZone/index.js.flow +++ /dev/null @@ -1,30 +0,0 @@ -// @flow -// This file is generated automatically by `scripts/build/typings.js`. Please, don't change it. - -import type { Day, FirstWeekContainsDate, Locale, LocaleUnit, RoundingMethod } from 'date-fns' - -type OptionsWithTZ = { - weekStartsOn?: Day, - firstWeekContainsDate?: FirstWeekContainsDate, - additionalDigits?: 0 | 1 | 2, - timeZone?: string, - originalDate?: Date | number, - locale?: Locale, - includeSeconds?: boolean, - addSuffix?: boolean, - unit?: LocaleUnit, - roundingMethod?: RoundingMethod, - awareOfUnicodeTokens?: boolean, -} - -type CurriedFn1 = (a: A) => R - -type CurriedFn2 = (a: A) => CurriedFn1 | ((a: A, b: B) => R) - -type CurriedFn3 = ( - a: A -) => - | CurriedFn2 - | ((a: A, b: B) => CurriedFn1 | ((a: A, b: B, c: C) => R)) - -declare module.exports: CurriedFn3 diff --git a/src/fp/formatInTimeZoneWithOptions/index.js.flow b/src/fp/formatInTimeZoneWithOptions/index.js.flow deleted file mode 100644 index 4fb627d..0000000 --- a/src/fp/formatInTimeZoneWithOptions/index.js.flow +++ /dev/null @@ -1,45 +0,0 @@ -// @flow -// This file is generated automatically by `scripts/build/typings.js`. Please, don't change it. - -import type { Day, FirstWeekContainsDate, Locale, LocaleUnit, RoundingMethod } from 'date-fns' - -type OptionsWithTZ = { - weekStartsOn?: Day, - firstWeekContainsDate?: FirstWeekContainsDate, - additionalDigits?: 0 | 1 | 2, - timeZone?: string, - originalDate?: Date | number, - locale?: Locale, - includeSeconds?: boolean, - addSuffix?: boolean, - unit?: LocaleUnit, - roundingMethod?: RoundingMethod, - awareOfUnicodeTokens?: boolean, -} - -type CurriedFn1 = (a: A) => R - -type CurriedFn2 = (a: A) => CurriedFn1 | ((a: A, b: B) => R) - -type CurriedFn3 = ( - a: A -) => - | CurriedFn2 - | ((a: A, b: B) => CurriedFn1 | ((a: A, b: B, c: C) => R)) - -type CurriedFn4 = ( - a: A -) => - | CurriedFn3 - | (( - a: A, - b: B - ) => - | CurriedFn2 - | (( - a: A, - b: B, - c: C - ) => CurriedFn1 | ((a: A, b: B, c: C, d: D) => R))) - -declare module.exports: CurriedFn4 diff --git a/src/fp/formatWithOptions/index.js.flow b/src/fp/formatWithOptions/index.js.flow deleted file mode 100644 index 092c7b1..0000000 --- a/src/fp/formatWithOptions/index.js.flow +++ /dev/null @@ -1,30 +0,0 @@ -// @flow -// This file is generated automatically by `scripts/build/typings.js`. Please, don't change it. - -import type { Day, FirstWeekContainsDate, Locale, LocaleUnit, RoundingMethod } from 'date-fns' - -type OptionsWithTZ = { - weekStartsOn?: Day, - firstWeekContainsDate?: FirstWeekContainsDate, - additionalDigits?: 0 | 1 | 2, - timeZone?: string, - originalDate?: Date | number, - locale?: Locale, - includeSeconds?: boolean, - addSuffix?: boolean, - unit?: LocaleUnit, - roundingMethod?: RoundingMethod, - awareOfUnicodeTokens?: boolean, -} - -type CurriedFn1 = (a: A) => R - -type CurriedFn2 = (a: A) => CurriedFn1 | ((a: A, b: B) => R) - -type CurriedFn3 = ( - a: A -) => - | CurriedFn2 - | ((a: A, b: B) => CurriedFn1 | ((a: A, b: B, c: C) => R)) - -declare module.exports: CurriedFn3 diff --git a/src/fp/fromZonedTime/index.js.flow b/src/fp/fromZonedTime/index.js.flow deleted file mode 100644 index e81728f..0000000 --- a/src/fp/fromZonedTime/index.js.flow +++ /dev/null @@ -1,24 +0,0 @@ -// @flow -// This file is generated automatically by `scripts/build/typings.js`. Please, don't change it. - -import type { Day, FirstWeekContainsDate, Locale, LocaleUnit, RoundingMethod } from 'date-fns' - -type OptionsWithTZ = { - weekStartsOn?: Day, - firstWeekContainsDate?: FirstWeekContainsDate, - additionalDigits?: 0 | 1 | 2, - timeZone?: string, - originalDate?: Date | number, - locale?: Locale, - includeSeconds?: boolean, - addSuffix?: boolean, - unit?: LocaleUnit, - roundingMethod?: RoundingMethod, - awareOfUnicodeTokens?: boolean, -} - -type CurriedFn1 = (a: A) => R - -type CurriedFn2 = (a: A) => CurriedFn1 | ((a: A, b: B) => R) - -declare module.exports: CurriedFn2 diff --git a/src/fp/fromZonedTimeWithOptions/index.js.flow b/src/fp/fromZonedTimeWithOptions/index.js.flow deleted file mode 100644 index aa17bd2..0000000 --- a/src/fp/fromZonedTimeWithOptions/index.js.flow +++ /dev/null @@ -1,30 +0,0 @@ -// @flow -// This file is generated automatically by `scripts/build/typings.js`. Please, don't change it. - -import type { Day, FirstWeekContainsDate, Locale, LocaleUnit, RoundingMethod } from 'date-fns' - -type OptionsWithTZ = { - weekStartsOn?: Day, - firstWeekContainsDate?: FirstWeekContainsDate, - additionalDigits?: 0 | 1 | 2, - timeZone?: string, - originalDate?: Date | number, - locale?: Locale, - includeSeconds?: boolean, - addSuffix?: boolean, - unit?: LocaleUnit, - roundingMethod?: RoundingMethod, - awareOfUnicodeTokens?: boolean, -} - -type CurriedFn1 = (a: A) => R - -type CurriedFn2 = (a: A) => CurriedFn1 | ((a: A, b: B) => R) - -type CurriedFn3 = ( - a: A -) => - | CurriedFn2 - | ((a: A, b: B) => CurriedFn1 | ((a: A, b: B, c: C) => R)) - -declare module.exports: CurriedFn3 diff --git a/src/fp/getTimezoneOffset/index.js.flow b/src/fp/getTimezoneOffset/index.js.flow deleted file mode 100644 index ab329f9..0000000 --- a/src/fp/getTimezoneOffset/index.js.flow +++ /dev/null @@ -1,24 +0,0 @@ -// @flow -// This file is generated automatically by `scripts/build/typings.js`. Please, don't change it. - -import type { Day, FirstWeekContainsDate, Locale, LocaleUnit, RoundingMethod } from 'date-fns' - -type OptionsWithTZ = { - weekStartsOn?: Day, - firstWeekContainsDate?: FirstWeekContainsDate, - additionalDigits?: 0 | 1 | 2, - timeZone?: string, - originalDate?: Date | number, - locale?: Locale, - includeSeconds?: boolean, - addSuffix?: boolean, - unit?: LocaleUnit, - roundingMethod?: RoundingMethod, - awareOfUnicodeTokens?: boolean, -} - -type CurriedFn1 = (a: A) => R - -type CurriedFn2 = (a: A) => CurriedFn1 | ((a: A, b: B) => R) - -declare module.exports: CurriedFn2 diff --git a/src/fp/index.js.flow b/src/fp/index.js.flow deleted file mode 100644 index b741c5d..0000000 --- a/src/fp/index.js.flow +++ /dev/null @@ -1,63 +0,0 @@ -// @flow -// This file is generated automatically by `scripts/build/typings.js`. Please, don't change it. - -import type { Day, FirstWeekContainsDate, Locale, LocaleUnit, RoundingMethod } from 'date-fns' - -type OptionsWithTZ = { - weekStartsOn?: Day, - firstWeekContainsDate?: FirstWeekContainsDate, - additionalDigits?: 0 | 1 | 2, - timeZone?: string, - originalDate?: Date | number, - locale?: Locale, - includeSeconds?: boolean, - addSuffix?: boolean, - unit?: LocaleUnit, - roundingMethod?: RoundingMethod, - awareOfUnicodeTokens?: boolean, -} - -type CurriedFn1 = (a: A) => R - -type CurriedFn2 = (a: A) => CurriedFn1 | ((a: A, b: B) => R) - -type CurriedFn3 = ( - a: A -) => - | CurriedFn2 - | ((a: A, b: B) => CurriedFn1 | ((a: A, b: B, c: C) => R)) - -type CurriedFn4 = ( - a: A -) => - | CurriedFn3 - | (( - a: A, - b: B - ) => - | CurriedFn2 - | (( - a: A, - b: B, - c: C - ) => CurriedFn1 | ((a: A, b: B, c: C, d: D) => R))) - -declare module.exports: { - format: CurriedFn2, - formatInTimeZone: CurriedFn3, - formatInTimeZoneWithOptions: CurriedFn4< - OptionsWithTZ, - string, - string, - Date | string | number, - string - >, - formatWithOptions: CurriedFn3, - fromZonedTime: CurriedFn2, - fromZonedTimeWithOptions: CurriedFn3, - getTimezoneOffset: CurriedFn2, - toDate: CurriedFn1, - toDateWithOptions: CurriedFn2, - toZonedTime: CurriedFn2, - toZonedTimeWithOptions: CurriedFn3, -} diff --git a/src/fp/toDate/index.js.flow b/src/fp/toDate/index.js.flow deleted file mode 100644 index 317df6d..0000000 --- a/src/fp/toDate/index.js.flow +++ /dev/null @@ -1,22 +0,0 @@ -// @flow -// This file is generated automatically by `scripts/build/typings.js`. Please, don't change it. - -import type { Day, FirstWeekContainsDate, Locale, LocaleUnit, RoundingMethod } from 'date-fns' - -type OptionsWithTZ = { - weekStartsOn?: Day, - firstWeekContainsDate?: FirstWeekContainsDate, - additionalDigits?: 0 | 1 | 2, - timeZone?: string, - originalDate?: Date | number, - locale?: Locale, - includeSeconds?: boolean, - addSuffix?: boolean, - unit?: LocaleUnit, - roundingMethod?: RoundingMethod, - awareOfUnicodeTokens?: boolean, -} - -type CurriedFn1 = (a: A) => R - -declare module.exports: CurriedFn1 diff --git a/src/fp/toDateWithOptions/index.js.flow b/src/fp/toDateWithOptions/index.js.flow deleted file mode 100644 index 8c2c4ab..0000000 --- a/src/fp/toDateWithOptions/index.js.flow +++ /dev/null @@ -1,24 +0,0 @@ -// @flow -// This file is generated automatically by `scripts/build/typings.js`. Please, don't change it. - -import type { Day, FirstWeekContainsDate, Locale, LocaleUnit, RoundingMethod } from 'date-fns' - -type OptionsWithTZ = { - weekStartsOn?: Day, - firstWeekContainsDate?: FirstWeekContainsDate, - additionalDigits?: 0 | 1 | 2, - timeZone?: string, - originalDate?: Date | number, - locale?: Locale, - includeSeconds?: boolean, - addSuffix?: boolean, - unit?: LocaleUnit, - roundingMethod?: RoundingMethod, - awareOfUnicodeTokens?: boolean, -} - -type CurriedFn1 = (a: A) => R - -type CurriedFn2 = (a: A) => CurriedFn1 | ((a: A, b: B) => R) - -declare module.exports: CurriedFn2 diff --git a/src/fp/toZonedTime/index.js.flow b/src/fp/toZonedTime/index.js.flow deleted file mode 100644 index e81728f..0000000 --- a/src/fp/toZonedTime/index.js.flow +++ /dev/null @@ -1,24 +0,0 @@ -// @flow -// This file is generated automatically by `scripts/build/typings.js`. Please, don't change it. - -import type { Day, FirstWeekContainsDate, Locale, LocaleUnit, RoundingMethod } from 'date-fns' - -type OptionsWithTZ = { - weekStartsOn?: Day, - firstWeekContainsDate?: FirstWeekContainsDate, - additionalDigits?: 0 | 1 | 2, - timeZone?: string, - originalDate?: Date | number, - locale?: Locale, - includeSeconds?: boolean, - addSuffix?: boolean, - unit?: LocaleUnit, - roundingMethod?: RoundingMethod, - awareOfUnicodeTokens?: boolean, -} - -type CurriedFn1 = (a: A) => R - -type CurriedFn2 = (a: A) => CurriedFn1 | ((a: A, b: B) => R) - -declare module.exports: CurriedFn2 diff --git a/src/fp/toZonedTimeWithOptions/index.js.flow b/src/fp/toZonedTimeWithOptions/index.js.flow deleted file mode 100644 index aa17bd2..0000000 --- a/src/fp/toZonedTimeWithOptions/index.js.flow +++ /dev/null @@ -1,30 +0,0 @@ -// @flow -// This file is generated automatically by `scripts/build/typings.js`. Please, don't change it. - -import type { Day, FirstWeekContainsDate, Locale, LocaleUnit, RoundingMethod } from 'date-fns' - -type OptionsWithTZ = { - weekStartsOn?: Day, - firstWeekContainsDate?: FirstWeekContainsDate, - additionalDigits?: 0 | 1 | 2, - timeZone?: string, - originalDate?: Date | number, - locale?: Locale, - includeSeconds?: boolean, - addSuffix?: boolean, - unit?: LocaleUnit, - roundingMethod?: RoundingMethod, - awareOfUnicodeTokens?: boolean, -} - -type CurriedFn1 = (a: A) => R - -type CurriedFn2 = (a: A) => CurriedFn1 | ((a: A, b: B) => R) - -type CurriedFn3 = ( - a: A -) => - | CurriedFn2 - | ((a: A, b: B) => CurriedFn1 | ((a: A, b: B, c: C) => R)) - -declare module.exports: CurriedFn3 diff --git a/src/fromZonedTime/index.js.flow b/src/fromZonedTime/index.js.flow deleted file mode 100644 index a9c26f7..0000000 --- a/src/fromZonedTime/index.js.flow +++ /dev/null @@ -1,24 +0,0 @@ -// @flow -// This file is generated automatically by `scripts/build/typings.js`. Please, don't change it. - -import type { Day, FirstWeekContainsDate, Locale, LocaleUnit, RoundingMethod } from 'date-fns' - -type OptionsWithTZ = { - weekStartsOn?: Day, - firstWeekContainsDate?: FirstWeekContainsDate, - additionalDigits?: 0 | 1 | 2, - timeZone?: string, - originalDate?: Date | number, - locale?: Locale, - includeSeconds?: boolean, - addSuffix?: boolean, - unit?: LocaleUnit, - roundingMethod?: RoundingMethod, - awareOfUnicodeTokens?: boolean, -} - -declare module.exports: ( - date: Date | string | number, - timeZone: string, - options?: OptionsWithTZ -) => Date diff --git a/src/getTimezoneOffset/index.js.flow b/src/getTimezoneOffset/index.js.flow deleted file mode 100644 index 06e92ab..0000000 --- a/src/getTimezoneOffset/index.js.flow +++ /dev/null @@ -1,20 +0,0 @@ -// @flow -// This file is generated automatically by `scripts/build/typings.js`. Please, don't change it. - -import type { Day, FirstWeekContainsDate, Locale, LocaleUnit, RoundingMethod } from 'date-fns' - -type OptionsWithTZ = { - weekStartsOn?: Day, - firstWeekContainsDate?: FirstWeekContainsDate, - additionalDigits?: 0 | 1 | 2, - timeZone?: string, - originalDate?: Date | number, - locale?: Locale, - includeSeconds?: boolean, - addSuffix?: boolean, - unit?: LocaleUnit, - roundingMethod?: RoundingMethod, - awareOfUnicodeTokens?: boolean, -} - -declare module.exports: (timeZone: string, date?: Date | number) => number diff --git a/src/index.js.flow b/src/index.js.flow deleted file mode 100644 index de9a79b..0000000 --- a/src/index.js.flow +++ /dev/null @@ -1,37 +0,0 @@ -// @flow -// This file is generated automatically by `scripts/build/typings.js`. Please, don't change it. - -import type { Day, FirstWeekContainsDate, Locale, LocaleUnit, RoundingMethod } from 'date-fns' - -type OptionsWithTZ = { - weekStartsOn?: Day, - firstWeekContainsDate?: FirstWeekContainsDate, - additionalDigits?: 0 | 1 | 2, - timeZone?: string, - originalDate?: Date | number, - locale?: Locale, - includeSeconds?: boolean, - addSuffix?: boolean, - unit?: LocaleUnit, - roundingMethod?: RoundingMethod, - awareOfUnicodeTokens?: boolean, -} - -declare module.exports: { - format: (date: Date | number, format: string, options?: OptionsWithTZ) => string, - - formatInTimeZone: ( - date: Date | string | number, - timeZone: string, - formatStr: string, - options?: OptionsWithTZ - ) => string, - - fromZonedTime: (date: Date | string | number, timeZone: string, options?: OptionsWithTZ) => Date, - - getTimezoneOffset: (timeZone: string, date?: Date | number) => number, - - toDate: (argument: Date | string | number, options?: OptionsWithTZ) => Date, - - toZonedTime: (date: Date | string | number, timeZone: string, options?: OptionsWithTZ) => Date, -} diff --git a/src/toDate/index.js.flow b/src/toDate/index.js.flow deleted file mode 100644 index 922d2d4..0000000 --- a/src/toDate/index.js.flow +++ /dev/null @@ -1,20 +0,0 @@ -// @flow -// This file is generated automatically by `scripts/build/typings.js`. Please, don't change it. - -import type { Day, FirstWeekContainsDate, Locale, LocaleUnit, RoundingMethod } from 'date-fns' - -type OptionsWithTZ = { - weekStartsOn?: Day, - firstWeekContainsDate?: FirstWeekContainsDate, - additionalDigits?: 0 | 1 | 2, - timeZone?: string, - originalDate?: Date | number, - locale?: Locale, - includeSeconds?: boolean, - addSuffix?: boolean, - unit?: LocaleUnit, - roundingMethod?: RoundingMethod, - awareOfUnicodeTokens?: boolean, -} - -declare module.exports: (argument: Date | string | number, options?: OptionsWithTZ) => Date diff --git a/src/toZonedTime/index.js.flow b/src/toZonedTime/index.js.flow deleted file mode 100644 index a9c26f7..0000000 --- a/src/toZonedTime/index.js.flow +++ /dev/null @@ -1,24 +0,0 @@ -// @flow -// This file is generated automatically by `scripts/build/typings.js`. Please, don't change it. - -import type { Day, FirstWeekContainsDate, Locale, LocaleUnit, RoundingMethod } from 'date-fns' - -type OptionsWithTZ = { - weekStartsOn?: Day, - firstWeekContainsDate?: FirstWeekContainsDate, - additionalDigits?: 0 | 1 | 2, - timeZone?: string, - originalDate?: Date | number, - locale?: Locale, - includeSeconds?: boolean, - addSuffix?: boolean, - unit?: LocaleUnit, - roundingMethod?: RoundingMethod, - awareOfUnicodeTokens?: boolean, -} - -declare module.exports: ( - date: Date | string | number, - timeZone: string, - options?: OptionsWithTZ -) => Date diff --git a/yarn.lock b/yarn.lock index a0359b1..766a8cf 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3603,7 +3603,6 @@ __metadata: date-fns: "npm:^3.0.6" eslint: "npm:^7.11.0" eslint-config-prettier: "npm:^7.2.0" - flow-bin: "npm:^0.143.1" fs-promise: "npm:^2.0.3" husky: "npm:^4.3.0" jsdoc-to-markdown: "npm:^7.0.1" @@ -4811,15 +4810,6 @@ __metadata: languageName: node linkType: hard -"flow-bin@npm:^0.143.1": - version: 0.143.1 - resolution: "flow-bin@npm:0.143.1" - bin: - flow: cli.js - checksum: 10/022d15541693f7bad3b4bf2c6a807c80333db22cb21621fe0e75aeba200ccbf06fc8fe87514b60561762476a7c8300d232d90ae76a87585bff2b63a633b378ee - languageName: node - linkType: hard - "flush-write-stream@npm:^1.0.0": version: 1.1.1 resolution: "flush-write-stream@npm:1.1.1" From 2cf213a103b00d30bc8ded2fd031a4381b0af599 Mon Sep 17 00:00:00 2001 From: Marnus Weststrate Date: Thu, 4 Apr 2024 06:53:33 +0100 Subject: [PATCH 03/10] Export all functions using named exports --- scripts/build/fp.js | 6 ++---- scripts/build/indices.js | 4 ++-- src/_lib/newDateUTC/index.js | 2 +- src/_lib/newDateUTC/test.js | 2 +- src/_lib/tzIntlTimeZoneName/index.js | 4 ++-- src/_lib/tzIntlTimeZoneName/test.js | 2 +- src/_lib/tzParseTimezone/index.js | 11 +++++----- src/_lib/tzParseTimezone/test.js | 2 +- src/_lib/tzPattern/index.js | 2 +- src/_lib/tzTokenizeDate/index.js | 2 +- src/_lib/tzTokenizeDate/test.js | 2 +- src/esm/fp/index.js | 22 ++++++++++---------- src/esm/index.js | 12 +++++------ src/format/formatters/index.js | 6 +++--- src/format/index.js | 12 +++++------ src/format/test.js | 4 ++-- src/formatInTimeZone/index.js | 6 +++--- src/formatInTimeZone/test.js | 2 +- src/fp/format/index.js | 6 ++---- src/fp/formatInTimeZone/index.js | 6 ++---- src/fp/formatInTimeZoneWithOptions/index.js | 6 ++---- src/fp/formatWithOptions/index.js | 6 ++---- src/fp/fromZonedTime/index.js | 6 ++---- src/fp/fromZonedTimeWithOptions/index.js | 6 ++---- src/fp/getTimezoneOffset/index.js | 6 ++---- src/fp/index.js | 23 +++++++++++---------- src/fp/toDate/index.js | 6 ++---- src/fp/toDateWithOptions/index.js | 6 ++---- src/fp/toZonedTime/index.js | 6 ++---- src/fp/toZonedTimeWithOptions/index.js | 6 ++---- src/fromZonedTime/index.js | 10 ++++----- src/fromZonedTime/test.js | 6 +++--- src/getTimezoneOffset/index.js | 4 ++-- src/getTimezoneOffset/test.js | 2 +- src/index.js | 12 +++++------ src/toDate/index.js | 8 +++---- src/toDate/test.js | 2 +- src/toZonedTime/index.js | 6 +++--- src/toZonedTime/test.js | 4 ++-- 39 files changed, 112 insertions(+), 134 deletions(-) diff --git a/scripts/build/fp.js b/scripts/build/fp.js index bea07d9..b7c162c 100755 --- a/scripts/build/fp.js +++ b/scripts/build/fp.js @@ -26,12 +26,10 @@ buildFP(fpFns) function getFPFn(resultFnName, initialFnName, arity) { return [generatedAutomaticallyMessage] .concat('') - .concat(`import fn from '../../${initialFnName}/index.js'`) + .concat(`import { ${initialFnName} as fn } from '../../${initialFnName}'`) .concat(`import { convertToFP } from '../_lib/convertToFP'`) .concat('') - .concat(`var ${resultFnName} = convertToFP(fn, ${arity})`) - .concat('') - .concat(`export default ${resultFnName}`) + .concat(`export const ${resultFnName} = convertToFP(fn, ${arity})`) .concat('') .join('\n') } diff --git a/scripts/build/indices.js b/scripts/build/indices.js index aef5fba..57b2c19 100755 --- a/scripts/build/indices.js +++ b/scripts/build/indices.js @@ -30,7 +30,7 @@ function writeFile(relativePath, content) { function generateIndex(files) { const propertyRequireLines = files.map( - (fn) => ` ${fn.name}: require('${fn.path.replace(/\.js$/, '')}/index.js')` + (fn) => ` ${fn.name}: require('${fn.path.replace(/\.js$/, '')}/index.js').${fn.name}` ) const indexLines = [generatedAutomaticallyMessage] @@ -45,7 +45,7 @@ function generateIndex(files) { function generateESMIndex(files) { const fileLines = files.map( - (fn) => `export { default as ${fn.name} } from '${fn.path.replace(/\.js$/, '')}/index.js'` + (fn) => `export * from '${fn.path.replace(/\.js$/, '')}/index.js'` ) const indexLines = [generatedAutomaticallyMessage].concat('').concat(fileLines).join('\n') diff --git a/src/_lib/newDateUTC/index.js b/src/_lib/newDateUTC/index.js index 138f631..171174d 100644 --- a/src/_lib/newDateUTC/index.js +++ b/src/_lib/newDateUTC/index.js @@ -5,7 +5,7 @@ * * For `Date.UTC(...)`, use `newDateUTC(...).getTime()`. */ -export default function newDateUTC(fullYear, month, day, hour, minute, second, millisecond) { +export function newDateUTC(fullYear, month, day, hour, minute, second, millisecond) { var utcDate = new Date(0) utcDate.setUTCFullYear(fullYear, month, day) utcDate.setUTCHours(hour, minute, second, millisecond) diff --git a/src/_lib/newDateUTC/test.js b/src/_lib/newDateUTC/test.js index 42d2bb6..ecd81f7 100644 --- a/src/_lib/newDateUTC/test.js +++ b/src/_lib/newDateUTC/test.js @@ -1,5 +1,5 @@ import assert from 'power-assert' -import newDateUTC from '.' +import { newDateUTC } from '.' describe('newDateUTC', function () { it('Equivalent to Date.UTC', function () { diff --git a/src/_lib/tzIntlTimeZoneName/index.js b/src/_lib/tzIntlTimeZoneName/index.js index dd44ce8..0e89b4f 100644 --- a/src/_lib/tzIntlTimeZoneName/index.js +++ b/src/_lib/tzIntlTimeZoneName/index.js @@ -3,7 +3,7 @@ * system time zone if omitted, accounting for DST according to the UTC value of * the date. */ -export default function tzIntlTimeZoneName(length, date, options) { +export function tzIntlTimeZoneName(length, date, options) { var dtf = getDTF(length, options.timeZone, options.locale) return dtf.formatToParts ? partsTimeZone(dtf, date) : hackyTimeZone(dtf, date) } @@ -29,7 +29,7 @@ function hackyTimeZone(dtf, date) { function getDTF(length, timeZone, locale) { if (locale && !locale.code) { throw new Error( - "date-fns-tz error: Please set a language code on the locale object imported from date-fns, e.g. `locale.code = 'en-US'`" + 'date-fns-tz error: Please set a language code on the locale object imported from date-fns, e.g. `locale.code = \'en-US\'`', ) } return new Intl.DateTimeFormat(locale ? [locale.code, 'en-US'] : undefined, { diff --git a/src/_lib/tzIntlTimeZoneName/test.js b/src/_lib/tzIntlTimeZoneName/test.js index 901357a..4fc79c5 100644 --- a/src/_lib/tzIntlTimeZoneName/test.js +++ b/src/_lib/tzIntlTimeZoneName/test.js @@ -1,5 +1,5 @@ import assert from 'power-assert' -import tzIntlTimeZoneName from '.' +import { tzIntlTimeZoneName } from '.' describe('tzIntlTimeZoneName', function () { it('returns the short time zone name', function () { diff --git a/src/_lib/tzParseTimezone/index.js b/src/_lib/tzParseTimezone/index.js index 3b157ab..d6f9150 100644 --- a/src/_lib/tzParseTimezone/index.js +++ b/src/_lib/tzParseTimezone/index.js @@ -1,5 +1,5 @@ -import tzTokenizeDate from '../tzTokenizeDate/index.js' -import newDateUTC from '../newDateUTC/index.js' +import { tzTokenizeDate } from '../tzTokenizeDate' +import { newDateUTC } from '../newDateUTC' var MILLISECONDS_IN_HOUR = 3600000 var MILLISECONDS_IN_MINUTE = 60000 @@ -12,7 +12,7 @@ var patterns = { } // Parse various time zone offset formats to an offset in milliseconds -export default function tzParseTimezone(timezoneString, date, isUtcDate) { +export function tzParseTimezone(timezoneString, date, isUtcDate) { var token var absoluteOffset @@ -78,7 +78,7 @@ function toUtcDate(date) { date.getHours(), date.getMinutes(), date.getSeconds(), - date.getMilliseconds() + date.getMilliseconds(), ) } @@ -93,7 +93,7 @@ function calcOffset(date, timezoneString) { tokens[3] % 24, tokens[4], tokens[5], - 0 + 0, ).getTime() var asTS = date.getTime() @@ -134,6 +134,7 @@ function validateTimezone(hours, minutes) { } var validIANATimezoneCache = {} + function isValidTimezoneIANAString(timeZoneString) { if (validIANATimezoneCache[timeZoneString]) return true try { diff --git a/src/_lib/tzParseTimezone/test.js b/src/_lib/tzParseTimezone/test.js index 0634780..82be792 100644 --- a/src/_lib/tzParseTimezone/test.js +++ b/src/_lib/tzParseTimezone/test.js @@ -1,5 +1,5 @@ import assert from 'power-assert' -import tzParseTimezone from '.' +import { tzParseTimezone } from '.' describe('tzParseTimezone', function () { it('Empty time zone', function () { diff --git a/src/_lib/tzPattern/index.js b/src/_lib/tzPattern/index.js index d80ca94..ed0d47c 100644 --- a/src/_lib/tzPattern/index.js +++ b/src/_lib/tzPattern/index.js @@ -1,4 +1,4 @@ /** Regex to identify the presence of a time zone specifier in a date string */ var tzPattern = /(Z|[+-]\d{2}(?::?\d{2})?| UTC| [a-zA-Z]+\/[a-zA-Z_]+(?:\/[a-zA-Z_]+)?)$/ -export default tzPattern +export { tzPattern } diff --git a/src/_lib/tzTokenizeDate/index.js b/src/_lib/tzTokenizeDate/index.js index 46689e5..3b26ab2 100644 --- a/src/_lib/tzTokenizeDate/index.js +++ b/src/_lib/tzTokenizeDate/index.js @@ -2,7 +2,7 @@ * Returns the [year, month, day, hour, minute, seconds] tokens of the provided * `date` as it will be rendered in the `timeZone`. */ -export default function tzTokenizeDate(date, timeZone) { +export function tzTokenizeDate(date, timeZone) { var dtf = getDateTimeFormat(timeZone) return dtf.formatToParts ? partsOffset(dtf, date) : hackyOffset(dtf, date) } diff --git a/src/_lib/tzTokenizeDate/test.js b/src/_lib/tzTokenizeDate/test.js index 529a175..a568ad2 100644 --- a/src/_lib/tzTokenizeDate/test.js +++ b/src/_lib/tzTokenizeDate/test.js @@ -1,5 +1,5 @@ import assert from 'power-assert' -import tzTokenizeDate from '.' +import { tzTokenizeDate } from '.' describe('tzTokenizeDate', function () { it('returns year through second tokens of the local date in the time zone', function () { diff --git a/src/esm/fp/index.js b/src/esm/fp/index.js index bbcddfa..da4a9ba 100644 --- a/src/esm/fp/index.js +++ b/src/esm/fp/index.js @@ -1,13 +1,13 @@ // This file is generated automatically by `scripts/build/indices.js`. Please, don't change it. -export { default as format } from './format/index.js' -export { default as formatInTimeZone } from './formatInTimeZone/index.js' -export { default as formatInTimeZoneWithOptions } from './formatInTimeZoneWithOptions/index.js' -export { default as formatWithOptions } from './formatWithOptions/index.js' -export { default as fromZonedTime } from './fromZonedTime/index.js' -export { default as fromZonedTimeWithOptions } from './fromZonedTimeWithOptions/index.js' -export { default as getTimezoneOffset } from './getTimezoneOffset/index.js' -export { default as toDate } from './toDate/index.js' -export { default as toDateWithOptions } from './toDateWithOptions/index.js' -export { default as toZonedTime } from './toZonedTime/index.js' -export { default as toZonedTimeWithOptions } from './toZonedTimeWithOptions/index.js' +export * from './format/index.js' +export * from './formatInTimeZone/index.js' +export * from './formatInTimeZoneWithOptions/index.js' +export * from './formatWithOptions/index.js' +export * from './fromZonedTime/index.js' +export * from './fromZonedTimeWithOptions/index.js' +export * from './getTimezoneOffset/index.js' +export * from './toDate/index.js' +export * from './toDateWithOptions/index.js' +export * from './toZonedTime/index.js' +export * from './toZonedTimeWithOptions/index.js' diff --git a/src/esm/index.js b/src/esm/index.js index 649cce3..29ca60a 100644 --- a/src/esm/index.js +++ b/src/esm/index.js @@ -1,8 +1,8 @@ // This file is generated automatically by `scripts/build/indices.js`. Please, don't change it. -export { default as format } from './format/index.js' -export { default as formatInTimeZone } from './formatInTimeZone/index.js' -export { default as fromZonedTime } from './fromZonedTime/index.js' -export { default as getTimezoneOffset } from './getTimezoneOffset/index.js' -export { default as toDate } from './toDate/index.js' -export { default as toZonedTime } from './toZonedTime/index.js' +export * from './format/index.js' +export * from './formatInTimeZone/index.js' +export * from './fromZonedTime/index.js' +export * from './getTimezoneOffset/index.js' +export * from './toDate/index.js' +export * from './toZonedTime/index.js' diff --git a/src/format/formatters/index.js b/src/format/formatters/index.js index 15be26f..c3cc3d8 100644 --- a/src/format/formatters/index.js +++ b/src/format/formatters/index.js @@ -1,5 +1,5 @@ -import tzIntlTimeZoneName from '../../_lib/tzIntlTimeZoneName/index.js' -import tzParseTimezone from '../../_lib/tzParseTimezone/index.js' +import { tzIntlTimeZoneName } from '../../_lib/tzIntlTimeZoneName' +import { tzParseTimezone } from '../../_lib/tzParseTimezone' var MILLISECONDS_IN_MINUTE = 60 * 1000 @@ -141,4 +141,4 @@ function formatTimezoneShort(offset, dirtyDelimiter) { return sign + String(hours) + delimiter + addLeadingZeros(minutes, 2) } -export default formatters +export { formatters } diff --git a/src/format/index.js b/src/format/index.js index 347df7e..f963a53 100644 --- a/src/format/index.js +++ b/src/format/index.js @@ -1,6 +1,6 @@ import { format as dateFnsFormat } from 'date-fns/format' -import formatters from './formatters/index.js' -import toDate from '../toDate/index.js' +import { formatters } from './formatters' +import { toDate } from '../toDate' var tzFormattingTokensRegExp = /([xXOz]+)|''|'(''|[^'])+('|$)/g @@ -316,7 +316,7 @@ var tzFormattingTokensRegExp = /([xXOz]+)|''|'(''|[^'])+('|$)/g * var result = format(new Date(2014, 6, 2, 15), "h 'o''clock'") * //=> "3 o'clock" */ -export default function format(dirtyDate, dirtyFormatStr, dirtyOptions) { +export function format(dirtyDate, dirtyFormatStr, dirtyOptions) { var formatStr = String(dirtyFormatStr) var options = dirtyOptions || {} @@ -326,14 +326,14 @@ export default function format(dirtyDate, dirtyFormatStr, dirtyOptions) { // Work through each match and replace the tz token in the format string with the quoted // formatted time zone so the remaining tokens can be filled in by date-fns#format. formatStr = matches.reduce(function (result, token) { - if (token[0] === "'") { + if (token[0] === '\'') { return result // This is a quoted portion, matched only to ensure we don't match inside it } var pos = result.indexOf(token) - var precededByQuotedSection = result[pos - 1] === "'" + var precededByQuotedSection = result[pos - 1] === '\'' var replaced = result.replace( token, - "'" + formatters[token[0]](date, token, null, options) + "'" + '\'' + formatters[token[0]](date, token, null, options) + '\'', ) // If the replacement results in two adjoining quoted strings, the back to back quotes // are removed, so it doesn't look like an escaped quote. diff --git a/src/format/test.js b/src/format/test.js index 59e68ba..439c1bf 100644 --- a/src/format/test.js +++ b/src/format/test.js @@ -1,9 +1,9 @@ /* eslint-env mocha */ import assert from 'power-assert' -import format from '.' +import { format } from '.' import { enGB } from 'date-fns/locale/en-GB' -import toZonedTime from '../toZonedTime' +import { toZonedTime } from '../toZonedTime' describe('format', function () { var date = new Date(1986, 3 /* Apr */, 4, 10, 32, 55, 123) diff --git a/src/formatInTimeZone/index.js b/src/formatInTimeZone/index.js index 060b2a7..45136f7 100644 --- a/src/formatInTimeZone/index.js +++ b/src/formatInTimeZone/index.js @@ -1,5 +1,5 @@ -import format from '../format/index.js' -import toZonedTime from '../toZonedTime/index.js' +import { format } from '../format' +import { toZonedTime } from '../toZonedTime' import cloneDeep from 'lodash.clonedeep' /** @@ -24,7 +24,7 @@ import cloneDeep from 'lodash.clonedeep' * @param {String} [options.timeZone=''] - used to specify the IANA time zone offset of a date String. * @returns {String} the formatted date string */ -export default function formatInTimeZone(date, timeZone, formatStr, options) { +export function formatInTimeZone(date, timeZone, formatStr, options) { var extendedOptions = cloneDeep(options || {}) extendedOptions.timeZone = timeZone extendedOptions.originalDate = date diff --git a/src/formatInTimeZone/test.js b/src/formatInTimeZone/test.js index 615838f..d77398f 100644 --- a/src/formatInTimeZone/test.js +++ b/src/formatInTimeZone/test.js @@ -1,6 +1,6 @@ import assert from 'power-assert' import { enGB } from 'date-fns/locale/en-GB' -import formatInTimeZone from './index' +import { formatInTimeZone } from './index' describe('formatInTimeZone', function () { describe('shifts the date to the zoned time and formats', function () { diff --git a/src/fp/format/index.js b/src/fp/format/index.js index 77be07c..d03dfa4 100644 --- a/src/fp/format/index.js +++ b/src/fp/format/index.js @@ -1,8 +1,6 @@ // This file is generated automatically by `scripts/build/fp.js`. Please, don't change it. -import fn from '../../format/index.js' +import { format as fn } from '../../format' import { convertToFP } from '../_lib/convertToFP' -var format = convertToFP(fn, 2) - -export default format +export const format = convertToFP(fn, 2) diff --git a/src/fp/formatInTimeZone/index.js b/src/fp/formatInTimeZone/index.js index 2eba769..9bb431a 100644 --- a/src/fp/formatInTimeZone/index.js +++ b/src/fp/formatInTimeZone/index.js @@ -1,8 +1,6 @@ // This file is generated automatically by `scripts/build/fp.js`. Please, don't change it. -import fn from '../../formatInTimeZone/index.js' +import { formatInTimeZone as fn } from '../../formatInTimeZone' import { convertToFP } from '../_lib/convertToFP' -var formatInTimeZone = convertToFP(fn, 3) - -export default formatInTimeZone +export const formatInTimeZone = convertToFP(fn, 3) diff --git a/src/fp/formatInTimeZoneWithOptions/index.js b/src/fp/formatInTimeZoneWithOptions/index.js index 1fa7463..51e0f92 100644 --- a/src/fp/formatInTimeZoneWithOptions/index.js +++ b/src/fp/formatInTimeZoneWithOptions/index.js @@ -1,8 +1,6 @@ // This file is generated automatically by `scripts/build/fp.js`. Please, don't change it. -import fn from '../../formatInTimeZone/index.js' +import { formatInTimeZone as fn } from '../../formatInTimeZone' import { convertToFP } from '../_lib/convertToFP' -var formatInTimeZoneWithOptions = convertToFP(fn, 4) - -export default formatInTimeZoneWithOptions +export const formatInTimeZoneWithOptions = convertToFP(fn, 4) diff --git a/src/fp/formatWithOptions/index.js b/src/fp/formatWithOptions/index.js index 2926479..5ba9819 100644 --- a/src/fp/formatWithOptions/index.js +++ b/src/fp/formatWithOptions/index.js @@ -1,8 +1,6 @@ // This file is generated automatically by `scripts/build/fp.js`. Please, don't change it. -import fn from '../../format/index.js' +import { format as fn } from '../../format' import { convertToFP } from '../_lib/convertToFP' -var formatWithOptions = convertToFP(fn, 3) - -export default formatWithOptions +export const formatWithOptions = convertToFP(fn, 3) diff --git a/src/fp/fromZonedTime/index.js b/src/fp/fromZonedTime/index.js index a060eb0..2916c5c 100644 --- a/src/fp/fromZonedTime/index.js +++ b/src/fp/fromZonedTime/index.js @@ -1,8 +1,6 @@ // This file is generated automatically by `scripts/build/fp.js`. Please, don't change it. -import fn from '../../fromZonedTime/index.js' +import { fromZonedTime as fn } from '../../fromZonedTime' import { convertToFP } from '../_lib/convertToFP' -var fromZonedTime = convertToFP(fn, 2) - -export default fromZonedTime +export const fromZonedTime = convertToFP(fn, 2) diff --git a/src/fp/fromZonedTimeWithOptions/index.js b/src/fp/fromZonedTimeWithOptions/index.js index 8e8d1b0..859ea25 100644 --- a/src/fp/fromZonedTimeWithOptions/index.js +++ b/src/fp/fromZonedTimeWithOptions/index.js @@ -1,8 +1,6 @@ // This file is generated automatically by `scripts/build/fp.js`. Please, don't change it. -import fn from '../../fromZonedTime/index.js' +import { fromZonedTime as fn } from '../../fromZonedTime' import { convertToFP } from '../_lib/convertToFP' -var fromZonedTimeWithOptions = convertToFP(fn, 3) - -export default fromZonedTimeWithOptions +export const fromZonedTimeWithOptions = convertToFP(fn, 3) diff --git a/src/fp/getTimezoneOffset/index.js b/src/fp/getTimezoneOffset/index.js index d01bdb5..001e1cd 100644 --- a/src/fp/getTimezoneOffset/index.js +++ b/src/fp/getTimezoneOffset/index.js @@ -1,8 +1,6 @@ // This file is generated automatically by `scripts/build/fp.js`. Please, don't change it. -import fn from '../../getTimezoneOffset/index.js' +import { getTimezoneOffset as fn } from '../../getTimezoneOffset' import { convertToFP } from '../_lib/convertToFP' -var getTimezoneOffset = convertToFP(fn, 2) - -export default getTimezoneOffset +export const getTimezoneOffset = convertToFP(fn, 2) diff --git a/src/fp/index.js b/src/fp/index.js index 3a86187..d1f80eb 100644 --- a/src/fp/index.js +++ b/src/fp/index.js @@ -1,15 +1,16 @@ // This file is generated automatically by `scripts/build/indices.js`. Please, don't change it. module.exports = { - format: require('./format/index.js'), - formatInTimeZone: require('./formatInTimeZone/index.js'), - formatInTimeZoneWithOptions: require('./formatInTimeZoneWithOptions/index.js'), - formatWithOptions: require('./formatWithOptions/index.js'), - fromZonedTime: require('./fromZonedTime/index.js'), - fromZonedTimeWithOptions: require('./fromZonedTimeWithOptions/index.js'), - getTimezoneOffset: require('./getTimezoneOffset/index.js'), - toDate: require('./toDate/index.js'), - toDateWithOptions: require('./toDateWithOptions/index.js'), - toZonedTime: require('./toZonedTime/index.js'), - toZonedTimeWithOptions: require('./toZonedTimeWithOptions/index.js'), + format: require('./format/index.js').format, + formatInTimeZone: require('./formatInTimeZone/index.js').formatInTimeZone, + formatInTimeZoneWithOptions: require('./formatInTimeZoneWithOptions/index.js') + .formatInTimeZoneWithOptions, + formatWithOptions: require('./formatWithOptions/index.js').formatWithOptions, + fromZonedTime: require('./fromZonedTime/index.js').fromZonedTime, + fromZonedTimeWithOptions: require('./fromZonedTimeWithOptions/index.js').fromZonedTimeWithOptions, + getTimezoneOffset: require('./getTimezoneOffset/index.js').getTimezoneOffset, + toDate: require('./toDate/index.js').toDate, + toDateWithOptions: require('./toDateWithOptions/index.js').toDateWithOptions, + toZonedTime: require('./toZonedTime/index.js').toZonedTime, + toZonedTimeWithOptions: require('./toZonedTimeWithOptions/index.js').toZonedTimeWithOptions, } diff --git a/src/fp/toDate/index.js b/src/fp/toDate/index.js index 5cbe9c2..1a08951 100644 --- a/src/fp/toDate/index.js +++ b/src/fp/toDate/index.js @@ -1,8 +1,6 @@ // This file is generated automatically by `scripts/build/fp.js`. Please, don't change it. -import fn from '../../toDate/index.js' +import { toDate as fn } from '../../toDate' import { convertToFP } from '../_lib/convertToFP' -var toDate = convertToFP(fn, 1) - -export default toDate +export const toDate = convertToFP(fn, 1) diff --git a/src/fp/toDateWithOptions/index.js b/src/fp/toDateWithOptions/index.js index 1ca4409..09fa4d0 100644 --- a/src/fp/toDateWithOptions/index.js +++ b/src/fp/toDateWithOptions/index.js @@ -1,8 +1,6 @@ // This file is generated automatically by `scripts/build/fp.js`. Please, don't change it. -import fn from '../../toDate/index.js' +import { toDate as fn } from '../../toDate' import { convertToFP } from '../_lib/convertToFP' -var toDateWithOptions = convertToFP(fn, 2) - -export default toDateWithOptions +export const toDateWithOptions = convertToFP(fn, 2) diff --git a/src/fp/toZonedTime/index.js b/src/fp/toZonedTime/index.js index 0d2a5a0..2b5174f 100644 --- a/src/fp/toZonedTime/index.js +++ b/src/fp/toZonedTime/index.js @@ -1,8 +1,6 @@ // This file is generated automatically by `scripts/build/fp.js`. Please, don't change it. -import fn from '../../toZonedTime/index.js' +import { toZonedTime as fn } from '../../toZonedTime' import { convertToFP } from '../_lib/convertToFP' -var toZonedTime = convertToFP(fn, 2) - -export default toZonedTime +export const toZonedTime = convertToFP(fn, 2) diff --git a/src/fp/toZonedTimeWithOptions/index.js b/src/fp/toZonedTimeWithOptions/index.js index 2d56b78..4cf1f17 100644 --- a/src/fp/toZonedTimeWithOptions/index.js +++ b/src/fp/toZonedTimeWithOptions/index.js @@ -1,8 +1,6 @@ // This file is generated automatically by `scripts/build/fp.js`. Please, don't change it. -import fn from '../../toZonedTime/index.js' +import { toZonedTime as fn } from '../../toZonedTime' import { convertToFP } from '../_lib/convertToFP' -var toZonedTimeWithOptions = convertToFP(fn, 3) - -export default toZonedTimeWithOptions +export const toZonedTimeWithOptions = convertToFP(fn, 3) diff --git a/src/fromZonedTime/index.js b/src/fromZonedTime/index.js index f0b51f8..d478c8a 100644 --- a/src/fromZonedTime/index.js +++ b/src/fromZonedTime/index.js @@ -1,7 +1,7 @@ -import toDate from '../toDate/index.js' -import tzPattern from '../_lib/tzPattern/index.js' -import tzParseTimezone from '../_lib/tzParseTimezone/index.js' -import newDateUTC from '../_lib/newDateUTC/index.js' +import { toDate } from '../toDate' +import { tzPattern } from '../_lib/tzPattern' +import { tzParseTimezone } from '../_lib/tzParseTimezone' +import { newDateUTC } from '../_lib/newDateUTC' import cloneDeep from 'lodash.clonedeep' /** @@ -28,7 +28,7 @@ import cloneDeep from 'lodash.clonedeep' * const result = fromZonedTime(new Date(2014, 5, 25, 10, 0, 0), 'America/Los_Angeles') * //=> 2014-06-25T17:00:00.000Z */ -export default function fromZonedTime(date, timeZone, options) { +export function fromZonedTime(date, timeZone, options) { if (typeof date === 'string' && !date.match(tzPattern)) { var extendedOptions = cloneDeep(options || {}) extendedOptions.timeZone = timeZone diff --git a/src/fromZonedTime/test.js b/src/fromZonedTime/test.js index 60877c1..5f3dbcd 100644 --- a/src/fromZonedTime/test.js +++ b/src/fromZonedTime/test.js @@ -1,7 +1,7 @@ import assert from 'power-assert' -import format from '../format' -import toZonedTime from '../toZonedTime' -import fromZonedTime from '.' +import { format } from '../format' +import { toZonedTime } from '../toZonedTime' +import { fromZonedTime } from '.' describe('fromZonedTime', function () { it('returns the UTC time of the date in the time zone for a date input and IANA tz', function () { diff --git a/src/getTimezoneOffset/index.js b/src/getTimezoneOffset/index.js index 10fc346..8680d83 100644 --- a/src/getTimezoneOffset/index.js +++ b/src/getTimezoneOffset/index.js @@ -1,4 +1,4 @@ -import tzParseTimezone from '../_lib/tzParseTimezone/index.js' +import { tzParseTimezone } from '../_lib/tzParseTimezone/index.js' /** * @name getTimezoneOffset @@ -27,6 +27,6 @@ import tzParseTimezone from '../_lib/tzParseTimezone/index.js' * const result = getTimezoneOffset('America/New_York', new Date(2016, 6, 1)) * //=> -14400000 (-4 * 60 * 60 * 1000) */ -export default function getTimezoneOffset(timeZone, date) { +export function getTimezoneOffset(timeZone, date) { return -tzParseTimezone(timeZone, date) } diff --git a/src/getTimezoneOffset/test.js b/src/getTimezoneOffset/test.js index e37f44f..a78a1a3 100644 --- a/src/getTimezoneOffset/test.js +++ b/src/getTimezoneOffset/test.js @@ -1,5 +1,5 @@ import assert from 'power-assert' -import getTimezoneOffset from './index' +import { getTimezoneOffset } from './index' const hours = 60 * 60 * 1000 diff --git a/src/index.js b/src/index.js index 2f231c6..ff3c6ce 100644 --- a/src/index.js +++ b/src/index.js @@ -1,10 +1,10 @@ // This file is generated automatically by `scripts/build/indices.js`. Please, don't change it. module.exports = { - format: require('./format/index.js'), - formatInTimeZone: require('./formatInTimeZone/index.js'), - fromZonedTime: require('./fromZonedTime/index.js'), - getTimezoneOffset: require('./getTimezoneOffset/index.js'), - toDate: require('./toDate/index.js'), - toZonedTime: require('./toZonedTime/index.js'), + format: require('./format/index.js').format, + formatInTimeZone: require('./formatInTimeZone/index.js').formatInTimeZone, + fromZonedTime: require('./fromZonedTime/index.js').fromZonedTime, + getTimezoneOffset: require('./getTimezoneOffset/index.js').getTimezoneOffset, + toDate: require('./toDate/index.js').toDate, + toZonedTime: require('./toZonedTime/index.js').toZonedTime, } diff --git a/src/toDate/index.js b/src/toDate/index.js index 48804d7..2d1e318 100644 --- a/src/toDate/index.js +++ b/src/toDate/index.js @@ -1,6 +1,6 @@ -import { getTimezoneOffsetInMilliseconds } from '../_lib/getTimezoneOffsetInMilliseconds/index.js' -import tzParseTimezone from '../_lib/tzParseTimezone/index.js' -import tzPattern from '../_lib/tzPattern/index.js' +import { getTimezoneOffsetInMilliseconds } from '../_lib/getTimezoneOffsetInMilliseconds' +import { tzParseTimezone } from '../_lib/tzParseTimezone' +import { tzPattern } from '../_lib/tzPattern' var MILLISECONDS_IN_HOUR = 3600000 var MILLISECONDS_IN_MINUTE = 60000 @@ -81,7 +81,7 @@ var patterns = { * var result = toDate('+02014101', {additionalDigits: 1}) * //=> Fri Apr 11 2014 00:00:00 */ -export default function toDate(argument, dirtyOptions) { +export function toDate(argument, dirtyOptions) { if (arguments.length < 1) { throw new TypeError('1 argument required, but only ' + arguments.length + ' present') } diff --git a/src/toDate/test.js b/src/toDate/test.js index cc60e5b..9d9bc89 100644 --- a/src/toDate/test.js +++ b/src/toDate/test.js @@ -1,5 +1,5 @@ import assert from 'power-assert' -import toDate from '.' +import { toDate } from '.' describe('toDate', function () { describe('date argument', function () { diff --git a/src/toZonedTime/index.js b/src/toZonedTime/index.js index eb4d99d..f05ca46 100644 --- a/src/toZonedTime/index.js +++ b/src/toZonedTime/index.js @@ -1,5 +1,5 @@ -import tzParseTimezone from '../_lib/tzParseTimezone/index.js' -import toDate from '../toDate/index.js' +import { tzParseTimezone } from '../_lib/tzParseTimezone' +import { toDate } from '../toDate' /** * @name toZonedTime @@ -25,7 +25,7 @@ import toDate from '../toDate/index.js' * const result = toZonedTime('2014-06-25T10:00:00.000Z', 'America/New_York') * //=> Jun 25 2014 06:00:00 */ -export default function toZonedTime(dirtyDate, timeZone, options) { +export function toZonedTime(dirtyDate, timeZone, options) { var date = toDate(dirtyDate, options) var offsetMilliseconds = tzParseTimezone(timeZone, date, true) diff --git a/src/toZonedTime/test.js b/src/toZonedTime/test.js index 8beb6ca..60be714 100644 --- a/src/toZonedTime/test.js +++ b/src/toZonedTime/test.js @@ -1,7 +1,7 @@ import assert from 'power-assert' import { format } from 'date-fns/format' -import toZonedTime from '.' -import newDateUTC from '../_lib/newDateUTC' +import { toZonedTime } from '.' +import { newDateUTC } from '../_lib/newDateUTC' describe('toZonedTime', function () { it('returns the equivalent date at the time zone for a date string and IANA tz', function () { From 5a782045fc9ef5fcd21c0fdc1b1f37e26695399a Mon Sep 17 00:00:00 2001 From: Marnus Weststrate Date: Thu, 4 Apr 2024 06:58:16 +0100 Subject: [PATCH 04/10] Remove redundant step from package.sh --- scripts/build/package.sh | 7 ------- 1 file changed, 7 deletions(-) diff --git a/scripts/build/package.sh b/scripts/build/package.sh index 1b68c42..c61ec32 100755 --- a/scripts/build/package.sh +++ b/scripts/build/package.sh @@ -59,11 +59,4 @@ find "$dir" -type f -name "benchmark.js" -delete # Copy esm package.json cp ./src/esm/package.json "$dir/esm/package.json" -# Rewrite import paths to use esm version of date-fns -# todo Restore once date-fns supports ESM: https://github.com/date-fns/date-fns/issues/1781 -# for fnFile in $(find $dir/esm -maxdepth 3 -mindepth 2 -type f -name index.js) -# do -# sed -i "s/from 'date-fns/from 'date-fns\/esm/" "$fnFile" -# done - ./scripts/build/packages.js From 6cfdcb92cb4141c2111f392b7a12d0b84f54fd1b Mon Sep 17 00:00:00 2001 From: Marnus Weststrate Date: Thu, 4 Apr 2024 07:00:26 +0100 Subject: [PATCH 05/10] 3.0.0-beta.4 --- CHANGELOG.md | 3 ++- package.json | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1a550d1..350ba2e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,8 +1,9 @@ -### v3.0.0 +### v3.0.0-beta.4 (4 April 2024) - [BREAKING CHANGE] Rename `utcToZonedTime` to `toZonedTime` - [BREAKING CHANGE] Rename `zonedTimeToUtc` to `fromZonedTime` - [BREAKING CHANGE] Remove `flow` support +- [BREAKING CHANGE] All functions are now exported as named exports ### v3.0.0-beta.3 (28 March 2024) diff --git a/package.json b/package.json index 4de5f7d..4cc10b1 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "date-fns-tz", - "version": "3.0.0-beta.3", + "version": "3.0.0-beta.4", "sideEffects": false, "description": "Time zone support for date-fns v3 with the Intl API", "author": "Marnus Weststrate ", From 01e6bdf2041917b4c9b1a47dbbb676df39283bb1 Mon Sep 17 00:00:00 2001 From: Marnus Weststrate Date: Thu, 4 Apr 2024 22:49:18 +0100 Subject: [PATCH 06/10] Fix ESM import paths --- scripts/build/fp.js | 4 ++-- src/_lib/tzParseTimezone/index.js | 8 ++++---- src/format/index.js | 10 +++++----- src/formatInTimeZone/index.js | 4 ++-- src/fp/format/index.js | 4 ++-- src/fp/formatInTimeZone/index.js | 4 ++-- src/fp/formatInTimeZoneWithOptions/index.js | 4 ++-- src/fp/formatWithOptions/index.js | 4 ++-- src/fp/fromZonedTime/index.js | 4 ++-- src/fp/fromZonedTimeWithOptions/index.js | 4 ++-- src/fp/getTimezoneOffset/index.js | 4 ++-- src/fp/toDate/index.js | 4 ++-- src/fp/toDateWithOptions/index.js | 4 ++-- src/fp/toZonedTime/index.js | 4 ++-- src/fp/toZonedTimeWithOptions/index.js | 4 ++-- src/fromZonedTime/index.js | 8 ++++---- src/toDate/index.js | 6 +++--- src/toZonedTime/index.js | 4 ++-- 18 files changed, 44 insertions(+), 44 deletions(-) diff --git a/scripts/build/fp.js b/scripts/build/fp.js index b7c162c..d957015 100755 --- a/scripts/build/fp.js +++ b/scripts/build/fp.js @@ -26,8 +26,8 @@ buildFP(fpFns) function getFPFn(resultFnName, initialFnName, arity) { return [generatedAutomaticallyMessage] .concat('') - .concat(`import { ${initialFnName} as fn } from '../../${initialFnName}'`) - .concat(`import { convertToFP } from '../_lib/convertToFP'`) + .concat(`import { ${initialFnName} as fn } from '../../${initialFnName}/index.js'`) + .concat(`import { convertToFP } from '../_lib/convertToFP/index.js'`) .concat('') .concat(`export const ${resultFnName} = convertToFP(fn, ${arity})`) .concat('') diff --git a/src/_lib/tzParseTimezone/index.js b/src/_lib/tzParseTimezone/index.js index d6f9150..c801cc4 100644 --- a/src/_lib/tzParseTimezone/index.js +++ b/src/_lib/tzParseTimezone/index.js @@ -1,5 +1,5 @@ -import { tzTokenizeDate } from '../tzTokenizeDate' -import { newDateUTC } from '../newDateUTC' +import { tzTokenizeDate } from '../tzTokenizeDate/index.js' +import { newDateUTC } from '../newDateUTC/index.js' var MILLISECONDS_IN_HOUR = 3600000 var MILLISECONDS_IN_MINUTE = 60000 @@ -78,7 +78,7 @@ function toUtcDate(date) { date.getHours(), date.getMinutes(), date.getSeconds(), - date.getMilliseconds(), + date.getMilliseconds() ) } @@ -93,7 +93,7 @@ function calcOffset(date, timezoneString) { tokens[3] % 24, tokens[4], tokens[5], - 0, + 0 ).getTime() var asTS = date.getTime() diff --git a/src/format/index.js b/src/format/index.js index f963a53..08d50d9 100644 --- a/src/format/index.js +++ b/src/format/index.js @@ -1,6 +1,6 @@ import { format as dateFnsFormat } from 'date-fns/format' -import { formatters } from './formatters' -import { toDate } from '../toDate' +import { formatters } from './formatters/index.js' +import { toDate } from '../toDate/index.js' var tzFormattingTokensRegExp = /([xXOz]+)|''|'(''|[^'])+('|$)/g @@ -326,14 +326,14 @@ export function format(dirtyDate, dirtyFormatStr, dirtyOptions) { // Work through each match and replace the tz token in the format string with the quoted // formatted time zone so the remaining tokens can be filled in by date-fns#format. formatStr = matches.reduce(function (result, token) { - if (token[0] === '\'') { + if (token[0] === "'") { return result // This is a quoted portion, matched only to ensure we don't match inside it } var pos = result.indexOf(token) - var precededByQuotedSection = result[pos - 1] === '\'' + var precededByQuotedSection = result[pos - 1] === "'" var replaced = result.replace( token, - '\'' + formatters[token[0]](date, token, null, options) + '\'', + "'" + formatters[token[0]](date, token, null, options) + "'" ) // If the replacement results in two adjoining quoted strings, the back to back quotes // are removed, so it doesn't look like an escaped quote. diff --git a/src/formatInTimeZone/index.js b/src/formatInTimeZone/index.js index 45136f7..629029f 100644 --- a/src/formatInTimeZone/index.js +++ b/src/formatInTimeZone/index.js @@ -1,5 +1,5 @@ -import { format } from '../format' -import { toZonedTime } from '../toZonedTime' +import { format } from '../format/index.js' +import { toZonedTime } from '../toZonedTime/index.js' import cloneDeep from 'lodash.clonedeep' /** diff --git a/src/fp/format/index.js b/src/fp/format/index.js index d03dfa4..fd2e9d7 100644 --- a/src/fp/format/index.js +++ b/src/fp/format/index.js @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.js`. Please, don't change it. -import { format as fn } from '../../format' -import { convertToFP } from '../_lib/convertToFP' +import { format as fn } from '../../format/index.js' +import { convertToFP } from '../_lib/convertToFP/index.js' export const format = convertToFP(fn, 2) diff --git a/src/fp/formatInTimeZone/index.js b/src/fp/formatInTimeZone/index.js index 9bb431a..5c541d4 100644 --- a/src/fp/formatInTimeZone/index.js +++ b/src/fp/formatInTimeZone/index.js @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.js`. Please, don't change it. -import { formatInTimeZone as fn } from '../../formatInTimeZone' -import { convertToFP } from '../_lib/convertToFP' +import { formatInTimeZone as fn } from '../../formatInTimeZone/index.js' +import { convertToFP } from '../_lib/convertToFP/index.js' export const formatInTimeZone = convertToFP(fn, 3) diff --git a/src/fp/formatInTimeZoneWithOptions/index.js b/src/fp/formatInTimeZoneWithOptions/index.js index 51e0f92..4c01c29 100644 --- a/src/fp/formatInTimeZoneWithOptions/index.js +++ b/src/fp/formatInTimeZoneWithOptions/index.js @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.js`. Please, don't change it. -import { formatInTimeZone as fn } from '../../formatInTimeZone' -import { convertToFP } from '../_lib/convertToFP' +import { formatInTimeZone as fn } from '../../formatInTimeZone/index.js' +import { convertToFP } from '../_lib/convertToFP/index.js' export const formatInTimeZoneWithOptions = convertToFP(fn, 4) diff --git a/src/fp/formatWithOptions/index.js b/src/fp/formatWithOptions/index.js index 5ba9819..2cb2760 100644 --- a/src/fp/formatWithOptions/index.js +++ b/src/fp/formatWithOptions/index.js @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.js`. Please, don't change it. -import { format as fn } from '../../format' -import { convertToFP } from '../_lib/convertToFP' +import { format as fn } from '../../format/index.js' +import { convertToFP } from '../_lib/convertToFP/index.js' export const formatWithOptions = convertToFP(fn, 3) diff --git a/src/fp/fromZonedTime/index.js b/src/fp/fromZonedTime/index.js index 2916c5c..362370f 100644 --- a/src/fp/fromZonedTime/index.js +++ b/src/fp/fromZonedTime/index.js @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.js`. Please, don't change it. -import { fromZonedTime as fn } from '../../fromZonedTime' -import { convertToFP } from '../_lib/convertToFP' +import { fromZonedTime as fn } from '../../fromZonedTime/index.js' +import { convertToFP } from '../_lib/convertToFP/index.js' export const fromZonedTime = convertToFP(fn, 2) diff --git a/src/fp/fromZonedTimeWithOptions/index.js b/src/fp/fromZonedTimeWithOptions/index.js index 859ea25..747c7e4 100644 --- a/src/fp/fromZonedTimeWithOptions/index.js +++ b/src/fp/fromZonedTimeWithOptions/index.js @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.js`. Please, don't change it. -import { fromZonedTime as fn } from '../../fromZonedTime' -import { convertToFP } from '../_lib/convertToFP' +import { fromZonedTime as fn } from '../../fromZonedTime/index.js' +import { convertToFP } from '../_lib/convertToFP/index.js' export const fromZonedTimeWithOptions = convertToFP(fn, 3) diff --git a/src/fp/getTimezoneOffset/index.js b/src/fp/getTimezoneOffset/index.js index 001e1cd..0732840 100644 --- a/src/fp/getTimezoneOffset/index.js +++ b/src/fp/getTimezoneOffset/index.js @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.js`. Please, don't change it. -import { getTimezoneOffset as fn } from '../../getTimezoneOffset' -import { convertToFP } from '../_lib/convertToFP' +import { getTimezoneOffset as fn } from '../../getTimezoneOffset/index.js' +import { convertToFP } from '../_lib/convertToFP/index.js' export const getTimezoneOffset = convertToFP(fn, 2) diff --git a/src/fp/toDate/index.js b/src/fp/toDate/index.js index 1a08951..89ab442 100644 --- a/src/fp/toDate/index.js +++ b/src/fp/toDate/index.js @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.js`. Please, don't change it. -import { toDate as fn } from '../../toDate' -import { convertToFP } from '../_lib/convertToFP' +import { toDate as fn } from '../../toDate/index.js' +import { convertToFP } from '../_lib/convertToFP/index.js' export const toDate = convertToFP(fn, 1) diff --git a/src/fp/toDateWithOptions/index.js b/src/fp/toDateWithOptions/index.js index 09fa4d0..aa3a895 100644 --- a/src/fp/toDateWithOptions/index.js +++ b/src/fp/toDateWithOptions/index.js @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.js`. Please, don't change it. -import { toDate as fn } from '../../toDate' -import { convertToFP } from '../_lib/convertToFP' +import { toDate as fn } from '../../toDate/index.js' +import { convertToFP } from '../_lib/convertToFP/index.js' export const toDateWithOptions = convertToFP(fn, 2) diff --git a/src/fp/toZonedTime/index.js b/src/fp/toZonedTime/index.js index 2b5174f..22c0748 100644 --- a/src/fp/toZonedTime/index.js +++ b/src/fp/toZonedTime/index.js @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.js`. Please, don't change it. -import { toZonedTime as fn } from '../../toZonedTime' -import { convertToFP } from '../_lib/convertToFP' +import { toZonedTime as fn } from '../../toZonedTime/index.js' +import { convertToFP } from '../_lib/convertToFP/index.js' export const toZonedTime = convertToFP(fn, 2) diff --git a/src/fp/toZonedTimeWithOptions/index.js b/src/fp/toZonedTimeWithOptions/index.js index 4cf1f17..d2b5082 100644 --- a/src/fp/toZonedTimeWithOptions/index.js +++ b/src/fp/toZonedTimeWithOptions/index.js @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.js`. Please, don't change it. -import { toZonedTime as fn } from '../../toZonedTime' -import { convertToFP } from '../_lib/convertToFP' +import { toZonedTime as fn } from '../../toZonedTime/index.js' +import { convertToFP } from '../_lib/convertToFP/index.js' export const toZonedTimeWithOptions = convertToFP(fn, 3) diff --git a/src/fromZonedTime/index.js b/src/fromZonedTime/index.js index d478c8a..73ebdfd 100644 --- a/src/fromZonedTime/index.js +++ b/src/fromZonedTime/index.js @@ -1,7 +1,7 @@ -import { toDate } from '../toDate' -import { tzPattern } from '../_lib/tzPattern' -import { tzParseTimezone } from '../_lib/tzParseTimezone' -import { newDateUTC } from '../_lib/newDateUTC' +import { toDate } from '../toDate/index.js' +import { tzPattern } from '../_lib/tzPattern/index.js' +import { tzParseTimezone } from '../_lib/tzParseTimezone/index.js' +import { newDateUTC } from '../_lib/newDateUTC/index.js' import cloneDeep from 'lodash.clonedeep' /** diff --git a/src/toDate/index.js b/src/toDate/index.js index 2d1e318..845ade9 100644 --- a/src/toDate/index.js +++ b/src/toDate/index.js @@ -1,6 +1,6 @@ -import { getTimezoneOffsetInMilliseconds } from '../_lib/getTimezoneOffsetInMilliseconds' -import { tzParseTimezone } from '../_lib/tzParseTimezone' -import { tzPattern } from '../_lib/tzPattern' +import { getTimezoneOffsetInMilliseconds } from '../_lib/getTimezoneOffsetInMilliseconds/index.js' +import { tzParseTimezone } from '../_lib/tzParseTimezone/index.js' +import { tzPattern } from '../_lib/tzPattern/index.js' var MILLISECONDS_IN_HOUR = 3600000 var MILLISECONDS_IN_MINUTE = 60000 diff --git a/src/toZonedTime/index.js b/src/toZonedTime/index.js index f05ca46..9084ee4 100644 --- a/src/toZonedTime/index.js +++ b/src/toZonedTime/index.js @@ -1,5 +1,5 @@ -import { tzParseTimezone } from '../_lib/tzParseTimezone' -import { toDate } from '../toDate' +import { tzParseTimezone } from '../_lib/tzParseTimezone/index.js' +import { toDate } from '../toDate/index.js' /** * @name toZonedTime From c9d9e79e90fa014d33824e645f3cac89933c9110 Mon Sep 17 00:00:00 2001 From: Marnus Weststrate Date: Thu, 4 Apr 2024 22:51:32 +0100 Subject: [PATCH 07/10] 3.0.0-beta.5 --- CHANGELOG.md | 4 ++++ package.json | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 350ba2e..310a597 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +### v3.0.0-beta.5 (4 April 2024) + +- [BUGFIX] Fix internal ESM import paths + ### v3.0.0-beta.4 (4 April 2024) - [BREAKING CHANGE] Rename `utcToZonedTime` to `toZonedTime` diff --git a/package.json b/package.json index 4cc10b1..9035948 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "date-fns-tz", - "version": "3.0.0-beta.4", + "version": "3.0.0-beta.5", "sideEffects": false, "description": "Time zone support for date-fns v3 with the Intl API", "author": "Marnus Weststrate ", From d437176b8b37dbdaa133bf6734800b707f5fb383 Mon Sep 17 00:00:00 2001 From: Marnus Weststrate Date: Thu, 4 Apr 2024 22:57:39 +0100 Subject: [PATCH 08/10] Fix ESM import paths --- src/format/formatters/index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/format/formatters/index.js b/src/format/formatters/index.js index c3cc3d8..3ec09ab 100644 --- a/src/format/formatters/index.js +++ b/src/format/formatters/index.js @@ -1,5 +1,5 @@ -import { tzIntlTimeZoneName } from '../../_lib/tzIntlTimeZoneName' -import { tzParseTimezone } from '../../_lib/tzParseTimezone' +import { tzIntlTimeZoneName } from '../../_lib/tzIntlTimeZoneName/index.js' +import { tzParseTimezone } from '../../_lib/tzParseTimezone/index.js' var MILLISECONDS_IN_MINUTE = 60 * 1000 From 1133e3c3992f706a688dc7bb5291418884a48e70 Mon Sep 17 00:00:00 2001 From: Marnus Weststrate Date: Thu, 4 Apr 2024 22:57:54 +0100 Subject: [PATCH 09/10] 3.0.0-beta.6 --- CHANGELOG.md | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 310a597..06cec3e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,4 @@ -### v3.0.0-beta.5 (4 April 2024) +### v3.0.0-beta.6 (4 April 2024) - [BUGFIX] Fix internal ESM import paths diff --git a/package.json b/package.json index 9035948..4314170 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "date-fns-tz", - "version": "3.0.0-beta.5", + "version": "3.0.0-beta.6", "sideEffects": false, "description": "Time zone support for date-fns v3 with the Intl API", "author": "Marnus Weststrate ", From 1cd68ff1c6bf3e50da819e7cdb528af24e07c00e Mon Sep 17 00:00:00 2001 From: Marnus Weststrate Date: Sat, 6 Apr 2024 06:52:40 +0100 Subject: [PATCH 10/10] v3 release notes --- CHANGELOG.md | 40 +++++++++++++++------------------------- 1 file changed, 15 insertions(+), 25 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 06cec3e..6f7756a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,30 +1,20 @@ -### v3.0.0-beta.6 (4 April 2024) - -- [BUGFIX] Fix internal ESM import paths - -### v3.0.0-beta.4 (4 April 2024) - -- [BREAKING CHANGE] Rename `utcToZonedTime` to `toZonedTime` -- [BREAKING CHANGE] Rename `zonedTimeToUtc` to `fromZonedTime` -- [BREAKING CHANGE] Remove `flow` support -- [BREAKING CHANGE] All functions are now exported as named exports - -### v3.0.0-beta.3 (28 March 2024) - -- [BUGFIX] Fix `date-fns` imports for `fp` by copying the `convertToFP` function - -### v3.0.0-beta.2 (26 March 2024) - -- [BUGFIX] Fix `date-fns` imports by copying the `getTimezoneOffsetInMilliseconds` (#272) - -### v3.0.0-beta.1 (22 March 2024) +### v3.0.0 (6 April 2024) +- [UPGRADE] Support `date-fns` v3 (#265) Thank you, @christopherklint97 - [BUGFIX] Correct import of `date-fns@v3` format and use Babel Webpack loader for mjs files (#271) -- [BUGFIX] Correct various other `date-fns@v3` imports - -### v3.0.0-beta.0 (9 March 2024) - -- [UPGRADE] Support date-fns v3 (#265) Thank you, @christopherklint97 +- [BREAKING CHANGE] `date-fns` v2 is no longer supported +- [BREAKING CHANGE] Renamed `utcToZonedTime` to `toZonedTime` to make the name less confusing, just search & replace +- [BREAKING CHANGE] Renamed `zonedTimeToUtc` to `fromZonedTime` to make the name less confusing, just search & replace +- [BREAKING CHANGE] All functions are now exported using named exports, this requires changing direct + imports from `import formatInTimeZone from 'date-fns-tz/formatInTimeZone'` to + `import { formatInTimeZone } from 'date-fns-tz/formatInTimeZone'` +- [BREAKING CHANGE] Functions now don’t check the number of passed arguments, delegating this task to type checkers + (This isn't fully implemented yet, but it should be the assumption moving forward, as it is in `date-fns`) +- [BREAKING CHANGE] Arguments are not explicitly converted to the target types. Instead, they are passed as is, + delegating this task to type checkers (This isn't fully implemented yet, but it should be the assumption + moving forward, as it is in `date-fns`) +- [BREAKING CHANGE] IE is no longer supported since `date-fns` no longer supports it +- [BREAKING CHANGE] Removed `flow` support since `date-fns` also removed it ### v2.0.1 (9 March 2024)