diff options
author | Sebastian <sebasjm@gmail.com> | 2021-08-23 16:46:06 -0300 |
---|---|---|
committer | Sebastian <sebasjm@gmail.com> | 2021-08-23 16:48:30 -0300 |
commit | 38acabfa6089ab8ac469c12b5f55022fb96935e5 (patch) | |
tree | 453dbf70000cc5e338b06201af1eaca8343f8f73 /date-fns/src/endOfTomorrow | |
parent | f26125e039143b92dc0d84e7775f508ab0cdcaa8 (diff) | |
download | node-vendor-38acabfa6089ab8ac469c12b5f55022fb96935e5.tar.gz node-vendor-38acabfa6089ab8ac469c12b5f55022fb96935e5.tar.bz2 node-vendor-38acabfa6089ab8ac469c12b5f55022fb96935e5.zip |
Diffstat (limited to 'date-fns/src/endOfTomorrow')
-rw-r--r-- | date-fns/src/endOfTomorrow/benchmark.js | 9 | ||||
-rw-r--r-- | date-fns/src/endOfTomorrow/index.d.ts | 4 | ||||
-rw-r--r-- | date-fns/src/endOfTomorrow/index.js.flow | 52 | ||||
-rw-r--r-- | date-fns/src/endOfTomorrow/index.ts | 34 | ||||
-rw-r--r-- | date-fns/src/endOfTomorrow/test.ts | 34 |
5 files changed, 133 insertions, 0 deletions
diff --git a/date-fns/src/endOfTomorrow/benchmark.js b/date-fns/src/endOfTomorrow/benchmark.js new file mode 100644 index 0000000..c2b7e6b --- /dev/null +++ b/date-fns/src/endOfTomorrow/benchmark.js @@ -0,0 +1,9 @@ +// @flow +/* eslint-env mocha */ +/* global suite, benchmark */ + +import endOfTomorrow from '.' + +suite('endOfTomorrow', () => { + benchmark('date-fns', () => endOfTomorrow()) +}) diff --git a/date-fns/src/endOfTomorrow/index.d.ts b/date-fns/src/endOfTomorrow/index.d.ts new file mode 100644 index 0000000..df5619e --- /dev/null +++ b/date-fns/src/endOfTomorrow/index.d.ts @@ -0,0 +1,4 @@ +// This file is generated automatically by `scripts/build/typings.js`. Please, don't change it. + +import { endOfTomorrow } from 'date-fns' +export default endOfTomorrow diff --git a/date-fns/src/endOfTomorrow/index.js.flow b/date-fns/src/endOfTomorrow/index.js.flow new file mode 100644 index 0000000..26bde32 --- /dev/null +++ b/date-fns/src/endOfTomorrow/index.js.flow @@ -0,0 +1,52 @@ +// @flow +// This file is generated automatically by `scripts/build/typings.js`. Please, don't change it. + +export type Interval = { + start: Date | number, + end: Date | number, +} + +export type Locale = { + code?: string, + formatDistance?: (...args: Array<any>) => any, + formatRelative?: (...args: Array<any>) => any, + localize?: { + ordinalNumber: (...args: Array<any>) => any, + era: (...args: Array<any>) => any, + quarter: (...args: Array<any>) => any, + month: (...args: Array<any>) => any, + day: (...args: Array<any>) => any, + dayPeriod: (...args: Array<any>) => any, + }, + formatLong?: { + date: (...args: Array<any>) => any, + time: (...args: Array<any>) => any, + dateTime: (...args: Array<any>) => any, + }, + match?: { + ordinalNumber: (...args: Array<any>) => any, + era: (...args: Array<any>) => any, + quarter: (...args: Array<any>) => any, + month: (...args: Array<any>) => any, + day: (...args: Array<any>) => any, + dayPeriod: (...args: Array<any>) => any, + }, + options?: { + weekStartsOn?: 0 | 1 | 2 | 3 | 4 | 5 | 6, + firstWeekContainsDate?: 1 | 2 | 3 | 4 | 5 | 6 | 7, + }, +} + +export type Duration = { + years?: number, + months?: number, + weeks?: number, + days?: number, + hours?: number, + minutes?: number, + seconds?: number, +} + +export type Day = 0 | 1 | 2 | 3 | 4 | 5 | 6 + +declare module.exports: () => Date diff --git a/date-fns/src/endOfTomorrow/index.ts b/date-fns/src/endOfTomorrow/index.ts new file mode 100644 index 0000000..a196b1d --- /dev/null +++ b/date-fns/src/endOfTomorrow/index.ts @@ -0,0 +1,34 @@ +/** + * @name endOfTomorrow + * @category Day Helpers + * @summary Return the end of tomorrow. + * @pure false + * + * @description + * Return the end of tomorrow. + * + * > ⚠️ Please note that this function is not present in the FP submodule as + * > it uses `new Date()` internally hence impure and can't be safely curried. + * + * ### v2.0.0 breaking changes: + * + * - [Changes that are common for the whole library](https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#Common-Changes). + * + * @returns {Date} the end of tomorrow + * + * @example + * // If today is 6 October 2014: + * const result = endOfTomorrow() + * //=> Tue Oct 7 2014 23:59:59.999 + */ +export default function endOfTomorrow(): Date { + const now = new Date() + const year = now.getFullYear() + const month = now.getMonth() + const day = now.getDate() + + const date = new Date(0) + date.setFullYear(year, month, day + 1) + date.setHours(23, 59, 59, 999) + return date +} diff --git a/date-fns/src/endOfTomorrow/test.ts b/date-fns/src/endOfTomorrow/test.ts new file mode 100644 index 0000000..01e5afe --- /dev/null +++ b/date-fns/src/endOfTomorrow/test.ts @@ -0,0 +1,34 @@ +// @flow +/* eslint-env mocha */ + +import assert from 'assert' +import sinon from 'sinon' +import endOfTomorrow from '.' + +describe('endOfTomorrow', function() { + it('returns tomorrow with the time settled to 23:59:59.999', function() { + const clock = sinon.useFakeTimers( + new Date(2014, 8 /* Sep */, 25, 14, 30, 45, 500).getTime() + ) + + const result = endOfTomorrow() + assert.deepEqual(result, new Date(2014, 8 /* Sep */, 26, 23, 59, 59, 999)) + + clock.restore() + }) + + it('handles dates before 100 AD', function() { + const now = new Date(0) + now.setFullYear(14, 8 /* Sep */, 25) + now.setHours(14, 30, 45, 500) + const clock = sinon.useFakeTimers(now.getTime()) + + const expectedResult = new Date(0) + expectedResult.setFullYear(14, 8 /* Sep */, 26) + expectedResult.setHours(23, 59, 59, 999) + const result = endOfTomorrow() + assert.deepEqual(result, expectedResult) + + clock.restore() + }) +}) |