Skip to content

Commit dd4f96e

Browse files
committed
add option nearestTo
1 parent a0dc42a commit dd4f96e

14 files changed

Lines changed: 258 additions & 18 deletions

File tree

src/fp/index.js.flow

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -282,8 +282,8 @@ declare module.exports: {
282282
minWithOptions: CurriedFn2<Options, (Date | string | number)[], Date>,
283283
parse: CurriedFn3<Date | string | number, string, string, Date>,
284284
parseWithOptions: CurriedFn4<Options, Date | string | number, string, string, Date>,
285-
roundToNearestMinutes: CurriedFn1<Date | string | number, Date>,
286-
roundToNearestMinutesWithOptions: CurriedFn2<Options, Date | string | number, Date>,
285+
roundToNearestMinutes: CurriedFn2<number, Date | string | number, Date>,
286+
roundToNearestMinutesWithOptions: CurriedFn3<Options, number, Date | string | number, Date>,
287287
setDate: CurriedFn2<number, Date | string | number, Date>,
288288
setDateWithOptions: CurriedFn3<Options, number, Date | string | number, Date>,
289289
setDay: CurriedFn2<number, Date | string | number, Date>,
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// This file is generated automatically by `scripts/build/typings.js`. Please, don't change it.
2+
3+
import {roundToNearestMinutes} from 'date-fns/fp'
4+
export = roundToNearestMinutes
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// This file is generated automatically by `scripts/build/fp.js`. Please, don't change it.
2+
3+
import fn from '../../roundToNearestMinutes/index.js'
4+
import convertToFP from '../_lib/convertToFP/index.js'
5+
6+
var roundToNearestMinutes = convertToFP(fn, 2)
7+
8+
export default roundToNearestMinutes
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
// @flow
2+
// This file is generated automatically by `scripts/build/typings.js`. Please, don't change it.
3+
4+
type Interval = {
5+
start: Date | string | number,
6+
end: Date | string | number
7+
}
8+
9+
type Options = {
10+
weekStartsOn?: 0 | 1 | 2 | 3 | 4 | 5 | 6,
11+
firstWeekContainsDate?: 1 | 2 | 3 | 4 | 5 | 6 | 7,
12+
additionalDigits?: 0 | 1 | 2,
13+
locale?: Locale,
14+
includeSeconds?: boolean,
15+
addSuffix?: boolean,
16+
unit?: 'second' | 'minute' | 'hour' | 'day' | 'month' | 'year',
17+
roundingMethod?: 'floor' | 'ceil' | 'round',
18+
awareOfUnicodeTokens?: boolean
19+
}
20+
21+
type Locale = {
22+
formatDistance: Function,
23+
formatRelative: Function,
24+
localize: {
25+
ordinalNumber: Function,
26+
era: Function,
27+
quarter: Function,
28+
month: Function,
29+
day: Function,
30+
dayPeriod: Function
31+
},
32+
formatLong: Object,
33+
date: Function,
34+
time: Function,
35+
dateTime: Function,
36+
match: {
37+
ordinalNumber: Function,
38+
era: Function,
39+
quarter: Function,
40+
month: Function,
41+
day: Function,
42+
dayPeriod: Function
43+
},
44+
options?: {
45+
weekStartsOn?: 0 | 1 | 2 | 3 | 4 | 5 | 6,
46+
firstWeekContainsDate?: 1 | 2 | 3 | 4 | 5 | 6 | 7
47+
}
48+
}
49+
50+
type CurriedFn1<A, R> = <A>(a: A) => R
51+
52+
type CurriedFn2<A, B, R> = <A>(a: A) => CurriedFn1<B, R>
53+
| <A, B>(a: A, b: B) => R
54+
55+
declare module.exports: CurriedFn2<number, Date | string | number, Date>
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// This file is generated automatically by `scripts/build/typings.js`. Please, don't change it.
2+
3+
import {roundToNearestMinutesWithOptions} from 'date-fns/fp'
4+
export = roundToNearestMinutesWithOptions
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// This file is generated automatically by `scripts/build/fp.js`. Please, don't change it.
2+
3+
import fn from '../../roundToNearestMinutes/index.js'
4+
import convertToFP from '../_lib/convertToFP/index.js'
5+
6+
var roundToNearestMinutesWithOptions = convertToFP(fn, 3)
7+
8+
export default roundToNearestMinutesWithOptions
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
// @flow
2+
// This file is generated automatically by `scripts/build/typings.js`. Please, don't change it.
3+
4+
type Interval = {
5+
start: Date | string | number,
6+
end: Date | string | number
7+
}
8+
9+
type Options = {
10+
weekStartsOn?: 0 | 1 | 2 | 3 | 4 | 5 | 6,
11+
firstWeekContainsDate?: 1 | 2 | 3 | 4 | 5 | 6 | 7,
12+
additionalDigits?: 0 | 1 | 2,
13+
locale?: Locale,
14+
includeSeconds?: boolean,
15+
addSuffix?: boolean,
16+
unit?: 'second' | 'minute' | 'hour' | 'day' | 'month' | 'year',
17+
roundingMethod?: 'floor' | 'ceil' | 'round',
18+
awareOfUnicodeTokens?: boolean
19+
}
20+
21+
type Locale = {
22+
formatDistance: Function,
23+
formatRelative: Function,
24+
localize: {
25+
ordinalNumber: Function,
26+
era: Function,
27+
quarter: Function,
28+
month: Function,
29+
day: Function,
30+
dayPeriod: Function
31+
},
32+
formatLong: Object,
33+
date: Function,
34+
time: Function,
35+
dateTime: Function,
36+
match: {
37+
ordinalNumber: Function,
38+
era: Function,
39+
quarter: Function,
40+
month: Function,
41+
day: Function,
42+
dayPeriod: Function
43+
},
44+
options?: {
45+
weekStartsOn?: 0 | 1 | 2 | 3 | 4 | 5 | 6,
46+
firstWeekContainsDate?: 1 | 2 | 3 | 4 | 5 | 6 | 7
47+
}
48+
}
49+
50+
type CurriedFn1<A, R> = <A>(a: A) => R
51+
52+
type CurriedFn2<A, B, R> = <A>(a: A) => CurriedFn1<B, R>
53+
| <A, B>(a: A, b: B) => R
54+
55+
type CurriedFn3<A, B, C, R> = <A>(a: A) => CurriedFn2<B, C, R>
56+
| <A,B>(a: A, b: B) => CurriedFn1<C, R>
57+
| <A,B,C>(a: A, b: B, c: C) => R
58+
59+
declare module.exports: CurriedFn3<Options, number, Date | string | number, Date>

src/fp/test.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1308,12 +1308,18 @@ describe('FP functions', function () {
13081308
})
13091309

13101310
it('roundToNearestMinutes', function () {
1311-
var result = fp.roundToNearestMinutes()(new Date(2014, 6 /* Jul */, 10, 12, 10, 34, 99))
1311+
var result = fp.roundToNearestMinutes(5)(new Date(2014, 6 /* Jul */, 10, 12, 11, 34, 99))
1312+
assert.deepEqual(result, new Date(2014, 6 /* Jul */, 10, 12, 10))
1313+
1314+
var result = fp.roundToNearestMinutes()(new Date(2014, 6 /* Jul */, 10, 12, 11, 34, 99))
13121315
assert.deepEqual(result, new Date(2014, 6 /* Jul */, 10, 12, 11))
13131316
})
13141317

13151318
it('roundToNearestMinutesWithOptions', function () {
1316-
var result = fp.addMinutesWithOptions({})()(new Date(2014, 6 /* Jul */, 10, 12, 10, 34, 99))
1319+
var result = fp.roundToNearestMinutesWithOptions({})(5)(new Date(2014, 6 /* Jul */, 10, 12, 11, 34, 99))
1320+
assert.deepEqual(result, new Date(2014, 6 /* Jul */, 10, 12, 10))
1321+
1322+
var result = fp.roundToNearestMinutesWithOptions({})()(new Date(2014, 6 /* Jul */, 10, 12, 11, 34, 99))
13171323
assert.deepEqual(result, new Date(2014, 6 /* Jul */, 10, 12, 11))
13181324
})
13191325

src/index.js.flow

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -653,6 +653,7 @@ declare module.exports: {
653653

654654
roundToNearestMinutes: (
655655
date: Date | string | number,
656+
nearestTo?: number,
656657
options?: Options
657658
) => Date,
658659

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// This file is generated automatically by `scripts/build/typings.js`. Please, don't change it.
2+
3+
import {roundToNearestMinutes} from 'date-fns'
4+
export = roundToNearestMinutes

0 commit comments

Comments
 (0)