Skip to content

Commit 9f4f88a

Browse files
committed
add tests
1 parent da83376 commit 9f4f88a

File tree

1 file changed

+52
-1
lines changed

1 file changed

+52
-1
lines changed

src/roundToNearestHours/test.ts

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,58 @@ describe('roundToNearestHours', function () {
4343
it('does not mutate the original date', function () {
4444
const date = new Date(2014, 6 /* Jul */, 10, 12, 10, 10, 99)
4545
roundToNearestHours(date)
46-
assert.deepStrictEqual(date, new Date(2014, 6 /* Jul */, 10, 12, 10, 10, 99))
46+
assert.deepStrictEqual(
47+
date,
48+
new Date(2014, 6 /* Jul */, 10, 12, 10, 10, 99)
49+
)
50+
})
51+
52+
it('rounds according to the passed mode - floor', () => {
53+
const result = roundToNearestHours(
54+
new Date(2014, 6 /* Jul */, 10, 12, 30, 0, 5),
55+
{ roundingMethod: 'floor' }
56+
)
57+
assert.deepStrictEqual(result, new Date(2014, 6 /* Jul */, 10, 13, 0, 0))
58+
})
59+
60+
it('rounds according to the passed mode - floor - when nearestTo is provided', () => {
61+
const result = roundToNearestHours(
62+
new Date(2014, 6 /* Jul */, 10, 15, 10, 30, 5),
63+
{ nearestTo: 4, roundingMethod: 'floor' }
64+
)
65+
assert.deepStrictEqual(result, new Date(2014, 6 /* Jul */, 10, 16, 0, 0))
66+
})
67+
68+
it('rounds according to the passed mode - ceil', () => {
69+
const result = roundToNearestHours(
70+
new Date(2014, 6 /* Jul */, 10, 12, 10, 30, 5),
71+
{ roundingMethod: 'ceil' }
72+
)
73+
assert.deepStrictEqual(result, new Date(2014, 6 /* Jul */, 10, 13, 0, 0))
74+
})
75+
76+
it('rounds according to the passed mode - ceil - when nearestTo is provided', () => {
77+
const result = roundToNearestHours(
78+
new Date(2014, 6 /* Jul */, 10, 12, 10, 30, 5),
79+
{ nearestTo: 4, roundingMethod: 'ceil' }
80+
)
81+
assert.deepStrictEqual(result, new Date(2014, 6 /* Jul */, 10, 16, 0, 0))
82+
})
83+
84+
it('rounds according to the passed mode - round - when nearestTo is provided', () => {
85+
const result = roundToNearestHours(
86+
new Date(2014, 6 /* Jul */, 10, 12, 10, 30, 5),
87+
{ nearestTo: 4, roundingMethod: 'round' }
88+
)
89+
assert.deepStrictEqual(result, new Date(2014, 6 /* Jul */, 10, 12, 0, 0))
90+
})
91+
92+
it('rounds according to the passed mode - trunc - when nearestTo is provided', () => {
93+
const result = roundToNearestHours(
94+
new Date(2014, 6 /* Jul */, 10, 12, 10, 30, 5),
95+
{ nearestTo: 4, roundingMethod: 'trunc' }
96+
)
97+
assert.deepStrictEqual(result, new Date(2014, 6 /* Jul */, 10, 12, 0, 0))
4798
})
4899

49100
it('returns `Invalid Date` if the given date is invalid', function () {

0 commit comments

Comments
 (0)