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/isThisQuarter | |
parent | f26125e039143b92dc0d84e7775f508ab0cdcaa8 (diff) | |
download | node-vendor-38acabfa6089ab8ac469c12b5f55022fb96935e5.tar.gz node-vendor-38acabfa6089ab8ac469c12b5f55022fb96935e5.tar.bz2 node-vendor-38acabfa6089ab8ac469c12b5f55022fb96935e5.zip |
Diffstat (limited to 'date-fns/src/isThisQuarter')
-rw-r--r-- | date-fns/src/isThisQuarter/benchmark.js | 20 | ||||
-rw-r--r-- | date-fns/src/isThisQuarter/index.d.ts | 4 | ||||
-rw-r--r-- | date-fns/src/isThisQuarter/index.js.flow | 52 | ||||
-rw-r--r-- | date-fns/src/isThisQuarter/index.ts | 33 | ||||
-rw-r--r-- | date-fns/src/isThisQuarter/test.ts | 37 |
5 files changed, 146 insertions, 0 deletions
diff --git a/date-fns/src/isThisQuarter/benchmark.js b/date-fns/src/isThisQuarter/benchmark.js new file mode 100644 index 0000000..2c0db5c --- /dev/null +++ b/date-fns/src/isThisQuarter/benchmark.js @@ -0,0 +1,20 @@ +// @flow +/* eslint-env mocha */ + +/* global suite, benchmark */ + +import isThisQuarter from '.' + +suite( + 'isThisQuarter', + () => { + benchmark('date-fns', function() { + return isThisQuarter(this.date) + }) + }, + { + setup: function() { + this.date = new Date() + } + } +) diff --git a/date-fns/src/isThisQuarter/index.d.ts b/date-fns/src/isThisQuarter/index.d.ts new file mode 100644 index 0000000..8c25708 --- /dev/null +++ b/date-fns/src/isThisQuarter/index.d.ts @@ -0,0 +1,4 @@ +// This file is generated automatically by `scripts/build/typings.js`. Please, don't change it. + +import { isThisQuarter } from 'date-fns' +export default isThisQuarter diff --git a/date-fns/src/isThisQuarter/index.js.flow b/date-fns/src/isThisQuarter/index.js.flow new file mode 100644 index 0000000..d3f01ee --- /dev/null +++ b/date-fns/src/isThisQuarter/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: Date | number) => boolean diff --git a/date-fns/src/isThisQuarter/index.ts b/date-fns/src/isThisQuarter/index.ts new file mode 100644 index 0000000..2d22060 --- /dev/null +++ b/date-fns/src/isThisQuarter/index.ts @@ -0,0 +1,33 @@ +import isSameQuarter from '../isSameQuarter/index' +import requiredArgs from '../_lib/requiredArgs/index' + +/** + * @name isThisQuarter + * @category Quarter Helpers + * @summary Is the given date in the same quarter as the current date? + * @pure false + * + * @description + * Is the given date in the same quarter as the current date? + * + * > ⚠️ Please note that this function is not present in the FP submodule as + * > it uses `Date.now()` 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). + * + * @param {Date|Number} date - the date to check + * @returns {Boolean} the date is in this quarter + * @throws {TypeError} 1 argument required + * + * @example + * // If today is 25 September 2014, is 2 July 2014 in this quarter? + * var result = isThisQuarter(new Date(2014, 6, 2)) + * //=> true + */ +export default function isThisQuarter(dirtyDate: Date | number): boolean { + requiredArgs(1, arguments) + + return isSameQuarter(Date.now(), dirtyDate) +} diff --git a/date-fns/src/isThisQuarter/test.ts b/date-fns/src/isThisQuarter/test.ts new file mode 100644 index 0000000..1a4b77f --- /dev/null +++ b/date-fns/src/isThisQuarter/test.ts @@ -0,0 +1,37 @@ +// @flow +/* eslint-env mocha */ + +import assert from 'assert' +import sinon from 'sinon' +import isThisQuarter from '.' + +describe('isThisQuarter', function() { + let clock: sinon.SinonFakeTimers + beforeEach(function() { + clock = sinon.useFakeTimers(new Date(2014, 8 /* Sep */, 25).getTime()) + }) + + afterEach(function() { + clock.restore() + }) + + it('returns true if the given date and the current date have the same quarter (and year)', function() { + const date = new Date(2014, 6 /* Jul */, 2) + assert(isThisQuarter(date) === true) + }) + + it('returns false if the given date and the current date have different quarters', function() { + const date = new Date(2014, 1 /* Feb */, 11) + assert(isThisQuarter(date) === false) + }) + + it('accepts a timestamp', function() { + const date = new Date(2014, 6 /* Jul */, 2).getTime() + assert(isThisQuarter(date) === true) + }) + + it('throws TypeError exception if passed less than 1 argument', function() { + // @ts-expect-error + assert.throws(isThisQuarter.bind(null), TypeError) + }) +}) |