summaryrefslogtreecommitdiff
path: root/date-fns/src/isSameQuarter
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/isSameQuarter
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/isSameQuarter')
-rw-r--r--date-fns/src/isSameQuarter/benchmark.js23
-rw-r--r--date-fns/src/isSameQuarter/index.d.ts4
-rw-r--r--date-fns/src/isSameQuarter/index.js.flow55
-rw-r--r--date-fns/src/isSameQuarter/index.ts33
-rw-r--r--date-fns/src/isSameQuarter/test.ts51
5 files changed, 166 insertions, 0 deletions
diff --git a/date-fns/src/isSameQuarter/benchmark.js b/date-fns/src/isSameQuarter/benchmark.js
new file mode 100644
index 0000000..ad6b2f4
--- /dev/null
+++ b/date-fns/src/isSameQuarter/benchmark.js
@@ -0,0 +1,23 @@
+// @flow
+/* eslint-env mocha */
+/* global suite, benchmark */
+
+import isSameQuarter from '.'
+import moment from 'moment'
+
+suite('isSameQuarter', function () {
+ benchmark('date-fns', function () {
+ return isSameQuarter(this.dateA, this.dateB)
+ })
+
+ benchmark('Moment.js', function () {
+ return this.momentA.isSame(this.momentB, 'quarter')
+ })
+}, {
+ setup: function () {
+ this.dateA = new Date()
+ this.momentA = moment()
+ this.dateB = new Date(this.dateA.getTime() + 604800000)
+ this.momentB = this.momentA.clone().add(7, 'days')
+ }
+})
diff --git a/date-fns/src/isSameQuarter/index.d.ts b/date-fns/src/isSameQuarter/index.d.ts
new file mode 100644
index 0000000..584660a
--- /dev/null
+++ b/date-fns/src/isSameQuarter/index.d.ts
@@ -0,0 +1,4 @@
+// This file is generated automatically by `scripts/build/typings.js`. Please, don't change it.
+
+import { isSameQuarter } from 'date-fns'
+export default isSameQuarter
diff --git a/date-fns/src/isSameQuarter/index.js.flow b/date-fns/src/isSameQuarter/index.js.flow
new file mode 100644
index 0000000..55ea578
--- /dev/null
+++ b/date-fns/src/isSameQuarter/index.js.flow
@@ -0,0 +1,55 @@
+// @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: (
+ dateLeft: Date | number,
+ dateRight: Date | number
+) => boolean
diff --git a/date-fns/src/isSameQuarter/index.ts b/date-fns/src/isSameQuarter/index.ts
new file mode 100644
index 0000000..84d84d4
--- /dev/null
+++ b/date-fns/src/isSameQuarter/index.ts
@@ -0,0 +1,33 @@
+import startOfQuarter from '../startOfQuarter/index'
+import requiredArgs from '../_lib/requiredArgs/index'
+
+/**
+ * @name isSameQuarter
+ * @category Quarter Helpers
+ * @summary Are the given dates in the same year quarter?
+ *
+ * @description
+ * Are the given dates in the same year quarter?
+ *
+ * ### 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} dateLeft - the first date to check
+ * @param {Date|Number} dateRight - the second date to check
+ * @returns {Boolean} the dates are in the same quarter
+ * @throws {TypeError} 2 arguments required
+ *
+ * @example
+ * // Are 1 January 2014 and 8 March 2014 in the same quarter?
+ * var result = isSameQuarter(new Date(2014, 0, 1), new Date(2014, 2, 8))
+ * //=> true
+ */
+export default function isSameQuarter(dirtyDateLeft: Date | number, dirtyDateRight: Date | number): boolean {
+ requiredArgs(2, arguments)
+
+ const dateLeftStartOfQuarter = startOfQuarter(dirtyDateLeft)
+ const dateRightStartOfQuarter = startOfQuarter(dirtyDateRight)
+
+ return dateLeftStartOfQuarter.getTime() === dateRightStartOfQuarter.getTime()
+}
diff --git a/date-fns/src/isSameQuarter/test.ts b/date-fns/src/isSameQuarter/test.ts
new file mode 100644
index 0000000..67fd437
--- /dev/null
+++ b/date-fns/src/isSameQuarter/test.ts
@@ -0,0 +1,51 @@
+// @flow
+/* eslint-env mocha */
+
+import assert from 'power-assert'
+import isSameQuarter from '.'
+
+describe('isSameQuarter', function() {
+ it('returns true if the given dates have the same quarter (and year)', function() {
+ const result = isSameQuarter(
+ new Date(2014, 0 /* Jan */, 1),
+ new Date(2014, 2 /* Mar */, 8)
+ )
+ assert(result === true)
+ })
+
+ it('returns false if the given dates have different quarters', function() {
+ const result = isSameQuarter(
+ new Date(2014, 0 /* Jan */, 1),
+ new Date(2013, 8 /* Sep */, 25)
+ )
+ assert(result === false)
+ })
+
+ it('accepts a timestamp', function() {
+ const result = isSameQuarter(
+ new Date(2014, 6 /* Jul */, 2).getTime(),
+ new Date(2014, 8 /* Sep */, 25).getTime()
+ )
+ assert(result === true)
+ })
+
+ it('returns false if the first date is `Invalid Date`', function() {
+ const result = isSameQuarter(new Date(NaN), new Date(1989, 6 /* Jul */, 10))
+ assert(result === false)
+ })
+
+ it('returns false if the second date is `Invalid Date`', function() {
+ const result = isSameQuarter(new Date(1987, 1 /* Feb */, 11), new Date(NaN))
+ assert(result === false)
+ })
+
+ it('returns false if the both dates are `Invalid Date`', function() {
+ const result = isSameQuarter(new Date(NaN), new Date(NaN))
+ assert(result === false)
+ })
+
+ it('throws TypeError exception if passed less than 2 arguments', function() {
+ assert.throws(isSameQuarter.bind(null), TypeError)
+ assert.throws(isSameQuarter.bind(null, 1), TypeError)
+ })
+})