diff options
Diffstat (limited to 'date-fns/src/isSunday')
-rw-r--r-- | date-fns/src/isSunday/benchmark.js | 15 | ||||
-rw-r--r-- | date-fns/src/isSunday/index.d.ts | 4 | ||||
-rw-r--r-- | date-fns/src/isSunday/index.js.flow | 52 | ||||
-rw-r--r-- | date-fns/src/isSunday/index.ts | 29 | ||||
-rw-r--r-- | date-fns/src/isSunday/test.ts | 31 |
5 files changed, 131 insertions, 0 deletions
diff --git a/date-fns/src/isSunday/benchmark.js b/date-fns/src/isSunday/benchmark.js new file mode 100644 index 0000000..9b65eb2 --- /dev/null +++ b/date-fns/src/isSunday/benchmark.js @@ -0,0 +1,15 @@ +// @flow +/* eslint-env mocha */ +/* global suite, benchmark */ + +import isSunday from '.' + +suite('isSunday', function () { + benchmark('date-fns', function () { + return isSunday(this.date) + }) +}, { + setup: function () { + this.date = new Date() + } +}) diff --git a/date-fns/src/isSunday/index.d.ts b/date-fns/src/isSunday/index.d.ts new file mode 100644 index 0000000..5830086 --- /dev/null +++ b/date-fns/src/isSunday/index.d.ts @@ -0,0 +1,4 @@ +// This file is generated automatically by `scripts/build/typings.js`. Please, don't change it. + +import { isSunday } from 'date-fns' +export default isSunday diff --git a/date-fns/src/isSunday/index.js.flow b/date-fns/src/isSunday/index.js.flow new file mode 100644 index 0000000..d3f01ee --- /dev/null +++ b/date-fns/src/isSunday/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/isSunday/index.ts b/date-fns/src/isSunday/index.ts new file mode 100644 index 0000000..cc3eba7 --- /dev/null +++ b/date-fns/src/isSunday/index.ts @@ -0,0 +1,29 @@ +import toDate from '../toDate/index' +import requiredArgs from '../_lib/requiredArgs/index' + +/** + * @name isSunday + * @category Weekday Helpers + * @summary Is the given date Sunday? + * + * @description + * Is the given date Sunday? + * + * ### 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 Sunday + * @throws {TypeError} 1 argument required + * + * @example + * // Is 21 September 2014 Sunday? + * var result = isSunday(new Date(2014, 8, 21)) + * //=> true + */ +export default function isSunday(dirtyDate: Date | number): boolean { + requiredArgs(1, arguments) + + return toDate(dirtyDate).getDay() === 0 +} diff --git a/date-fns/src/isSunday/test.ts b/date-fns/src/isSunday/test.ts new file mode 100644 index 0000000..8e68e20 --- /dev/null +++ b/date-fns/src/isSunday/test.ts @@ -0,0 +1,31 @@ +// @flow +/* eslint-env mocha */ + +import assert from 'power-assert' +import isSunday from '.' + +describe('isSunday', function() { + it('returns true if the given date is Sunday', function() { + const result = isSunday(new Date(2014, 8 /* Sep */, 21)) + assert(result === true) + }) + + it('returns false if the given date is not Sunday', function() { + const result = isSunday(new Date(2014, 8 /* Sep */, 25)) + assert(result === false) + }) + + it('accepts a timestamp', function() { + const result = isSunday(new Date(2014, 1 /* Feb */, 9).getTime()) + assert(result === true) + }) + + it('returns false if the given date is `Invalid Date`', function() { + const result = isSunday(new Date(NaN)) + assert(result === false) + }) + + it('throws TypeError exception if passed less than 1 argument', function() { + assert.throws(isSunday.bind(null), TypeError) + }) +}) |