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