summaryrefslogtreecommitdiff
path: root/date-fns/src/startOfISOWeekYear
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/startOfISOWeekYear
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/startOfISOWeekYear')
-rw-r--r--date-fns/src/startOfISOWeekYear/benchmark.js15
-rw-r--r--date-fns/src/startOfISOWeekYear/index.d.ts4
-rw-r--r--date-fns/src/startOfISOWeekYear/index.js.flow52
-rw-r--r--date-fns/src/startOfISOWeekYear/index.ts39
-rw-r--r--date-fns/src/startOfISOWeekYear/test.ts51
5 files changed, 161 insertions, 0 deletions
diff --git a/date-fns/src/startOfISOWeekYear/benchmark.js b/date-fns/src/startOfISOWeekYear/benchmark.js
new file mode 100644
index 0000000..754d6c9
--- /dev/null
+++ b/date-fns/src/startOfISOWeekYear/benchmark.js
@@ -0,0 +1,15 @@
+// @flow
+/* eslint-env mocha */
+/* global suite, benchmark */
+
+import startOfISOWeekYear from '.'
+
+suite('startOfISOWeekYear', function () {
+ benchmark('date-fns', function () {
+ return startOfISOWeekYear(this.date)
+ })
+}, {
+ setup: function () {
+ this.date = new Date()
+ }
+})
diff --git a/date-fns/src/startOfISOWeekYear/index.d.ts b/date-fns/src/startOfISOWeekYear/index.d.ts
new file mode 100644
index 0000000..c29d7d0
--- /dev/null
+++ b/date-fns/src/startOfISOWeekYear/index.d.ts
@@ -0,0 +1,4 @@
+// This file is generated automatically by `scripts/build/typings.js`. Please, don't change it.
+
+import { startOfISOWeekYear } from 'date-fns'
+export default startOfISOWeekYear
diff --git a/date-fns/src/startOfISOWeekYear/index.js.flow b/date-fns/src/startOfISOWeekYear/index.js.flow
new file mode 100644
index 0000000..4b7c616
--- /dev/null
+++ b/date-fns/src/startOfISOWeekYear/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) => Date
diff --git a/date-fns/src/startOfISOWeekYear/index.ts b/date-fns/src/startOfISOWeekYear/index.ts
new file mode 100644
index 0000000..9417ed4
--- /dev/null
+++ b/date-fns/src/startOfISOWeekYear/index.ts
@@ -0,0 +1,39 @@
+import getISOWeekYear from '../getISOWeekYear/index'
+import startOfISOWeek from '../startOfISOWeek/index'
+import requiredArgs from '../_lib/requiredArgs/index'
+
+/**
+ * @name startOfISOWeekYear
+ * @category ISO Week-Numbering Year Helpers
+ * @summary Return the start of an ISO week-numbering year for the given date.
+ *
+ * @description
+ * Return the start of an ISO week-numbering year,
+ * which always starts 3 days before the year's first Thursday.
+ * The result will be in the local timezone.
+ *
+ * ISO week-numbering year: http://en.wikipedia.org/wiki/ISO_week_date
+ *
+ * ### 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 original date
+ * @returns {Date} the start of an ISO week-numbering year
+ * @throws {TypeError} 1 argument required
+ *
+ * @example
+ * // The start of an ISO week-numbering year for 2 July 2005:
+ * const result = startOfISOWeekYear(new Date(2005, 6, 2))
+ * //=> Mon Jan 03 2005 00:00:00
+ */
+export default function startOfISOWeekYear(dirtyDate: Date | number): Date {
+ requiredArgs(1, arguments)
+
+ const year = getISOWeekYear(dirtyDate)
+ const fourthOfJanuary = new Date(0)
+ fourthOfJanuary.setFullYear(year, 0, 4)
+ fourthOfJanuary.setHours(0, 0, 0, 0)
+ const date = startOfISOWeek(fourthOfJanuary)
+ return date
+}
diff --git a/date-fns/src/startOfISOWeekYear/test.ts b/date-fns/src/startOfISOWeekYear/test.ts
new file mode 100644
index 0000000..104c632
--- /dev/null
+++ b/date-fns/src/startOfISOWeekYear/test.ts
@@ -0,0 +1,51 @@
+// @flow
+/* eslint-env mocha */
+
+import assert from 'power-assert'
+import startOfISOWeekYear from '.'
+
+describe('startOfISOWeekYear', function() {
+ it('returns the date with the time set to 00:00:00 and the date set to the first day of an ISO year', function() {
+ const result = startOfISOWeekYear(new Date(2009, 0 /* Jan */, 1, 16, 0))
+ assert.deepEqual(result, new Date(2008, 11 /* Dec */, 29, 0, 0, 0, 0))
+ })
+
+ it('accepts a timestamp', function() {
+ const result = startOfISOWeekYear(
+ new Date(2005, 0 /* Jan */, 1, 6, 0).getTime()
+ )
+ assert.deepEqual(result, new Date(2003, 11 /* Dec */, 29, 0, 0, 0, 0))
+ })
+
+ it('does not mutate the original date', function() {
+ const date = new Date(2014, 6 /* Jul */, 2)
+ startOfISOWeekYear(date)
+ assert.deepEqual(date, new Date(2014, 6 /* Jul */, 2))
+ })
+
+ it('handles dates before 100 AD', function() {
+ const initialDate = new Date(0)
+ initialDate.setFullYear(9, 0 /* Jan */, 1)
+ initialDate.setHours(0, 0, 0, 0)
+ const expectedResult = new Date(0)
+ expectedResult.setFullYear(8, 11 /* Dec */, 29)
+ expectedResult.setHours(0, 0, 0, 0)
+ const result = startOfISOWeekYear(initialDate)
+ assert.deepEqual(result, expectedResult)
+ })
+
+ it('correctly handles years in which 4 January is Sunday', function() {
+ const result = startOfISOWeekYear(new Date(2009, 6 /* Jul */, 2))
+ assert.deepEqual(result, new Date(2008, 11 /* Dec */, 29))
+ })
+
+ it('returns `Invalid Date` if the given date is invalid', function() {
+ const result = startOfISOWeekYear(new Date(NaN))
+ //@ts-expect-error
+ assert(result instanceof Date && isNaN(result))
+ })
+
+ it('throws TypeError exception if passed less than 1 argument', function() {
+ assert.throws(startOfISOWeekYear.bind(null), TypeError)
+ })
+})