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/isThisISOWeek | |
parent | f26125e039143b92dc0d84e7775f508ab0cdcaa8 (diff) | |
download | node-vendor-38acabfa6089ab8ac469c12b5f55022fb96935e5.tar.gz node-vendor-38acabfa6089ab8ac469c12b5f55022fb96935e5.tar.bz2 node-vendor-38acabfa6089ab8ac469c12b5f55022fb96935e5.zip |
Diffstat (limited to 'date-fns/src/isThisISOWeek')
-rw-r--r-- | date-fns/src/isThisISOWeek/benchmark.js | 20 | ||||
-rw-r--r-- | date-fns/src/isThisISOWeek/index.d.ts | 4 | ||||
-rw-r--r-- | date-fns/src/isThisISOWeek/index.js.flow | 52 | ||||
-rw-r--r-- | date-fns/src/isThisISOWeek/index.ts | 36 | ||||
-rw-r--r-- | date-fns/src/isThisISOWeek/test.ts | 36 |
5 files changed, 148 insertions, 0 deletions
diff --git a/date-fns/src/isThisISOWeek/benchmark.js b/date-fns/src/isThisISOWeek/benchmark.js new file mode 100644 index 0000000..d036d61 --- /dev/null +++ b/date-fns/src/isThisISOWeek/benchmark.js @@ -0,0 +1,20 @@ +// @flow +/* eslint-env mocha */ + +/* global suite, benchmark */ + +import isThisISOWeek from '.' + +suite( + 'isThisISOWeek', + () => { + benchmark('date-fns', function() { + return isThisISOWeek(this.date) + }) + }, + { + setup: function() { + this.date = new Date() + } + } +) diff --git a/date-fns/src/isThisISOWeek/index.d.ts b/date-fns/src/isThisISOWeek/index.d.ts new file mode 100644 index 0000000..4fb42e8 --- /dev/null +++ b/date-fns/src/isThisISOWeek/index.d.ts @@ -0,0 +1,4 @@ +// This file is generated automatically by `scripts/build/typings.js`. Please, don't change it. + +import { isThisISOWeek } from 'date-fns' +export default isThisISOWeek diff --git a/date-fns/src/isThisISOWeek/index.js.flow b/date-fns/src/isThisISOWeek/index.js.flow new file mode 100644 index 0000000..d3f01ee --- /dev/null +++ b/date-fns/src/isThisISOWeek/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/isThisISOWeek/index.ts b/date-fns/src/isThisISOWeek/index.ts new file mode 100644 index 0000000..6841b50 --- /dev/null +++ b/date-fns/src/isThisISOWeek/index.ts @@ -0,0 +1,36 @@ +import isSameISOWeek from '../isSameISOWeek/index' +import requiredArgs from '../_lib/requiredArgs/index' + +/** + * @name isThisISOWeek + * @category ISO Week Helpers + * @summary Is the given date in the same ISO week as the current date? + * @pure false + * + * @description + * Is the given date in the same ISO week as the current date? + * + * ISO week-numbering year: http://en.wikipedia.org/wiki/ISO_week_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 ISO week + * @throws {TypeError} 1 argument required + * + * @example + * // If today is 25 September 2014, is 22 September 2014 in this ISO week? + * var result = isThisISOWeek(new Date(2014, 8, 22)) + * //=> true + */ + +export default function isThisISOWeek(dirtyDate: Date | number): boolean { + requiredArgs(1, arguments) + + return isSameISOWeek(dirtyDate, Date.now()) +} diff --git a/date-fns/src/isThisISOWeek/test.ts b/date-fns/src/isThisISOWeek/test.ts new file mode 100644 index 0000000..0fe319e --- /dev/null +++ b/date-fns/src/isThisISOWeek/test.ts @@ -0,0 +1,36 @@ +// @flow +/* eslint-env mocha */ + +import assert from 'assert' +import sinon from 'sinon' +import isThisISOWeek from '.' + +describe('isSameISOWeek', () => { + let clock + beforeEach(() => { + clock = sinon.useFakeTimers(new Date(2014, 8 /* Sep */, 25).getTime()) + }) + + afterEach(() => { + clock.restore() + }) + + it('returns true if the given date and the current date have the same ISO week', () => { + const date = new Date(2014, 8 /* Sep */, 22) + assert(isThisISOWeek(date) === true) + }) + + it('returns false if the given date and the current date have different ISO weeks', () => { + const date = new Date(2014, 8 /* Sep */, 21) + assert(isThisISOWeek(date) === false) + }) + + it('accepts a timestamp', () => { + const date = new Date(2014, 8 /* Sep */, 29).getTime() + assert(isThisISOWeek(date) === false) + }) + + it('throws TypeError exception if passed less than 1 argument', function() { + assert.throws(isThisISOWeek.bind(null), TypeError) + }) +}) |