aboutsummaryrefslogtreecommitdiff
path: root/date-fns/src/isThisMonth
diff options
context:
space:
mode:
authorSebastian <sebasjm@gmail.com>2021-08-23 16:46:06 -0300
committerSebastian <sebasjm@gmail.com>2021-08-23 16:48:30 -0300
commit38acabfa6089ab8ac469c12b5f55022fb96935e5 (patch)
tree453dbf70000cc5e338b06201af1eaca8343f8f73 /date-fns/src/isThisMonth
parentf26125e039143b92dc0d84e7775f508ab0cdcaa8 (diff)
downloadnode-vendor-38acabfa6089ab8ac469c12b5f55022fb96935e5.tar.gz
node-vendor-38acabfa6089ab8ac469c12b5f55022fb96935e5.tar.bz2
node-vendor-38acabfa6089ab8ac469c12b5f55022fb96935e5.zip
added web vendorsHEADmaster
Diffstat (limited to 'date-fns/src/isThisMonth')
-rw-r--r--date-fns/src/isThisMonth/benchmark.js20
-rw-r--r--date-fns/src/isThisMonth/index.d.ts4
-rw-r--r--date-fns/src/isThisMonth/index.js.flow52
-rw-r--r--date-fns/src/isThisMonth/index.ts34
-rw-r--r--date-fns/src/isThisMonth/test.ts37
5 files changed, 147 insertions, 0 deletions
diff --git a/date-fns/src/isThisMonth/benchmark.js b/date-fns/src/isThisMonth/benchmark.js
new file mode 100644
index 0000000..d3deed0
--- /dev/null
+++ b/date-fns/src/isThisMonth/benchmark.js
@@ -0,0 +1,20 @@
+// @flow
+/* eslint-env mocha */
+
+/* global suite, benchmark */
+
+import isThisMonth from '.'
+
+suite(
+ 'isThisMonth',
+ () => {
+ benchmark('date-fns', function() {
+ return isThisMonth(this.date)
+ })
+ },
+ {
+ setup: function() {
+ this.date = new Date()
+ }
+ }
+)
diff --git a/date-fns/src/isThisMonth/index.d.ts b/date-fns/src/isThisMonth/index.d.ts
new file mode 100644
index 0000000..eaf72fd
--- /dev/null
+++ b/date-fns/src/isThisMonth/index.d.ts
@@ -0,0 +1,4 @@
+// This file is generated automatically by `scripts/build/typings.js`. Please, don't change it.
+
+import { isThisMonth } from 'date-fns'
+export default isThisMonth
diff --git a/date-fns/src/isThisMonth/index.js.flow b/date-fns/src/isThisMonth/index.js.flow
new file mode 100644
index 0000000..d3f01ee
--- /dev/null
+++ b/date-fns/src/isThisMonth/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/isThisMonth/index.ts b/date-fns/src/isThisMonth/index.ts
new file mode 100644
index 0000000..3079dc1
--- /dev/null
+++ b/date-fns/src/isThisMonth/index.ts
@@ -0,0 +1,34 @@
+import isSameMonth from '../isSameMonth/index'
+import requiredArgs from '../_lib/requiredArgs/index'
+
+/**
+ * @name isThisMonth
+ * @category Month Helpers
+ * @summary Is the given date in the same month as the current date?
+ * @pure false
+ *
+ * @description
+ * Is the given date in the same month 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 month
+ * @throws {TypeError} 1 argument required
+ *
+ * @example
+ * // If today is 25 September 2014, is 15 September 2014 in this month?
+ * var result = isThisMonth(new Date(2014, 8, 15))
+ * //=> true
+ */
+
+export default function isThisMonth(dirtyDate: Date | number): boolean {
+ requiredArgs(1, arguments)
+
+ return isSameMonth(Date.now(), dirtyDate)
+}
diff --git a/date-fns/src/isThisMonth/test.ts b/date-fns/src/isThisMonth/test.ts
new file mode 100644
index 0000000..4c9d651
--- /dev/null
+++ b/date-fns/src/isThisMonth/test.ts
@@ -0,0 +1,37 @@
+// @flow
+/* eslint-env mocha */
+
+import assert from 'assert'
+import sinon from 'sinon'
+import isThisMonth from '.'
+
+describe('isThisMonth', () => {
+ let clock: sinon.SinonFakeTimers
+ 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 month (and year)', () => {
+ const date = new Date(2014, 8 /* Sep */, 15)
+ assert(isThisMonth(date) === true)
+ })
+
+ it('returns false if the given date and the current date have different months', () => {
+ const date = new Date(2013, 7 /* Aug */, 31)
+ assert(isThisMonth(date) === false)
+ })
+
+ it('accepts a timestamp', () => {
+ const date = new Date(2014, 8 /* Sep */, 30).getTime()
+ assert(isThisMonth(date) === true)
+ })
+
+ it('throws TypeError exception if passed less than 1 argument', function() {
+ // @ts-expect-error
+ assert.throws(isThisMonth.bind(null), TypeError)
+ })
+})