forked from date-fns/date-fns
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
56adab6
commit 9b0cfbf
Showing
21 changed files
with
477 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
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
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 {roundToNearestMinutes} from 'date-fns/fp' | ||
export = roundToNearestMinutes |
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 '../../roundToNearestMinutes/index.js' | ||
import convertToFP from '../_lib/convertToFP/index.js' | ||
|
||
var roundToNearestMinutes = convertToFP(fn, 2) | ||
|
||
export default roundToNearestMinutes |
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,55 @@ | ||
// @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', | ||
awareOfUnicodeTokens?: boolean | ||
} | ||
|
||
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<number, 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 {roundToNearestMinutesWithOptions} from 'date-fns/fp' | ||
export = roundToNearestMinutesWithOptions |
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 '../../roundToNearestMinutes/index.js' | ||
import convertToFP from '../_lib/convertToFP/index.js' | ||
|
||
var roundToNearestMinutesWithOptions = convertToFP(fn, 3) | ||
|
||
export default roundToNearestMinutesWithOptions |
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,59 @@ | ||
// @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', | ||
awareOfUnicodeTokens?: boolean | ||
} | ||
|
||
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 | ||
|
||
type CurriedFn3<A, B, C, R> = <A>(a: A) => CurriedFn2<B, C, R> | ||
| <A,B>(a: A, b: B) => CurriedFn1<C, R> | ||
| <A,B,C>(a: A, b: B, c: C) => R | ||
|
||
declare module.exports: CurriedFn3<Options, number, 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
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
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 {roundToNearestMinutes} from 'date-fns' | ||
export = roundToNearestMinutes |
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,49 @@ | ||
import toDate from '../toDate/index.js' | ||
import toInteger from '../_lib/toInteger/index.js' | ||
|
||
/** | ||
* @name roundToNearestMinutes | ||
* @category Minute Helpers | ||
* @summary Rounds the given date to the nearest minute | ||
* | ||
* @description | ||
* Rounds the given date to the nearest minute | ||
* | ||
* @param {Date|String|Number} date - the date to round | ||
* @param {Number} [nearestTo=1] - the closest minute to round to, must be between 1 and 30 inclusive | ||
* @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} | ||
* @returns {Date} the new date rounded to the closest minute | ||
* @throws {TypeError} 1 argument required | ||
* @throws {RangeError} `nearestTo` must be between 1 and 30 | ||
* | ||
* @example | ||
* // Round 10 July 2014 12:12:34 to nearest minute: | ||
* var result = roundToNearestMinutes(new Date(2014, 6, 10, 12, 12, 34)) | ||
* //=> Thu Jul 10 2014 12:13:00 | ||
*/ | ||
export default function roundToNearestMinutes (dirtyDate, dirtyNearestTo, dirtyOptions) { | ||
if (arguments.length < 1) { | ||
throw new TypeError('1 argument required, but only none provided present') | ||
} | ||
|
||
var nearestTo = arguments.length === 1 ? 1 : toInteger(dirtyNearestTo) | ||
|
||
if (arguments.length === 2 && typeof dirtyNearestTo !== 'number' && typeof dirtyNearestTo !== 'string') { | ||
dirtyOptions = dirtyNearestTo | ||
nearestTo = 1 | ||
} | ||
|
||
if (!nearestTo || nearestTo > 30 || nearestTo < 1) { | ||
throw new RangeError('nearestTo must be between 1 and 30') | ||
} | ||
|
||
var date = toDate(dirtyDate, dirtyOptions) | ||
var seconds = date.getSeconds() // relevant if nearestTo is 1, which is the default case | ||
var minutes = date.getMinutes() + seconds / 60 | ||
var roundedMinutes = Math.floor(minutes / nearestTo) * nearestTo | ||
var remainderMinutes = minutes % nearestTo | ||
var addedMinutes = Math.round(remainderMinutes / nearestTo) * nearestTo | ||
|
||
return new Date(date.getFullYear(), date.getMonth(), date.getDate(), date.getHours(), roundedMinutes + addedMinutes) | ||
} |
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', | ||
awareOfUnicodeTokens?: boolean | ||
} | ||
|
||
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, | ||
nearestTo?: number, | ||
options?: Options | ||
) => Date |
Oops, something went wrong.