@checkdigit/time 4.0.0-PR.18-81a3 → 4.0.0-PR.18-e0fa
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +0 -2
- package/package.json +1 -1
- package/src/date-fns/_lib/addLeadingZeros/test.mts +0 -12
- package/src/date-fns/_lib/getRoundingMethod/test.mts +0 -50
- package/src/date-fns/_lib/getTimezoneOffsetInMilliseconds/test.mts +0 -25
- package/src/date-fns/add/test.mts +0 -95
- package/src/date-fns/addBusinessDays/test.mts +0 -78
- package/src/date-fns/addDays/test.mts +0 -90
- package/src/date-fns/addHours/test.mts +0 -30
- package/src/date-fns/addISOWeekYears/test.mts +0 -41
- package/src/date-fns/addMilliseconds/test.mts +0 -30
- package/src/date-fns/addMinutes/test.mts +0 -30
- package/src/date-fns/addMonths/test.mts +0 -123
- package/src/date-fns/addQuarters/test.mts +0 -47
- package/src/date-fns/addSeconds/test.mts +0 -30
- package/src/date-fns/addWeeks/test.mts +0 -30
- package/src/date-fns/addYears/test.mts +0 -46
- package/src/date-fns/areIntervalsOverlapping/test.mts +0 -231
- package/src/date-fns/clamp/test.mts +0 -36
- package/src/date-fns/closestIndexTo/test.mts +0 -51
- package/src/date-fns/closestTo/test.mts +0 -49
- package/src/date-fns/compareAsc/test.mts +0 -58
- package/src/date-fns/compareDesc/test.mts +0 -58
- package/src/date-fns/constructFrom/test.mts +0 -47
- package/src/date-fns/constructNow/test.mts +0 -37
- package/src/date-fns/daysToWeeks/test.mts +0 -36
- package/src/date-fns/differenceInBusinessDays/test.mts +0 -102
- package/src/date-fns/differenceInCalendarDays/test.mts +0 -206
- package/src/date-fns/differenceInCalendarISOWeekYears/test.mts +0 -93
- package/src/date-fns/differenceInCalendarISOWeeks/test.mts +0 -89
- package/src/date-fns/differenceInCalendarMonths/test.mts +0 -82
- package/src/date-fns/differenceInCalendarQuarters/test.mts +0 -82
- package/src/date-fns/differenceInCalendarWeeks/test.mts +0 -136
- package/src/date-fns/differenceInCalendarYears/test.mts +0 -82
- package/src/date-fns/differenceInDays/test.mts +0 -175
- package/src/date-fns/differenceInHours/test.mts +0 -122
- package/src/date-fns/differenceInISOWeekYears/test.mts +0 -93
- package/src/date-fns/differenceInMilliseconds/test.mts +0 -53
- package/src/date-fns/differenceInMinutes/test.mts +0 -123
- package/src/date-fns/differenceInMonths/test.mts +0 -121
- package/src/date-fns/differenceInQuarters/test.mts +0 -109
- package/src/date-fns/differenceInSeconds/test.mts +0 -144
- package/src/date-fns/differenceInWeeks/test.mts +0 -111
- package/src/date-fns/differenceInYears/test.mts +0 -97
- package/src/date-fns/eachDayOfInterval/test.mts +0 -164
- package/src/date-fns/eachHourOfInterval/test.mts +0 -154
- package/src/date-fns/eachMinuteOfInterval/test.mts +0 -159
- package/src/date-fns/eachMonthOfInterval/test.mts +0 -151
- package/src/date-fns/eachQuarterOfInterval/test.mts +0 -136
- package/src/date-fns/eachWeekOfInterval/test.mts +0 -177
- package/src/date-fns/eachWeekendOfInterval/test.mts +0 -67
- package/src/date-fns/eachWeekendOfMonth/test.mts +0 -23
- package/src/date-fns/eachWeekendOfYear/test.mts +0 -18
- package/src/date-fns/eachYearOfInterval/test.mts +0 -136
- package/src/date-fns/endOfDay/test.mts +0 -27
- package/src/date-fns/endOfDecade/test.mts +0 -32
- package/src/date-fns/endOfHour/test.mts +0 -26
- package/src/date-fns/endOfISOWeek/test.mts +0 -27
- package/src/date-fns/endOfISOWeekYear/test.mts +0 -36
- package/src/date-fns/endOfMinute/test.mts +0 -26
- package/src/date-fns/endOfMonth/test.mts +0 -41
- package/src/date-fns/endOfQuarter/test.mts +0 -27
- package/src/date-fns/endOfSecond/test.mts +0 -26
- package/src/date-fns/endOfToday/test.mts +0 -19
- package/src/date-fns/endOfTomorrow/test.mts +0 -29
- package/src/date-fns/endOfWeek/test.mts +0 -86
- package/src/date-fns/endOfYear/test.mts +0 -27
- package/src/date-fns/endOfYesterday/test.mts +0 -29
- package/src/date-fns/format/test.mts +0 -909
- package/src/date-fns/formatDistance/test.mts +0 -189
- package/src/date-fns/formatDistanceStrict/test.mts +0 -329
- package/src/date-fns/formatDistanceToNow/test.mts +0 -196
- package/src/date-fns/formatDistanceToNowStrict/test.mts +0 -293
- package/src/date-fns/formatDuration/test.mts +0 -74
- package/src/date-fns/formatISO/test.mts +0 -55
- package/src/date-fns/formatISO9075/test.mts +0 -35
- package/src/date-fns/formatISODuration/test.mts +0 -75
- package/src/date-fns/formatRFC3339/test.mts +0 -41
- package/src/date-fns/formatRFC7231/test.mts +0 -18
- package/src/date-fns/formatRelative/test.mts +0 -92
- package/src/date-fns/fp/_lib/convertToFP/test.mts +0 -114
- package/src/date-fns/fromUnixTime/test.mts +0 -14
- package/src/date-fns/getDate/test.mts +0 -19
- package/src/date-fns/getDay/test.mts +0 -19
- package/src/date-fns/getDayOfYear/test.mts +0 -27
- package/src/date-fns/getDaysInMonth/test.mts +0 -33
- package/src/date-fns/getDaysInYear/test.mts +0 -35
- package/src/date-fns/getDecade/test.mts +0 -24
- package/src/date-fns/getDefaultOptions/test.mts +0 -58
- package/src/date-fns/getHours/test.mts +0 -19
- package/src/date-fns/getISODay/test.mts +0 -24
- package/src/date-fns/getISOWeek/test.mts +0 -54
- package/src/date-fns/getISOWeekYear/test.mts +0 -27
- package/src/date-fns/getISOWeeksInYear/test.mts +0 -37
- package/src/date-fns/getMilliseconds/test.mts +0 -19
- package/src/date-fns/getMinutes/test.mts +0 -19
- package/src/date-fns/getMonth/test.mts +0 -19
- package/src/date-fns/getOverlappingDaysInIntervals/test.mts +0 -243
- package/src/date-fns/getQuarter/test.mts +0 -19
- package/src/date-fns/getSeconds/test.mts +0 -19
- package/src/date-fns/getTime/test.mts +0 -21
- package/src/date-fns/getUnixTime/test.mts +0 -26
- package/src/date-fns/getWeek/test.mts +0 -56
- package/src/date-fns/getWeekOfMonth/test.mts +0 -75
- package/src/date-fns/getWeekYear/test.mts +0 -49
- package/src/date-fns/getWeeksInMonth/test.mts +0 -51
- package/src/date-fns/getYear/test.mts +0 -19
- package/src/date-fns/hoursToMilliseconds/test.mts +0 -23
- package/src/date-fns/hoursToMinutes/test.mts +0 -25
- package/src/date-fns/hoursToSeconds/test.mts +0 -25
- package/src/date-fns/interval/test.mts +0 -42
- package/src/date-fns/intervalToDuration/test.mts +0 -235
- package/src/date-fns/intlFormat/test.mts +0 -88
- package/src/date-fns/intlFormatDistance/test.mts +0 -588
- package/src/date-fns/isAfter/test.mts +0 -39
- package/src/date-fns/isBefore/test.mts +0 -39
- package/src/date-fns/isDate/test.mts +0 -72
- package/src/date-fns/isEqual/test.mts +0 -34
- package/src/date-fns/isExists/test.mts +0 -14
- package/src/date-fns/isFirstDayOfMonth/test.mts +0 -25
- package/src/date-fns/isFriday/test.mts +0 -24
- package/src/date-fns/isFuture/test.mts +0 -34
- package/src/date-fns/isLastDayOfMonth/test.mts +0 -25
- package/src/date-fns/isLeapYear/test.mts +0 -35
- package/src/date-fns/isMatch/test.mts +0 -27
- package/src/date-fns/isMonday/test.mts +0 -24
- package/src/date-fns/isPast/test.mts +0 -34
- package/src/date-fns/isSameDay/test.mts +0 -37
- package/src/date-fns/isSameHour/test.mts +0 -37
- package/src/date-fns/isSameISOWeek/test.mts +0 -34
- package/src/date-fns/isSameISOWeekYear/test.mts +0 -48
- package/src/date-fns/isSameMinute/test.mts +0 -37
- package/src/date-fns/isSameMonth/test.mts +0 -34
- package/src/date-fns/isSameQuarter/test.mts +0 -34
- package/src/date-fns/isSameSecond/test.mts +0 -43
- package/src/date-fns/isSameWeek/test.mts +0 -58
- package/src/date-fns/isSameYear/test.mts +0 -34
- package/src/date-fns/isSaturday/test.mts +0 -24
- package/src/date-fns/isSunday/test.mts +0 -24
- package/src/date-fns/isThisHour/test.mts +0 -34
- package/src/date-fns/isThisISOWeek/test.mts +0 -34
- package/src/date-fns/isThisMinute/test.mts +0 -34
- package/src/date-fns/isThisMonth/test.mts +0 -34
- package/src/date-fns/isThisQuarter/test.mts +0 -34
- package/src/date-fns/isThisSecond/test.mts +0 -34
- package/src/date-fns/isThisWeek/test.mts +0 -39
- package/src/date-fns/isThisYear/test.mts +0 -34
- package/src/date-fns/isThursday/test.mts +0 -24
- package/src/date-fns/isToday/test.mts +0 -34
- package/src/date-fns/isTomorrow/test.mts +0 -34
- package/src/date-fns/isTuesday/test.mts +0 -24
- package/src/date-fns/isValid/test.mts +0 -24
- package/src/date-fns/isWednesday/test.mts +0 -24
- package/src/date-fns/isWeekend/test.mts +0 -24
- package/src/date-fns/isWithinInterval/test.mts +0 -92
- package/src/date-fns/isYesterday/test.mts +0 -34
- package/src/date-fns/lastDayOfDecade/test.mts +0 -32
- package/src/date-fns/lastDayOfISOWeek/test.mts +0 -27
- package/src/date-fns/lastDayOfISOWeekYear/test.mts +0 -36
- package/src/date-fns/lastDayOfMonth/test.mts +0 -41
- package/src/date-fns/lastDayOfQuarter/test.mts +0 -27
- package/src/date-fns/lastDayOfWeek/test.mts +0 -86
- package/src/date-fns/lastDayOfYear/test.mts +0 -27
- package/src/date-fns/lightFormat/test.mts +0 -126
- package/src/date-fns/max/test.mts +0 -34
- package/src/date-fns/milliseconds/test.mts +0 -62
- package/src/date-fns/millisecondsToHours/test.mts +0 -24
- package/src/date-fns/millisecondsToMinutes/test.mts +0 -24
- package/src/date-fns/millisecondsToSeconds/test.mts +0 -24
- package/src/date-fns/min/test.mts +0 -34
- package/src/date-fns/minutesToHours/test.mts +0 -24
- package/src/date-fns/minutesToMilliseconds/test.mts +0 -23
- package/src/date-fns/minutesToSeconds/test.mts +0 -23
- package/src/date-fns/monthsToQuarters/test.mts +0 -24
- package/src/date-fns/monthsToYears/test.mts +0 -24
- package/src/date-fns/nextDay/test.mts +0 -44
- package/src/date-fns/nextFriday/test.mts +0 -24
- package/src/date-fns/nextMonday/test.mts +0 -24
- package/src/date-fns/nextSaturday/test.mts +0 -24
- package/src/date-fns/nextSunday/test.mts +0 -24
- package/src/date-fns/nextThursday/test.mts +0 -24
- package/src/date-fns/nextTuesday/test.mts +0 -23
- package/src/date-fns/nextWednesday/test.mts +0 -24
- package/src/date-fns/parse/test.mts +0 -2202
- package/src/date-fns/parseISO/test.mts +0 -362
- package/src/date-fns/parseJSON/test.mts +0 -129
- package/src/date-fns/previousDay/test.mts +0 -42
- package/src/date-fns/previousFriday/test.mts +0 -22
- package/src/date-fns/previousMonday/test.mts +0 -22
- package/src/date-fns/previousSaturday/test.mts +0 -22
- package/src/date-fns/previousSunday/test.mts +0 -22
- package/src/date-fns/previousThursday/test.mts +0 -22
- package/src/date-fns/previousTuesday/test.mts +0 -22
- package/src/date-fns/previousWednesday/test.mts +0 -22
- package/src/date-fns/quartersToMonths/test.mts +0 -24
- package/src/date-fns/quartersToYears/test.mts +0 -24
- package/src/date-fns/roundToNearestHours/test.mts +0 -200
- package/src/date-fns/roundToNearestMinutes/test.mts +0 -208
- package/src/date-fns/secondsToHours/test.mts +0 -24
- package/src/date-fns/secondsToMilliseconds/test.mts +0 -14
- package/src/date-fns/secondsToMinutes/test.mts +0 -24
- package/src/date-fns/set/test.mts +0 -121
- package/src/date-fns/setDate/test.mts +0 -30
- package/src/date-fns/setDay/test.mts +0 -112
- package/src/date-fns/setDayOfYear/test.mts +0 -30
- package/src/date-fns/setDefaultOptions/test.mts +0 -498
- package/src/date-fns/setHours/test.mts +0 -30
- package/src/date-fns/setISODay/test.mts +0 -59
- package/src/date-fns/setISOWeek/test.mts +0 -41
- package/src/date-fns/setISOWeekYear/test.mts +0 -50
- package/src/date-fns/setMilliseconds/test.mts +0 -30
- package/src/date-fns/setMinutes/test.mts +0 -30
- package/src/date-fns/setMonth/test.mts +0 -46
- package/src/date-fns/setQuarter/test.mts +0 -46
- package/src/date-fns/setSeconds/test.mts +0 -30
- package/src/date-fns/setWeek/test.mts +0 -63
- package/src/date-fns/setWeekYear/test.mts +0 -72
- package/src/date-fns/setYear/test.mts +0 -30
- package/src/date-fns/startOfDay/test.mts +0 -27
- package/src/date-fns/startOfDecade/test.mts +0 -32
- package/src/date-fns/startOfHour/test.mts +0 -27
- package/src/date-fns/startOfISOWeek/test.mts +0 -27
- package/src/date-fns/startOfISOWeekYear/test.mts +0 -41
- package/src/date-fns/startOfMinute/test.mts +0 -27
- package/src/date-fns/startOfMonth/test.mts +0 -27
- package/src/date-fns/startOfQuarter/test.mts +0 -27
- package/src/date-fns/startOfSecond/test.mts +0 -27
- package/src/date-fns/startOfToday/test.mts +0 -19
- package/src/date-fns/startOfTomorrow/test.mts +0 -29
- package/src/date-fns/startOfWeek/test.mts +0 -86
- package/src/date-fns/startOfWeekYear/test.mts +0 -58
- package/src/date-fns/startOfYear/test.mts +0 -38
- package/src/date-fns/startOfYesterday/test.mts +0 -29
- package/src/date-fns/sub/test.mts +0 -83
- package/src/date-fns/subBusinessDays/test.mts +0 -40
- package/src/date-fns/subDays/test.mts +0 -30
- package/src/date-fns/subHours/test.mts +0 -30
- package/src/date-fns/subISOWeekYears/test.mts +0 -41
- package/src/date-fns/subMilliseconds/test.mts +0 -30
- package/src/date-fns/subMinutes/test.mts +0 -30
- package/src/date-fns/subMonths/test.mts +0 -47
- package/src/date-fns/subQuarters/test.mts +0 -47
- package/src/date-fns/subSeconds/test.mts +0 -30
- package/src/date-fns/subWeeks/test.mts +0 -30
- package/src/date-fns/subYears/test.mts +0 -46
- package/src/date-fns/toDate/test.mts +0 -35
- package/src/date-fns/weeksToDays/test.mts +0 -24
- package/src/date-fns/yearsToDays/test.mts +0 -24
- package/src/date-fns/yearsToMonths/test.mts +0 -24
- package/src/date-fns/yearsToQuarters/test.mts +0 -24
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from 'vitest';
|
|
2
|
-
import { previousWednesday } from './index';
|
|
3
|
-
|
|
4
|
-
describe('previousWednesday', () => {
|
|
5
|
-
it('returns the previous Wednesday given various dates after the same', () => {
|
|
6
|
-
expect(previousWednesday(new Date(2021, 5 /* Jun */, 5))).toEqual(new Date(2021, 5 /* Jun */, 2));
|
|
7
|
-
|
|
8
|
-
expect(previousWednesday(new Date(2021, 5 /* Jun */, 6))).toEqual(new Date(2021, 5 /* Jun */, 2));
|
|
9
|
-
|
|
10
|
-
expect(previousWednesday(new Date(2021, 5 /* Jun */, 9))).toEqual(new Date(2021, 5 /* Jun */, 2));
|
|
11
|
-
|
|
12
|
-
expect(previousWednesday(new Date(2021, 5 /* Jun */, 17))).toEqual(new Date(2021, 5 /* Jun */, 16));
|
|
13
|
-
|
|
14
|
-
expect(previousWednesday(new Date(2021, 5 /* Jun */, 18))).toEqual(new Date(2021, 5 /* Jun */, 16));
|
|
15
|
-
|
|
16
|
-
expect(previousWednesday(new Date(2021, 5 /* Jun */, 25))).toEqual(new Date(2021, 5 /* Jun */, 23));
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
it('returns `Invalid Date` if the given date is invalid', () => {
|
|
20
|
-
expect(previousWednesday(new Date(NaN)) instanceof Date).toBe(true);
|
|
21
|
-
});
|
|
22
|
-
});
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from 'vitest';
|
|
2
|
-
import { quartersToMonths } from './index';
|
|
3
|
-
|
|
4
|
-
describe('quartersToMonths', () => {
|
|
5
|
-
it('converts quarters to months', () => {
|
|
6
|
-
expect(quartersToMonths(1)).toBe(3);
|
|
7
|
-
expect(quartersToMonths(2)).toBe(6);
|
|
8
|
-
});
|
|
9
|
-
|
|
10
|
-
it('uses floor rounding', () => {
|
|
11
|
-
expect(quartersToMonths(1.5)).toBe(4);
|
|
12
|
-
expect(quartersToMonths(0.3)).toBe(0);
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
it('handles border values', () => {
|
|
16
|
-
expect(quartersToMonths(0.4)).toBe(1);
|
|
17
|
-
expect(quartersToMonths(0)).toBe(0);
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
it('properly works with negative numbers', () => {
|
|
21
|
-
expect(quartersToMonths(12.34)).toBe(37);
|
|
22
|
-
expect(quartersToMonths(-12.34)).toBe(-37);
|
|
23
|
-
});
|
|
24
|
-
});
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from 'vitest';
|
|
2
|
-
import { quartersToYears } from './index';
|
|
3
|
-
|
|
4
|
-
describe('quartersToYears', () => {
|
|
5
|
-
it('converts quarters to years', () => {
|
|
6
|
-
expect(quartersToYears(4)).toBe(1);
|
|
7
|
-
expect(quartersToYears(8)).toBe(2);
|
|
8
|
-
});
|
|
9
|
-
|
|
10
|
-
it('uses floor rounding', () => {
|
|
11
|
-
expect(quartersToYears(5)).toBe(1);
|
|
12
|
-
expect(quartersToYears(3)).toBe(0);
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
it('handles border values', () => {
|
|
16
|
-
expect(quartersToYears(4.5)).toBe(1);
|
|
17
|
-
expect(quartersToYears(0)).toBe(0);
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
it('properly works with negative numbers', () => {
|
|
21
|
-
expect(quartersToYears(12.34)).toBe(3);
|
|
22
|
-
expect(quartersToYears(-12.34)).toBe(-3);
|
|
23
|
-
});
|
|
24
|
-
});
|
|
@@ -1,200 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from 'vitest';
|
|
2
|
-
import { roundToNearestHours, type RoundToNearestHoursOptions } from './index';
|
|
3
|
-
|
|
4
|
-
describe('roundToNearestHours', () => {
|
|
5
|
-
it('rounds given date to the nearest hour by default', () => {
|
|
6
|
-
// low
|
|
7
|
-
expect(roundToNearestHours(makeDate(15, 10))).toEqual(makeDate(15));
|
|
8
|
-
|
|
9
|
-
// mid-point
|
|
10
|
-
expect(roundToNearestHours(makeDate(15, 30))).toEqual(makeDate(16));
|
|
11
|
-
|
|
12
|
-
// high
|
|
13
|
-
expect(roundToNearestHours(makeDate(15, 59))).toEqual(makeDate(16));
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
it('rounds to the closest x hours if nearestTo is provided', () => {
|
|
17
|
-
const options: RoundToNearestHoursOptions = { nearestTo: 3 };
|
|
18
|
-
|
|
19
|
-
// low
|
|
20
|
-
expect(roundToNearestHours(makeDate(9, 1), options)).toEqual(makeDate(9));
|
|
21
|
-
|
|
22
|
-
// mid-point
|
|
23
|
-
expect(roundToNearestHours(makeDate(10, 30), options)).toEqual(makeDate(12));
|
|
24
|
-
|
|
25
|
-
// high
|
|
26
|
-
expect(roundToNearestHours(makeDate(11, 59), options)).toEqual(makeDate(12));
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
describe('roundingMethod', () => {
|
|
30
|
-
it('trunc, nearestTo === 1 (default)', () => {
|
|
31
|
-
const options: RoundToNearestHoursOptions = { roundingMethod: 'trunc' };
|
|
32
|
-
|
|
33
|
-
// low
|
|
34
|
-
expect(roundToNearestHours(makeDate(15, 10), options)).toEqual(makeDate(15));
|
|
35
|
-
|
|
36
|
-
// mid-point
|
|
37
|
-
expect(roundToNearestHours(makeDate(15, 30), options)).toEqual(makeDate(15));
|
|
38
|
-
|
|
39
|
-
// high
|
|
40
|
-
expect(roundToNearestHours(makeDate(15, 59), options)).toEqual(makeDate(15));
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
it('trunc, nearestTo === 3', () => {
|
|
44
|
-
const options: RoundToNearestHoursOptions = {
|
|
45
|
-
roundingMethod: 'trunc',
|
|
46
|
-
nearestTo: 3,
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
// low
|
|
50
|
-
expect(roundToNearestHours(makeDate(9), options)).toEqual(makeDate(9));
|
|
51
|
-
|
|
52
|
-
// mid-point
|
|
53
|
-
expect(roundToNearestHours(makeDate(10, 30), options)).toEqual(makeDate(9));
|
|
54
|
-
|
|
55
|
-
// high
|
|
56
|
-
expect(roundToNearestHours(makeDate(11, 59), options)).toEqual(makeDate(9));
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
it('floor, nearestTo === 1 (default)', () => {
|
|
60
|
-
const options: RoundToNearestHoursOptions = { roundingMethod: 'floor' };
|
|
61
|
-
|
|
62
|
-
// low
|
|
63
|
-
expect(roundToNearestHours(makeDate(15), options)).toEqual(makeDate(15));
|
|
64
|
-
|
|
65
|
-
// mid-point
|
|
66
|
-
expect(roundToNearestHours(makeDate(15, 30), options)).toEqual(makeDate(15));
|
|
67
|
-
|
|
68
|
-
// high
|
|
69
|
-
expect(roundToNearestHours(makeDate(15, 59), options)).toEqual(makeDate(15));
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
it('floor, nearestTo === 3', () => {
|
|
73
|
-
const options: RoundToNearestHoursOptions = {
|
|
74
|
-
roundingMethod: 'floor',
|
|
75
|
-
nearestTo: 3,
|
|
76
|
-
};
|
|
77
|
-
|
|
78
|
-
// low
|
|
79
|
-
expect(roundToNearestHours(makeDate(15), options)).toEqual(makeDate(15));
|
|
80
|
-
|
|
81
|
-
// mid-point
|
|
82
|
-
expect(roundToNearestHours(makeDate(16, 30), options)).toEqual(makeDate(15));
|
|
83
|
-
|
|
84
|
-
// high
|
|
85
|
-
expect(roundToNearestHours(makeDate(17, 59), options)).toEqual(makeDate(15));
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
it('ceil, nearestTo === 1 (default)', () => {
|
|
89
|
-
const options: RoundToNearestHoursOptions = { roundingMethod: 'ceil' };
|
|
90
|
-
|
|
91
|
-
// low
|
|
92
|
-
expect(roundToNearestHours(makeDate(15, 1), options)).toEqual(makeDate(16));
|
|
93
|
-
|
|
94
|
-
// mid-point
|
|
95
|
-
expect(roundToNearestHours(makeDate(15, 30), options)).toEqual(makeDate(16));
|
|
96
|
-
|
|
97
|
-
// high
|
|
98
|
-
expect(roundToNearestHours(makeDate(15, 59), options)).toEqual(makeDate(16));
|
|
99
|
-
});
|
|
100
|
-
|
|
101
|
-
it('ceil, nearestTo === 3', () => {
|
|
102
|
-
const options: RoundToNearestHoursOptions = {
|
|
103
|
-
roundingMethod: 'ceil',
|
|
104
|
-
nearestTo: 3,
|
|
105
|
-
};
|
|
106
|
-
|
|
107
|
-
// low
|
|
108
|
-
expect(roundToNearestHours(makeDate(15, 1), options)).toEqual(makeDate(18));
|
|
109
|
-
|
|
110
|
-
// mid-point
|
|
111
|
-
expect(roundToNearestHours(makeDate(16, 30), options)).toEqual(makeDate(18));
|
|
112
|
-
|
|
113
|
-
// high
|
|
114
|
-
expect(roundToNearestHours(makeDate(17, 59), options)).toEqual(makeDate(18));
|
|
115
|
-
});
|
|
116
|
-
|
|
117
|
-
it('round, nearestTo === 1 (default)', () => {
|
|
118
|
-
const options: RoundToNearestHoursOptions = { roundingMethod: 'round' };
|
|
119
|
-
|
|
120
|
-
// low
|
|
121
|
-
expect(roundToNearestHours(makeDate(15), options)).toEqual(makeDate(15));
|
|
122
|
-
|
|
123
|
-
// mid-point
|
|
124
|
-
expect(roundToNearestHours(makeDate(15, 30), options)).toEqual(makeDate(16));
|
|
125
|
-
|
|
126
|
-
// high
|
|
127
|
-
expect(roundToNearestHours(makeDate(15, 59), options)).toEqual(makeDate(16));
|
|
128
|
-
});
|
|
129
|
-
|
|
130
|
-
it('round, nearestTo === 3', () => {
|
|
131
|
-
const options: RoundToNearestHoursOptions = {
|
|
132
|
-
roundingMethod: 'round',
|
|
133
|
-
nearestTo: 3,
|
|
134
|
-
};
|
|
135
|
-
|
|
136
|
-
// low
|
|
137
|
-
expect(roundToNearestHours(makeDate(15), options)).toEqual(makeDate(15));
|
|
138
|
-
|
|
139
|
-
// mid-point
|
|
140
|
-
expect(roundToNearestHours(makeDate(16, 30), options)).toEqual(makeDate(18));
|
|
141
|
-
|
|
142
|
-
// high
|
|
143
|
-
expect(roundToNearestHours(makeDate(17, 59), options)).toEqual(makeDate(18));
|
|
144
|
-
});
|
|
145
|
-
});
|
|
146
|
-
|
|
147
|
-
describe('edge cases', () => {
|
|
148
|
-
it('rounds up to the next day', () => {
|
|
149
|
-
expect(roundToNearestHours(new Date(2014, 6, 10, 23, 59, 59, 999))).toEqual(new Date(2014, 6, 11));
|
|
150
|
-
});
|
|
151
|
-
|
|
152
|
-
it('ceils correctly with 0 seconds and 1 millisecond', () => {
|
|
153
|
-
// "ceil" does not round up when exactly oclock
|
|
154
|
-
expect(roundToNearestHours(makeDate(15, 0, 0, 0), { roundingMethod: 'ceil' })).toEqual(makeDate(15));
|
|
155
|
-
|
|
156
|
-
expect(roundToNearestHours(makeDate(15, 0, 0, 1), { roundingMethod: 'ceil' })).toEqual(makeDate(16));
|
|
157
|
-
});
|
|
158
|
-
});
|
|
159
|
-
|
|
160
|
-
describe('examples', () => {
|
|
161
|
-
it('example 1', () => {
|
|
162
|
-
const result = roundToNearestHours(new Date(2014, 6, 10, 12, 34, 56));
|
|
163
|
-
expect(result).toEqual(new Date(2014, 6, 10, 13));
|
|
164
|
-
});
|
|
165
|
-
|
|
166
|
-
it('example 2', () => {
|
|
167
|
-
const result = roundToNearestHours(new Date(2014, 6, 10, 12, 34, 56), {
|
|
168
|
-
nearestTo: 6,
|
|
169
|
-
});
|
|
170
|
-
expect(result).toEqual(new Date(2014, 6, 10, 12));
|
|
171
|
-
});
|
|
172
|
-
|
|
173
|
-
it('example 3', () => {
|
|
174
|
-
const result = roundToNearestHours(new Date(2014, 6, 10, 12, 34, 56), {
|
|
175
|
-
nearestTo: 8,
|
|
176
|
-
});
|
|
177
|
-
expect(result).toEqual(new Date(2014, 6, 10, 16));
|
|
178
|
-
});
|
|
179
|
-
|
|
180
|
-
it('example 4', () => {
|
|
181
|
-
const result = roundToNearestHours(new Date(2014, 6, 10, 1, 23, 45), {
|
|
182
|
-
roundingMethod: 'ceil',
|
|
183
|
-
});
|
|
184
|
-
expect(result).toEqual(new Date(2014, 6, 10, 2));
|
|
185
|
-
});
|
|
186
|
-
|
|
187
|
-
it('example 5', () => {
|
|
188
|
-
const result = roundToNearestHours(new Date(2014, 6, 10, 12, 34, 56), {
|
|
189
|
-
roundingMethod: 'floor',
|
|
190
|
-
nearestTo: 8,
|
|
191
|
-
});
|
|
192
|
-
expect(result).toEqual(new Date(2014, 6, 10, 8));
|
|
193
|
-
});
|
|
194
|
-
});
|
|
195
|
-
});
|
|
196
|
-
|
|
197
|
-
function makeDate(hours: number, minutes: number = 0, seconds: number = 0, milliseconds: number = 0) {
|
|
198
|
-
// helper to make tests more readable since we mostly care about hours and minutes
|
|
199
|
-
return new Date(2014, 6 /* Jul */, 10, hours, minutes, seconds, milliseconds);
|
|
200
|
-
}
|
|
@@ -1,208 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from 'vitest';
|
|
2
|
-
import { roundToNearestMinutes, type RoundToNearestMinutesOptions } from './index';
|
|
3
|
-
|
|
4
|
-
describe('roundToNearestMinutes', () => {
|
|
5
|
-
it('rounds given date to the nearest minute by default', () => {
|
|
6
|
-
// low
|
|
7
|
-
expect(roundToNearestMinutes(makeDate(15, 10))).toEqual(makeDate(15));
|
|
8
|
-
|
|
9
|
-
// mid-point
|
|
10
|
-
expect(roundToNearestMinutes(makeDate(15, 30))).toEqual(makeDate(16));
|
|
11
|
-
|
|
12
|
-
// high
|
|
13
|
-
expect(roundToNearestMinutes(makeDate(15, 59))).toEqual(makeDate(16));
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
it('rounds to the closest x minutes if nearestTo is provided', () => {
|
|
17
|
-
const options: RoundToNearestMinutesOptions = { nearestTo: 4 };
|
|
18
|
-
|
|
19
|
-
// low
|
|
20
|
-
expect(roundToNearestMinutes(makeDate(9, 59), options)).toEqual(makeDate(8));
|
|
21
|
-
|
|
22
|
-
// mid-point
|
|
23
|
-
expect(roundToNearestMinutes(makeDate(10), options)).toEqual(makeDate(12));
|
|
24
|
-
|
|
25
|
-
// high
|
|
26
|
-
expect(roundToNearestMinutes(makeDate(10, 30), options)).toEqual(makeDate(12));
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
describe('roundingMethod', () => {
|
|
30
|
-
it('trunc, nearestTo === 1 (default)', () => {
|
|
31
|
-
const options: RoundToNearestMinutesOptions = { roundingMethod: 'trunc' };
|
|
32
|
-
|
|
33
|
-
// low
|
|
34
|
-
expect(roundToNearestMinutes(makeDate(15, 10), options)).toEqual(makeDate(15));
|
|
35
|
-
|
|
36
|
-
// mid-point
|
|
37
|
-
expect(roundToNearestMinutes(makeDate(15, 30), options)).toEqual(makeDate(15));
|
|
38
|
-
|
|
39
|
-
// high
|
|
40
|
-
expect(roundToNearestMinutes(makeDate(15, 59), options)).toEqual(makeDate(15));
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
it('trunc, nearestTo === 4', () => {
|
|
44
|
-
const options: RoundToNearestMinutesOptions = {
|
|
45
|
-
roundingMethod: 'trunc',
|
|
46
|
-
nearestTo: 4,
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
// low
|
|
50
|
-
expect(roundToNearestMinutes(makeDate(9, 59), options)).toEqual(makeDate(8));
|
|
51
|
-
|
|
52
|
-
// mid-point
|
|
53
|
-
expect(roundToNearestMinutes(makeDate(10), options)).toEqual(makeDate(8));
|
|
54
|
-
|
|
55
|
-
// high
|
|
56
|
-
expect(roundToNearestMinutes(makeDate(10, 30), options)).toEqual(makeDate(8));
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
it('floor, nearestTo === 1 (default)', () => {
|
|
60
|
-
const options: RoundToNearestMinutesOptions = { roundingMethod: 'floor' };
|
|
61
|
-
|
|
62
|
-
// low
|
|
63
|
-
expect(roundToNearestMinutes(makeDate(15, 10), options)).toEqual(makeDate(15));
|
|
64
|
-
|
|
65
|
-
// mid-point
|
|
66
|
-
expect(roundToNearestMinutes(makeDate(15, 30), options)).toEqual(makeDate(15));
|
|
67
|
-
|
|
68
|
-
// high
|
|
69
|
-
expect(roundToNearestMinutes(makeDate(15, 59), options)).toEqual(makeDate(15));
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
it('floor, nearestTo === 4', () => {
|
|
73
|
-
const options: RoundToNearestMinutesOptions = {
|
|
74
|
-
roundingMethod: 'floor',
|
|
75
|
-
nearestTo: 4,
|
|
76
|
-
};
|
|
77
|
-
|
|
78
|
-
// low
|
|
79
|
-
expect(roundToNearestMinutes(makeDate(9, 59), options)).toEqual(makeDate(8));
|
|
80
|
-
|
|
81
|
-
// mid-point
|
|
82
|
-
expect(roundToNearestMinutes(makeDate(10), options)).toEqual(makeDate(8));
|
|
83
|
-
|
|
84
|
-
// high
|
|
85
|
-
expect(roundToNearestMinutes(makeDate(10, 30), options)).toEqual(makeDate(8));
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
it('ceil, nearestTo === 1 (default)', () => {
|
|
89
|
-
const options: RoundToNearestMinutesOptions = { roundingMethod: 'ceil' };
|
|
90
|
-
|
|
91
|
-
// low
|
|
92
|
-
expect(roundToNearestMinutes(makeDate(15, 10), options)).toEqual(makeDate(16));
|
|
93
|
-
|
|
94
|
-
// mid-point
|
|
95
|
-
expect(roundToNearestMinutes(makeDate(15, 30), options)).toEqual(makeDate(16));
|
|
96
|
-
|
|
97
|
-
// high
|
|
98
|
-
expect(roundToNearestMinutes(makeDate(15, 59), options)).toEqual(makeDate(16));
|
|
99
|
-
});
|
|
100
|
-
|
|
101
|
-
it('ceil, nearestTo === 4', () => {
|
|
102
|
-
const options: RoundToNearestMinutesOptions = {
|
|
103
|
-
roundingMethod: 'ceil',
|
|
104
|
-
nearestTo: 4,
|
|
105
|
-
};
|
|
106
|
-
|
|
107
|
-
// low
|
|
108
|
-
expect(roundToNearestMinutes(makeDate(9, 59), options)).toEqual(makeDate(12));
|
|
109
|
-
|
|
110
|
-
// mid-point
|
|
111
|
-
expect(roundToNearestMinutes(makeDate(10), options)).toEqual(makeDate(12));
|
|
112
|
-
|
|
113
|
-
// high
|
|
114
|
-
expect(roundToNearestMinutes(makeDate(10, 30), options)).toEqual(makeDate(12));
|
|
115
|
-
});
|
|
116
|
-
|
|
117
|
-
it('round, nearestTo === 1 (default)', () => {
|
|
118
|
-
const options: RoundToNearestMinutesOptions = { roundingMethod: 'round' };
|
|
119
|
-
|
|
120
|
-
// low
|
|
121
|
-
expect(roundToNearestMinutes(makeDate(15, 10), options)).toEqual(makeDate(15));
|
|
122
|
-
|
|
123
|
-
// mid-point
|
|
124
|
-
expect(roundToNearestMinutes(makeDate(15, 30), options)).toEqual(makeDate(16));
|
|
125
|
-
|
|
126
|
-
// high
|
|
127
|
-
expect(roundToNearestMinutes(makeDate(15, 59), options)).toEqual(makeDate(16));
|
|
128
|
-
});
|
|
129
|
-
|
|
130
|
-
it('round, nearestTo === 4', () => {
|
|
131
|
-
const options: RoundToNearestMinutesOptions = {
|
|
132
|
-
roundingMethod: 'round',
|
|
133
|
-
nearestTo: 4,
|
|
134
|
-
};
|
|
135
|
-
|
|
136
|
-
// low
|
|
137
|
-
expect(roundToNearestMinutes(makeDate(9, 59), options)).toEqual(makeDate(8));
|
|
138
|
-
|
|
139
|
-
// mid-point
|
|
140
|
-
expect(roundToNearestMinutes(makeDate(10), options)).toEqual(makeDate(12));
|
|
141
|
-
|
|
142
|
-
// high
|
|
143
|
-
expect(roundToNearestMinutes(makeDate(10, 30), options)).toEqual(makeDate(12));
|
|
144
|
-
});
|
|
145
|
-
});
|
|
146
|
-
|
|
147
|
-
describe('edge cases', () => {
|
|
148
|
-
it('rounds up to the next day', () => {
|
|
149
|
-
expect(roundToNearestMinutes(new Date(2014, 6, 10, 23, 59, 59))).toEqual(new Date(2014, 6, 11));
|
|
150
|
-
});
|
|
151
|
-
|
|
152
|
-
it('ceils correctly with 0 seconds and 1 millisecond', () => {
|
|
153
|
-
expect(roundToNearestMinutes(makeDate(15, 0, 0), { roundingMethod: 'ceil' })).toEqual(makeDate(15));
|
|
154
|
-
|
|
155
|
-
expect(roundToNearestMinutes(makeDate(15, 0, 1), { roundingMethod: 'ceil' })).toEqual(makeDate(16));
|
|
156
|
-
});
|
|
157
|
-
});
|
|
158
|
-
|
|
159
|
-
describe('examples', () => {
|
|
160
|
-
it('example 1', () => {
|
|
161
|
-
const result = roundToNearestMinutes(new Date(2014, 6, 10, 12, 12, 34));
|
|
162
|
-
expect(result).toEqual(new Date(2014, 6, 10, 12, 13));
|
|
163
|
-
});
|
|
164
|
-
|
|
165
|
-
it('example 2', () => {
|
|
166
|
-
const result = roundToNearestMinutes(new Date(2014, 6, 10, 12, 12, 34), {
|
|
167
|
-
nearestTo: 15,
|
|
168
|
-
});
|
|
169
|
-
expect(result).toEqual(new Date(2014, 6, 10, 12, 15));
|
|
170
|
-
});
|
|
171
|
-
|
|
172
|
-
it('example 3', () => {
|
|
173
|
-
const result = roundToNearestMinutes(new Date(2014, 6, 10, 12, 12, 34), {
|
|
174
|
-
roundingMethod: 'floor',
|
|
175
|
-
});
|
|
176
|
-
expect(result).toEqual(new Date(2014, 6, 10, 12, 12));
|
|
177
|
-
});
|
|
178
|
-
|
|
179
|
-
it('example 4', () => {
|
|
180
|
-
const result = roundToNearestMinutes(new Date(2014, 6, 10, 12, 12, 34), {
|
|
181
|
-
roundingMethod: 'ceil',
|
|
182
|
-
nearestTo: 30,
|
|
183
|
-
});
|
|
184
|
-
expect(result).toEqual(new Date(2014, 6, 10, 12, 30));
|
|
185
|
-
});
|
|
186
|
-
});
|
|
187
|
-
|
|
188
|
-
it('accepts a timestamp', () => {
|
|
189
|
-
const result = roundToNearestMinutes(makeDate(13, 16).getTime());
|
|
190
|
-
expect(result).toEqual(makeDate(13));
|
|
191
|
-
});
|
|
192
|
-
|
|
193
|
-
it('does not mutate the original date', () => {
|
|
194
|
-
const date = makeDate(10, 10);
|
|
195
|
-
roundToNearestMinutes(date);
|
|
196
|
-
expect(date).toEqual(makeDate(10, 10));
|
|
197
|
-
});
|
|
198
|
-
|
|
199
|
-
it('returns `Invalid Date` if the given date is invalid', () => {
|
|
200
|
-
const result = roundToNearestMinutes(new Date(NaN));
|
|
201
|
-
expect(result instanceof Date && isNaN(result.getTime())).toBe(true);
|
|
202
|
-
});
|
|
203
|
-
});
|
|
204
|
-
|
|
205
|
-
function makeDate(minutes: number, seconds: number = 0, milliseconds: number = 0) {
|
|
206
|
-
// helper to make tests more readable since we mostly care about minutes and seconds
|
|
207
|
-
return new Date(2014, 6 /* Jul */, 10, 12, minutes, seconds, milliseconds);
|
|
208
|
-
}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from 'vitest';
|
|
2
|
-
import { secondsToHours } from './index';
|
|
3
|
-
|
|
4
|
-
describe('secondsToHours', () => {
|
|
5
|
-
it('converts seconds to hours', () => {
|
|
6
|
-
expect(secondsToHours(3600)).toBe(1);
|
|
7
|
-
expect(secondsToHours(7200)).toBe(2);
|
|
8
|
-
});
|
|
9
|
-
|
|
10
|
-
it('uses floor rounding', () => {
|
|
11
|
-
expect(secondsToHours(3601)).toBe(1);
|
|
12
|
-
expect(secondsToHours(3599)).toBe(0);
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
it('handles border values', () => {
|
|
16
|
-
expect(secondsToHours(3600.5)).toBe(1);
|
|
17
|
-
expect(secondsToHours(0)).toBe(0);
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
it('properly works with negative numbers', () => {
|
|
21
|
-
expect(secondsToHours(123456)).toBe(34);
|
|
22
|
-
expect(secondsToHours(-123456)).toBe(-34);
|
|
23
|
-
});
|
|
24
|
-
});
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from 'vitest';
|
|
2
|
-
import { secondsToMilliseconds } from './index';
|
|
3
|
-
|
|
4
|
-
describe('secondsToMilliseconds', () => {
|
|
5
|
-
it('converts seconds to milliseconds', () => {
|
|
6
|
-
expect(secondsToMilliseconds(1)).toBe(1000);
|
|
7
|
-
expect(secondsToMilliseconds(2)).toBe(2000);
|
|
8
|
-
});
|
|
9
|
-
|
|
10
|
-
it('handles border values', () => {
|
|
11
|
-
expect(secondsToMilliseconds(1.5)).toBe(1500);
|
|
12
|
-
expect(secondsToMilliseconds(0)).toBe(0);
|
|
13
|
-
});
|
|
14
|
-
});
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from 'vitest';
|
|
2
|
-
import { secondsToMinutes } from './index';
|
|
3
|
-
|
|
4
|
-
describe('secondsToMinutes', () => {
|
|
5
|
-
it('converts seconds to minutes', () => {
|
|
6
|
-
expect(secondsToMinutes(60)).toBe(1);
|
|
7
|
-
expect(secondsToMinutes(120)).toBe(2);
|
|
8
|
-
});
|
|
9
|
-
|
|
10
|
-
it('uses floor rounding', () => {
|
|
11
|
-
expect(secondsToMinutes(61)).toBe(1);
|
|
12
|
-
expect(secondsToMinutes(59)).toBe(0);
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
it('handles border values', () => {
|
|
16
|
-
expect(secondsToMinutes(60.5)).toBe(1);
|
|
17
|
-
expect(secondsToMinutes(0)).toBe(0);
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
it('properly works with negative numbers', () => {
|
|
21
|
-
expect(secondsToMinutes(123456)).toBe(2057);
|
|
22
|
-
expect(secondsToMinutes(-123456)).toBe(-2057);
|
|
23
|
-
});
|
|
24
|
-
});
|
|
@@ -1,121 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from 'vitest';
|
|
2
|
-
import { set } from './index';
|
|
3
|
-
|
|
4
|
-
describe('set', () => {
|
|
5
|
-
it('sets all values', () => {
|
|
6
|
-
const result = set(new Date(2013, 0 /* Jan */), {
|
|
7
|
-
year: 2014,
|
|
8
|
-
month: 8, // Sep
|
|
9
|
-
date: 20,
|
|
10
|
-
hours: 12,
|
|
11
|
-
minutes: 12,
|
|
12
|
-
seconds: 12,
|
|
13
|
-
milliseconds: 12,
|
|
14
|
-
});
|
|
15
|
-
expect(result.toString()).toEqual(new Date(2014, 8 /* Sep */, 20, 12, 12, 12, 12).toString());
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
it('sets year', () => {
|
|
19
|
-
const result = set(new Date(2013, 8 /* Sep */), { year: 2014 });
|
|
20
|
-
expect(result).toEqual(new Date(2014, 8 /* Sep */));
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
it('sets month', () => {
|
|
24
|
-
const result = set(new Date(2014, 8 /* Sep */), { month: 9 /* Oct */ });
|
|
25
|
-
expect(result).toEqual(new Date(2014, 9 /* Oct */));
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
it('sets day of month', () => {
|
|
29
|
-
const result = set(new Date(2014, 8 /* Sep */), { date: 20 });
|
|
30
|
-
expect(result).toEqual(new Date(2014, 8 /* Sep */, 20));
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
it('sets hours', () => {
|
|
34
|
-
const result = set(new Date(2014, 8 /* Sep */, 1), { hours: 12 });
|
|
35
|
-
expect(result).toEqual(new Date(2014, 8 /* Sep */, 1, 12));
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
it('sets minutes', () => {
|
|
39
|
-
const result = set(new Date(2014, 8 /* Sep */, 1, 1), { minutes: 12 });
|
|
40
|
-
expect(result).toEqual(new Date(2014, 8 /* Sep */, 1, 1, 12));
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
it('sets seconds', () => {
|
|
44
|
-
const result = set(new Date(2014, 8 /* Sep */, 1, 1, 1), { seconds: 12 });
|
|
45
|
-
expect(result).toEqual(new Date(2014, 8 /* Sep */, 1, 1, 1, 12));
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
it('sets milliseconds', () => {
|
|
49
|
-
const result = set(new Date(2014, 8 /* Sep */, 1, 1, 1, 1), {
|
|
50
|
-
milliseconds: 500,
|
|
51
|
-
});
|
|
52
|
-
expect(result).toEqual(new Date(2014, 8 /* Sep */, 1, 1, 1, 1, 500));
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
describe('value overflow', () => {
|
|
56
|
-
it('months overflow into years', () => {
|
|
57
|
-
const result = set(new Date(2014, 8 /* Sep */, 1), {
|
|
58
|
-
month: 12 /* 13th month */,
|
|
59
|
-
});
|
|
60
|
-
expect(result).toEqual(new Date(2015, 0 /* Jan */, 1));
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
it('days of months overflow into months', () => {
|
|
64
|
-
const result = set(new Date(2014, 8 /* Sep */, 1), { date: 31 });
|
|
65
|
-
expect(result).toEqual(new Date(2014, 9 /* Oct */, 1));
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
it('hours overflow into days', () => {
|
|
69
|
-
const result = set(new Date(2014, 8 /* Sep */, 19), { hours: 24 });
|
|
70
|
-
expect(result).toEqual(new Date(2014, 8 /* Sep */, 20));
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
it('minutes overflow into hours', () => {
|
|
74
|
-
const result = set(new Date(2014, 8 /* Sep */, 20, 11), { minutes: 60 });
|
|
75
|
-
expect(result).toEqual(new Date(2014, 8 /* Sep */, 20, 12));
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
it('seconds overflow into minutes', () => {
|
|
79
|
-
const result = set(new Date(2014, 8 /* Sep */, 20, 12, 58), {
|
|
80
|
-
seconds: 60,
|
|
81
|
-
});
|
|
82
|
-
expect(result).toEqual(new Date(2014, 8 /* Sep */, 20, 12, 59));
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
it('milliseconds overflow into seconds', () => {
|
|
86
|
-
const result = set(new Date(2014, 8 /* Sep */, 20, 12, 58, 30), {
|
|
87
|
-
milliseconds: 1000,
|
|
88
|
-
});
|
|
89
|
-
expect(result).toEqual(new Date(2014, 8 /* Sep */, 20, 12, 58, 31));
|
|
90
|
-
});
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
describe('edge cases', () => {
|
|
94
|
-
it('sets January', () => {
|
|
95
|
-
const result = set(new Date(2014, 8 /* Sep */), { month: 0 /* Jan */ });
|
|
96
|
-
expect(result).toEqual(new Date(2014, 0 /* Jan */));
|
|
97
|
-
});
|
|
98
|
-
|
|
99
|
-
it('sets the last day of new month if the initial date was the last day of a longer month', () => {
|
|
100
|
-
const result = set(new Date(2014, 7 /* Aug */, 31), {
|
|
101
|
-
month: 8 /* Sep */,
|
|
102
|
-
});
|
|
103
|
-
expect(result).toEqual(new Date(2014, 8 /* Sep */, 30));
|
|
104
|
-
});
|
|
105
|
-
|
|
106
|
-
it('ignores undefined values', () => {
|
|
107
|
-
const result = set(new Date(2014, 8 /* Sep */), { year: undefined });
|
|
108
|
-
expect(result).toEqual(new Date(2014, 8 /* Sep */));
|
|
109
|
-
});
|
|
110
|
-
|
|
111
|
-
it('returns Invalid Date if any value in values is NaN', () => {
|
|
112
|
-
const result = set(new Date(2014, 8 /* Sep */), { year: NaN });
|
|
113
|
-
expect(isNaN(result.getTime())).toBe(true);
|
|
114
|
-
});
|
|
115
|
-
|
|
116
|
-
it('returns Invalid Date the initial date was Invalid Date as well', () => {
|
|
117
|
-
const result = set(new Date(NaN), { year: 2019 });
|
|
118
|
-
expect(isNaN(result.getTime())).toBe(true);
|
|
119
|
-
});
|
|
120
|
-
});
|
|
121
|
-
});
|