Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- getDecade - startOfDecade - endOfDecade - lastDayOfDecade
- Loading branch information
1 parent
13efbc3
commit a817b3e
Showing
51 changed files
with
1,658 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// @flow | ||
/* eslint-env mocha */ | ||
/* global suite, benchmark */ | ||
|
||
import endOfDecade from '.' | ||
|
||
suite('endOfDecade', function () { | ||
benchmark('date-fns', function () { | ||
return endOfDecade(this.date) | ||
}) | ||
}, { | ||
setup: function () { | ||
this.date = new Date() | ||
} | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
// This file is generated automatically by `scripts/build/typings.js`. Please, don't change it. | ||
|
||
import {endOfDecade} from 'date-fns' | ||
export = endOfDecade |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import toDate from '../toDate/index.js' | ||
|
||
/** | ||
* @name endOfDecade | ||
* @category Decade Helpers | ||
* @summary Return the end of a decade for the given date. | ||
* | ||
* @description | ||
* Return the end of a decade for the given date. | ||
* | ||
* @param {Date|String|Number} date - the original date | ||
* @returns {Date} the end of a decade | ||
* @param {Options} [options] - the object with options. See [Options]{@link https://date-fns.org/docs/Options} | ||
* @param {0|1|2} [options.additionalDigits=2] - passed to `toDate`. See [toDate]{@link https://date-fns.org/docs/toDate} | ||
* @throws {TypeError} 1 argument required | ||
* @throws {RangeError} `options.additionalDigits` must be 0, 1 or 2 | ||
* | ||
* @example | ||
* // The end of a decade for 12 May 1984 00:00:00: | ||
* var result = endOfDecade(new Date(1984, 4, 12, 00, 00, 00)) | ||
* //=> Dec 31 1989 23:59:59.999 | ||
*/ | ||
export default function endOfDecade (dirtyDate, dirtyOptions) { | ||
if (arguments.length < 1) { | ||
throw new TypeError('1 argument required, but only ' + arguments.length + ' present') | ||
} | ||
|
||
var date = toDate(dirtyDate, dirtyOptions) | ||
var year = date.getFullYear() | ||
var decade = 9 + Math.floor(year / 10) * 10 | ||
date.setFullYear(decade, 11, 31) | ||
date.setHours(23, 59, 59, 999) | ||
return date | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// @flow | ||
// This file is generated automatically by `scripts/build/typings.js`. Please, don't change it. | ||
|
||
type Interval = { | ||
start: Date | string | number, | ||
end: Date | string | number | ||
} | ||
|
||
type Options = { | ||
weekStartsOn?: 0 | 1 | 2 | 3 | 4 | 5 | 6, | ||
firstWeekContainsDate?: 1 | 2 | 3 | 4 | 5 | 6 | 7, | ||
additionalDigits?: 0 | 1 | 2, | ||
locale?: Locale, | ||
includeSeconds?: boolean, | ||
addSuffix?: boolean, | ||
unit?: 'second' | 'minute' | 'hour' | 'day' | 'month' | 'year', | ||
roundingMethod?: 'floor' | 'ceil' | 'round' | ||
} | ||
|
||
type Locale = { | ||
formatDistance: Function, | ||
formatRelative: Function, | ||
localize: { | ||
ordinalNumber: Function, | ||
era: Function, | ||
quarter: Function, | ||
month: Function, | ||
day: Function, | ||
dayPeriod: Function | ||
}, | ||
formatLong: Object, | ||
date: Function, | ||
time: Function, | ||
dateTime: Function, | ||
match: { | ||
ordinalNumber: Function, | ||
era: Function, | ||
quarter: Function, | ||
month: Function, | ||
day: Function, | ||
dayPeriod: Function | ||
}, | ||
options?: { | ||
weekStartsOn?: 0 | 1 | 2 | 3 | 4 | 5 | 6, | ||
firstWeekContainsDate?: 1 | 2 | 3 | 4 | 5 | 6 | 7 | ||
} | ||
} | ||
|
||
declare module.exports: ( | ||
date: Date | string | number, | ||
options?: Options | ||
) => Date |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// @flow | ||
/* eslint-env mocha */ | ||
|
||
import assert from 'power-assert' | ||
import endOfDecade from '.' | ||
|
||
describe('endOfDecade', function () { | ||
it('returns the date with the time setted to 23:59:59.999 and the date setted to the last millisecond of a decade', function () { | ||
var date = new Date(2017, 3 /* Apr */, 10, 0, 0, 0) | ||
var result = endOfDecade(date) | ||
assert.deepEqual(result, | ||
new Date(2019, 11 /* Dec */, 31, 23, 59, 59, 999) | ||
) | ||
}) | ||
|
||
it('accepts a string', function () { | ||
var date = new Date(2004, 3 /* Apr */, 9, 0, 0, 0).toISOString() | ||
var result = endOfDecade(date) | ||
assert.deepEqual(result, | ||
new Date(2009, 11 /* Dec */, 31, 23, 59, 59, 999) | ||
) | ||
}) | ||
|
||
it('accepts a timestamp', function () { | ||
var date = new Date(2007, 9 /* Oct */, 10, 0, 0, 0).getTime() | ||
var result = endOfDecade(date) | ||
assert.deepEqual(result, | ||
new Date(2009, 11 /* Dec */, 31, 23, 59, 59, 999) | ||
) | ||
}) | ||
|
||
it('does not mutate the original date', function () { | ||
var date = new Date(2038, 0 /* Jan */, 19, 3, 14, 8) | ||
endOfDecade(date) | ||
assert.deepEqual(date, new Date(2038, 0 /* Jan */, 19, 3, 14, 8)) | ||
}) | ||
|
||
it('returns `Invalid Date` if the given date is invalid', function () { | ||
var result = endOfDecade(new Date(NaN)) | ||
assert(result instanceof Date && isNaN(result)) | ||
}) | ||
|
||
it('throws `RangeError` if `options.additionalDigits` is not convertable to 0, 1, 2 or undefined`', function () { | ||
var date = new Date(2018, 6 /* Jul */, 15, 0, 0, 0) | ||
// $ExpectedMistake | ||
var block = endOfDecade.bind(null, date, {additionalDigits: NaN}) | ||
assert.throws(block, RangeError) | ||
}) | ||
|
||
it('throws TypeError exception if passed less than 1 argument', function () { | ||
assert.throws(endOfDecade.bind(null), TypeError) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
// This file is generated automatically by `scripts/build/typings.js`. Please, don't change it. | ||
|
||
import {endOfDecade} from 'date-fns/fp' | ||
export = endOfDecade |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
// This file is generated automatically by `scripts/build/fp.js`. Please, don't change it. | ||
|
||
import fn from '../../endOfDecade/index.js' | ||
import convertToFP from '../_lib/convertToFP/index.js' | ||
|
||
var endOfDecade = convertToFP(fn, 1) | ||
|
||
export default endOfDecade |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// @flow | ||
// This file is generated automatically by `scripts/build/typings.js`. Please, don't change it. | ||
|
||
type Interval = { | ||
start: Date | string | number, | ||
end: Date | string | number | ||
} | ||
|
||
type Options = { | ||
weekStartsOn?: 0 | 1 | 2 | 3 | 4 | 5 | 6, | ||
firstWeekContainsDate?: 1 | 2 | 3 | 4 | 5 | 6 | 7, | ||
additionalDigits?: 0 | 1 | 2, | ||
locale?: Locale, | ||
includeSeconds?: boolean, | ||
addSuffix?: boolean, | ||
unit?: 'second' | 'minute' | 'hour' | 'day' | 'month' | 'year', | ||
roundingMethod?: 'floor' | 'ceil' | 'round' | ||
} | ||
|
||
type Locale = { | ||
formatDistance: Function, | ||
formatRelative: Function, | ||
localize: { | ||
ordinalNumber: Function, | ||
era: Function, | ||
quarter: Function, | ||
month: Function, | ||
day: Function, | ||
dayPeriod: Function | ||
}, | ||
formatLong: Object, | ||
date: Function, | ||
time: Function, | ||
dateTime: Function, | ||
match: { | ||
ordinalNumber: Function, | ||
era: Function, | ||
quarter: Function, | ||
month: Function, | ||
day: Function, | ||
dayPeriod: Function | ||
}, | ||
options?: { | ||
weekStartsOn?: 0 | 1 | 2 | 3 | 4 | 5 | 6, | ||
firstWeekContainsDate?: 1 | 2 | 3 | 4 | 5 | 6 | 7 | ||
} | ||
} | ||
|
||
type CurriedFn1<A, R> = <A>(a: A) => R | ||
|
||
declare module.exports: CurriedFn1<Date | string | number, Date> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
// This file is generated automatically by `scripts/build/typings.js`. Please, don't change it. | ||
|
||
import {endOfDecadeWithOptions} from 'date-fns/fp' | ||
export = endOfDecadeWithOptions |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
// This file is generated automatically by `scripts/build/fp.js`. Please, don't change it. | ||
|
||
import fn from '../../endOfDecade/index.js' | ||
import convertToFP from '../_lib/convertToFP/index.js' | ||
|
||
var endOfDecadeWithOptions = convertToFP(fn, 2) | ||
|
||
export default endOfDecadeWithOptions |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// @flow | ||
// This file is generated automatically by `scripts/build/typings.js`. Please, don't change it. | ||
|
||
type Interval = { | ||
start: Date | string | number, | ||
end: Date | string | number | ||
} | ||
|
||
type Options = { | ||
weekStartsOn?: 0 | 1 | 2 | 3 | 4 | 5 | 6, | ||
firstWeekContainsDate?: 1 | 2 | 3 | 4 | 5 | 6 | 7, | ||
additionalDigits?: 0 | 1 | 2, | ||
locale?: Locale, | ||
includeSeconds?: boolean, | ||
addSuffix?: boolean, | ||
unit?: 'second' | 'minute' | 'hour' | 'day' | 'month' | 'year', | ||
roundingMethod?: 'floor' | 'ceil' | 'round' | ||
} | ||
|
||
type Locale = { | ||
formatDistance: Function, | ||
formatRelative: Function, | ||
localize: { | ||
ordinalNumber: Function, | ||
era: Function, | ||
quarter: Function, | ||
month: Function, | ||
day: Function, | ||
dayPeriod: Function | ||
}, | ||
formatLong: Object, | ||
date: Function, | ||
time: Function, | ||
dateTime: Function, | ||
match: { | ||
ordinalNumber: Function, | ||
era: Function, | ||
quarter: Function, | ||
month: Function, | ||
day: Function, | ||
dayPeriod: Function | ||
}, | ||
options?: { | ||
weekStartsOn?: 0 | 1 | 2 | 3 | 4 | 5 | 6, | ||
firstWeekContainsDate?: 1 | 2 | 3 | 4 | 5 | 6 | 7 | ||
} | ||
} | ||
|
||
type CurriedFn1<A, R> = <A>(a: A) => R | ||
|
||
type CurriedFn2<A, B, R> = <A>(a: A) => CurriedFn1<B, R> | ||
| <A, B>(a: A, b: B) => R | ||
|
||
declare module.exports: CurriedFn2<Options, Date | string | number, Date> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
// This file is generated automatically by `scripts/build/typings.js`. Please, don't change it. | ||
|
||
import {getDecade} from 'date-fns/fp' | ||
export = getDecade |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
// This file is generated automatically by `scripts/build/fp.js`. Please, don't change it. | ||
|
||
import fn from '../../getDecade/index.js' | ||
import convertToFP from '../_lib/convertToFP/index.js' | ||
|
||
var getDecade = convertToFP(fn, 1) | ||
|
||
export default getDecade |
Oops, something went wrong.