@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,111 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from 'vitest';
|
|
2
|
-
import { differenceInWeeks } from './index';
|
|
3
|
-
|
|
4
|
-
describe('differenceInWeeks', () => {
|
|
5
|
-
it('returns the number of full weeks between the given dates', () => {
|
|
6
|
-
const result = differenceInWeeks(new Date(2014, 6 /* Jul */, 8, 18, 0), new Date(2014, 5 /* Jun */, 29, 6, 0));
|
|
7
|
-
expect(result).toBe(1);
|
|
8
|
-
});
|
|
9
|
-
|
|
10
|
-
it('returns the number of weeks between the given dates with `trunc` as default a rounding method', () => {
|
|
11
|
-
const result = differenceInWeeks(new Date(2014, 5 /* Jun */, 29, 6, 0), new Date(2014, 6 /* Jul */, 13, 5, 0));
|
|
12
|
-
expect(result).toBe(-1);
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
it('returns the number of weeks between the given dates with `trunc` passed in as a rounding method', () => {
|
|
16
|
-
const result = differenceInWeeks(new Date(2014, 6 /* Jul */, 8, 18, 0), new Date(2014, 5 /* Jun */, 29, 6, 0), {
|
|
17
|
-
roundingMethod: 'trunc',
|
|
18
|
-
});
|
|
19
|
-
expect(result).toBe(1);
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
it('returns the number of weeks between the given dates with `ceil` passed in as a rounding method', () => {
|
|
23
|
-
const result = differenceInWeeks(new Date(2014, 6 /* Jul */, 8, 18, 0), new Date(2014, 5 /* Jun */, 29, 6, 0), {
|
|
24
|
-
roundingMethod: 'ceil',
|
|
25
|
-
});
|
|
26
|
-
expect(result).toBe(2);
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
it('returns the number of weeks between the given dates with `floor` passed in as a rounding method', () => {
|
|
30
|
-
const result = differenceInWeeks(new Date(2014, 6 /* Jul */, 8, 18, 0), new Date(2014, 5 /* Jun */, 29, 6, 0), {
|
|
31
|
-
roundingMethod: 'floor',
|
|
32
|
-
});
|
|
33
|
-
expect(result).toBe(1);
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
it('returns the number of weeks between the given dates with `round` passed in as a rounding method', () => {
|
|
37
|
-
const result = differenceInWeeks(new Date(2014, 6 /* Jul */, 10, 18, 0), new Date(2014, 5 /* Jun */, 29, 6, 0), {
|
|
38
|
-
roundingMethod: 'round',
|
|
39
|
-
});
|
|
40
|
-
expect(result).toBe(2);
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
it('returns a negative number if the time value of the first date is smaller', () => {
|
|
44
|
-
const result = differenceInWeeks(new Date(2014, 5 /* Jun */, 29, 6, 0), new Date(2014, 6 /* Jul */, 8, 18, 0));
|
|
45
|
-
expect(result).toBe(-1);
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
it('returns a 0, not a negative 0 - issue #2555 ', () => {
|
|
49
|
-
const result = differenceInWeeks(
|
|
50
|
-
new Date(2021, 6 /* Jul */, 22, 6, 1, 28.973),
|
|
51
|
-
new Date(2021, 6 /* Jul */, 22, 6, 1, 28.976),
|
|
52
|
-
);
|
|
53
|
-
expect(result).toBe(0);
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
it('accepts timestamps', () => {
|
|
57
|
-
const result = differenceInWeeks(
|
|
58
|
-
new Date(2014, 6 /* Jul */, 12).getTime(),
|
|
59
|
-
new Date(2014, 6 /* Jul */, 2).getTime(),
|
|
60
|
-
);
|
|
61
|
-
expect(result).toBe(1);
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
describe('edge cases', () => {
|
|
65
|
-
it('the difference is less than a week, but the given dates are in different calendar weeks', () => {
|
|
66
|
-
const result = differenceInWeeks(new Date(2014, 6 /* Jul */, 6), new Date(2014, 6 /* Jul */, 5));
|
|
67
|
-
expect(result).toBe(0);
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
it('the same for the swapped dates', () => {
|
|
71
|
-
const result = differenceInWeeks(new Date(2014, 6 /* Jul */, 5), new Date(2014, 6 /* Jul */, 6));
|
|
72
|
-
expect(result).toBe(0);
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
it('days of weeks of the given dates are the same', () => {
|
|
76
|
-
const result = differenceInWeeks(new Date(2014, 6 /* Jul */, 9), new Date(2014, 6 /* Jul */, 2));
|
|
77
|
-
expect(result).toBe(1);
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
it('the given dates are the same', () => {
|
|
81
|
-
const result = differenceInWeeks(new Date(2014, 8 /* Sep */, 5, 0, 0), new Date(2014, 8 /* Sep */, 5, 0, 0));
|
|
82
|
-
expect(result).toBe(0);
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
it('does not return -0 when the given dates are the same', () => {
|
|
86
|
-
function isNegativeZero(x: number): boolean {
|
|
87
|
-
return x === 0 && 1 / x < 0;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
const result = differenceInWeeks(new Date(2014, 8 /* Sep */, 5, 0, 0), new Date(2014, 8 /* Sep */, 5, 0, 0));
|
|
91
|
-
|
|
92
|
-
const resultIsNegative = isNegativeZero(result);
|
|
93
|
-
expect(resultIsNegative).toBe(false);
|
|
94
|
-
});
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
it('returns NaN if the first date is `Invalid Date`', () => {
|
|
98
|
-
const result = differenceInWeeks(new Date(NaN), new Date(2017, 0 /* Jan */, 1));
|
|
99
|
-
expect(isNaN(result)).toBe(true);
|
|
100
|
-
});
|
|
101
|
-
|
|
102
|
-
it('returns NaN if the second date is `Invalid Date`', () => {
|
|
103
|
-
const result = differenceInWeeks(new Date(2017, 0 /* Jan */, 1), new Date(NaN));
|
|
104
|
-
expect(isNaN(result)).toBe(true);
|
|
105
|
-
});
|
|
106
|
-
|
|
107
|
-
it('returns NaN if the both dates are `Invalid Date`', () => {
|
|
108
|
-
const result = differenceInWeeks(new Date(NaN), new Date(NaN));
|
|
109
|
-
expect(isNaN(result)).toBe(true);
|
|
110
|
-
});
|
|
111
|
-
});
|
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from 'vitest';
|
|
2
|
-
import { differenceInYears } from './index';
|
|
3
|
-
|
|
4
|
-
describe('differenceInYears', () => {
|
|
5
|
-
it('returns the number of full years between the given dates', () => {
|
|
6
|
-
const result = differenceInYears(new Date(2012, 6 /* Jul */, 2, 18, 0), new Date(2011, 6 /* Jul */, 2, 6, 0));
|
|
7
|
-
expect(result).toBe(1);
|
|
8
|
-
});
|
|
9
|
-
|
|
10
|
-
it('returns a negative number if the time value of the first date is smaller', () => {
|
|
11
|
-
const result = differenceInYears(new Date(2011, 6 /* Jul */, 2, 6, 0), new Date(2012, 6 /* Jul */, 2, 18, 0));
|
|
12
|
-
expect(result).toBe(-1);
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
it('accepts timestamps', () => {
|
|
16
|
-
const result = differenceInYears(
|
|
17
|
-
new Date(2014, 6 /* Jul */, 2).getTime(),
|
|
18
|
-
new Date(2010, 6 /* Jul */, 2).getTime(),
|
|
19
|
-
);
|
|
20
|
-
expect(result).toBe(4);
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
describe('leap days', () => {
|
|
24
|
-
it('supports past dates with right side after leap day', () => {
|
|
25
|
-
const result = differenceInYears(new Date(2004, 1 /* Feb */, 29, 0, 0), new Date(2002, 2 /* Mar */, 1, 0, 0));
|
|
26
|
-
expect(result).toBe(1);
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
it('supports past dates with right side before leap day', () => {
|
|
30
|
-
const result = differenceInYears(new Date(2004, 1 /* Feb */, 29, 0, 0), new Date(2002, 1 /* Feb */, 28, 0, 0));
|
|
31
|
-
expect(result).toBe(2);
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
it('supports future dates', () => {
|
|
35
|
-
const result = differenceInYears(new Date(2004, 1 /* Feb */, 29, 0, 0), new Date(2006, 2 /* Mar */, 1, 0, 0));
|
|
36
|
-
expect(result).toBe(-2);
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
it('supports equal dates of same year', () => {
|
|
40
|
-
const result = differenceInYears(new Date(2004, 1 /* Feb */, 29, 0, 0), new Date(2004, 1 /* Feb */, 29, 0, 0));
|
|
41
|
-
expect(result).toBe(0);
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
it('supports equal dates of different years', () => {
|
|
45
|
-
const result = differenceInYears(new Date(2008, 1 /* Feb */, 29, 0, 0), new Date(2004, 1 /* Feb */, 29, 0, 0));
|
|
46
|
-
expect(result).toBe(4);
|
|
47
|
-
});
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
describe('edge cases', () => {
|
|
51
|
-
it('the difference is less than a year, but the given dates are in different calendar years', () => {
|
|
52
|
-
const result = differenceInYears(new Date(2015, 0 /* Jan */, 1), new Date(2014, 11 /* Dec */, 31));
|
|
53
|
-
expect(result).toBe(0);
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
it('the same for the swapped dates', () => {
|
|
57
|
-
const result = differenceInYears(new Date(2014, 11 /* Dec */, 31), new Date(2015, 0 /* Jan */, 1));
|
|
58
|
-
expect(result).toBe(0);
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
it('the days and months of the given dates are the same', () => {
|
|
62
|
-
const result = differenceInYears(new Date(2014, 8 /* Sep */, 5), new Date(2012, 8 /* Sep */, 5));
|
|
63
|
-
expect(result).toBe(2);
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
it('the given dates are the same', () => {
|
|
67
|
-
const result = differenceInYears(new Date(2014, 8 /* Sep */, 5, 0, 0), new Date(2014, 8 /* Sep */, 5, 0, 0));
|
|
68
|
-
expect(result).toBe(0);
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
it('does not return -0 when the given dates are the same', () => {
|
|
72
|
-
function isNegativeZero(x: number): boolean {
|
|
73
|
-
return x === 0 && 1 / x < 0;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
const result = differenceInYears(new Date(2014, 8 /* Sep */, 5, 0, 0), new Date(2014, 8 /* Sep */, 5, 0, 0));
|
|
77
|
-
|
|
78
|
-
const resultIsNegative = isNegativeZero(result);
|
|
79
|
-
expect(resultIsNegative).toBe(false);
|
|
80
|
-
});
|
|
81
|
-
});
|
|
82
|
-
|
|
83
|
-
it('returns NaN if the first date is `Invalid Date`', () => {
|
|
84
|
-
const result = differenceInYears(new Date(NaN), new Date(2017, 0 /* Jan */, 1));
|
|
85
|
-
expect(isNaN(result)).toBe(true);
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
it('returns NaN if the second date is `Invalid Date`', () => {
|
|
89
|
-
const result = differenceInYears(new Date(2017, 0 /* Jan */, 1), new Date(NaN));
|
|
90
|
-
expect(isNaN(result)).toBe(true);
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
it('returns NaN if the both dates are `Invalid Date`', () => {
|
|
94
|
-
const result = differenceInYears(new Date(NaN), new Date(NaN));
|
|
95
|
-
expect(isNaN(result)).toBe(true);
|
|
96
|
-
});
|
|
97
|
-
});
|
|
@@ -1,164 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from 'vitest';
|
|
2
|
-
import { eachDayOfInterval } from './index';
|
|
3
|
-
|
|
4
|
-
describe('eachDayOfInterval', () => {
|
|
5
|
-
it('returns an array with starts of days from the day of the start date to the day of the end date', () => {
|
|
6
|
-
const result = eachDayOfInterval({
|
|
7
|
-
start: new Date(2014, 9 /* Oct */, 6),
|
|
8
|
-
end: new Date(2014, 9 /* Oct */, 12),
|
|
9
|
-
});
|
|
10
|
-
expect(result).toEqual([
|
|
11
|
-
new Date(2014, 9 /* Oct */, 6),
|
|
12
|
-
new Date(2014, 9 /* Oct */, 7),
|
|
13
|
-
new Date(2014, 9 /* Oct */, 8),
|
|
14
|
-
new Date(2014, 9 /* Oct */, 9),
|
|
15
|
-
new Date(2014, 9 /* Oct */, 10),
|
|
16
|
-
new Date(2014, 9 /* Oct */, 11),
|
|
17
|
-
new Date(2014, 9 /* Oct */, 12),
|
|
18
|
-
]);
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
it('accepts timestamps', () => {
|
|
22
|
-
const result = eachDayOfInterval({
|
|
23
|
-
start: new Date(2014, 9 /* Oct */, 6).getTime(),
|
|
24
|
-
end: new Date(2014, 9 /* Oct */, 12).getTime(),
|
|
25
|
-
});
|
|
26
|
-
expect(result).toEqual([
|
|
27
|
-
new Date(2014, 9 /* Oct */, 6),
|
|
28
|
-
new Date(2014, 9 /* Oct */, 7),
|
|
29
|
-
new Date(2014, 9 /* Oct */, 8),
|
|
30
|
-
new Date(2014, 9 /* Oct */, 9),
|
|
31
|
-
new Date(2014, 9 /* Oct */, 10),
|
|
32
|
-
new Date(2014, 9 /* Oct */, 11),
|
|
33
|
-
new Date(2014, 9 /* Oct */, 12),
|
|
34
|
-
]);
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
it('handles the dates that are not starts of days', () => {
|
|
38
|
-
const result = eachDayOfInterval({
|
|
39
|
-
start: new Date(2014, 9 /* Oct */, 6, 6, 35),
|
|
40
|
-
end: new Date(2014, 9 /* Oct */, 12, 22, 15),
|
|
41
|
-
});
|
|
42
|
-
expect(result).toEqual([
|
|
43
|
-
new Date(2014, 9 /* Oct */, 6),
|
|
44
|
-
new Date(2014, 9 /* Oct */, 7),
|
|
45
|
-
new Date(2014, 9 /* Oct */, 8),
|
|
46
|
-
new Date(2014, 9 /* Oct */, 9),
|
|
47
|
-
new Date(2014, 9 /* Oct */, 10),
|
|
48
|
-
new Date(2014, 9 /* Oct */, 11),
|
|
49
|
-
new Date(2014, 9 /* Oct */, 12),
|
|
50
|
-
]);
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
it('returns one day if the both arguments are on the same day', () => {
|
|
54
|
-
const result = eachDayOfInterval({
|
|
55
|
-
start: new Date(2014, 9 /* Oct */, 6, 14),
|
|
56
|
-
end: new Date(2014, 9 /* Oct */, 6, 15),
|
|
57
|
-
});
|
|
58
|
-
expect(result).toEqual([new Date(2014, 9 /* Oct */, 6)]);
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
it('returns one day if the both arguments are the same', () => {
|
|
62
|
-
const result = eachDayOfInterval({
|
|
63
|
-
start: new Date(2014, 9 /* Oct */, 6, 14),
|
|
64
|
-
end: new Date(2014, 9 /* Oct */, 6, 14),
|
|
65
|
-
});
|
|
66
|
-
expect(result).toEqual([new Date(2014, 9 /* Oct */, 6)]);
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
it('returns reversed array if the start date is after the end date', () => {
|
|
70
|
-
const result = eachDayOfInterval({
|
|
71
|
-
start: new Date(2014, 9 /* Oct */, 12),
|
|
72
|
-
end: new Date(2014, 9 /* Oct */, 6),
|
|
73
|
-
});
|
|
74
|
-
expect(result).toEqual([
|
|
75
|
-
new Date(2014, 9 /* Oct */, 12),
|
|
76
|
-
new Date(2014, 9 /* Oct */, 11),
|
|
77
|
-
new Date(2014, 9 /* Oct */, 10),
|
|
78
|
-
new Date(2014, 9 /* Oct */, 9),
|
|
79
|
-
new Date(2014, 9 /* Oct */, 8),
|
|
80
|
-
new Date(2014, 9 /* Oct */, 7),
|
|
81
|
-
new Date(2014, 9 /* Oct */, 6),
|
|
82
|
-
]);
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
it('returns an empty array if the start date is `Invalid Date`', () => {
|
|
86
|
-
const result = eachDayOfInterval({
|
|
87
|
-
start: new Date(NaN),
|
|
88
|
-
end: new Date(2014, 9 /* Oct */, 6),
|
|
89
|
-
});
|
|
90
|
-
expect(result).toEqual([]);
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
it('returns an empty array if the end date is `Invalid Date`', () => {
|
|
94
|
-
const result = eachDayOfInterval({
|
|
95
|
-
start: new Date(2014, 9 /* Oct */, 12),
|
|
96
|
-
end: new Date(NaN),
|
|
97
|
-
});
|
|
98
|
-
expect(result).toEqual([]);
|
|
99
|
-
});
|
|
100
|
-
|
|
101
|
-
it('returns an empty array if both of the properties are `Invalid Date`', () => {
|
|
102
|
-
const result = eachDayOfInterval({
|
|
103
|
-
start: new Date(NaN),
|
|
104
|
-
end: new Date(NaN),
|
|
105
|
-
});
|
|
106
|
-
expect(result).toEqual([]);
|
|
107
|
-
});
|
|
108
|
-
|
|
109
|
-
describe('options.step', () => {
|
|
110
|
-
const interval = {
|
|
111
|
-
start: new Date(2014, 9 /* Oct */, 6),
|
|
112
|
-
end: new Date(2014, 9 /* Oct */, 13),
|
|
113
|
-
};
|
|
114
|
-
|
|
115
|
-
it('returns an array with starts of days from the day of the start date to the day of the end date with the given step', () => {
|
|
116
|
-
const result = eachDayOfInterval(interval, { step: 3 });
|
|
117
|
-
expect(result).toEqual([
|
|
118
|
-
new Date(2014, 9 /* Oct */, 6),
|
|
119
|
-
new Date(2014, 9 /* Oct */, 9),
|
|
120
|
-
new Date(2014, 9 /* Oct */, 12),
|
|
121
|
-
]);
|
|
122
|
-
});
|
|
123
|
-
|
|
124
|
-
it('returns reversed array if `options.step` is negative', () => {
|
|
125
|
-
const result = eachDayOfInterval(
|
|
126
|
-
{
|
|
127
|
-
start: new Date(2014, 9 /* Oct */, 10),
|
|
128
|
-
end: new Date(2014, 9 /* Oct */, 12),
|
|
129
|
-
},
|
|
130
|
-
{ step: -1 },
|
|
131
|
-
);
|
|
132
|
-
expect(result).toEqual([
|
|
133
|
-
new Date(2014, 9 /* Oct */, 12),
|
|
134
|
-
new Date(2014, 9 /* Oct */, 11),
|
|
135
|
-
new Date(2014, 9 /* Oct */, 10),
|
|
136
|
-
]);
|
|
137
|
-
});
|
|
138
|
-
|
|
139
|
-
it('reverses array twice if `options.step` is negative and the interval is negative too', () => {
|
|
140
|
-
const result = eachDayOfInterval(
|
|
141
|
-
{
|
|
142
|
-
start: new Date(2014, 9 /* Oct */, 12),
|
|
143
|
-
end: new Date(2014, 9 /* Oct */, 10),
|
|
144
|
-
},
|
|
145
|
-
{ step: -1 },
|
|
146
|
-
);
|
|
147
|
-
expect(result).toEqual([
|
|
148
|
-
new Date(2014, 9 /* Oct */, 10),
|
|
149
|
-
new Date(2014, 9 /* Oct */, 11),
|
|
150
|
-
new Date(2014, 9 /* Oct */, 12),
|
|
151
|
-
]);
|
|
152
|
-
});
|
|
153
|
-
|
|
154
|
-
it('returns empty array if `options.step` is less than 1', () => {
|
|
155
|
-
const result = eachDayOfInterval(interval, { step: 0 });
|
|
156
|
-
expect(result).toEqual([]);
|
|
157
|
-
});
|
|
158
|
-
|
|
159
|
-
it('returns empty array if `options.step` is NaN', () => {
|
|
160
|
-
const result = eachDayOfInterval(interval, { step: NaN });
|
|
161
|
-
expect(result).toEqual([]);
|
|
162
|
-
});
|
|
163
|
-
});
|
|
164
|
-
});
|
|
@@ -1,154 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from 'vitest';
|
|
2
|
-
import { eachHourOfInterval } from './index';
|
|
3
|
-
|
|
4
|
-
describe('eachHourOfInterval', () => {
|
|
5
|
-
it('returns an array with starts of hours from the hour of the start date to the hour of the end date', () => {
|
|
6
|
-
const result = eachHourOfInterval({
|
|
7
|
-
start: new Date(2014, 9 /* Oct */, 6, 12),
|
|
8
|
-
end: new Date(2014, 9 /* Oct */, 6, 15),
|
|
9
|
-
});
|
|
10
|
-
expect(result).toEqual([
|
|
11
|
-
new Date(2014, 9 /* Oct */, 6, 12),
|
|
12
|
-
new Date(2014, 9 /* Oct */, 6, 13),
|
|
13
|
-
new Date(2014, 9 /* Oct */, 6, 14),
|
|
14
|
-
new Date(2014, 9 /* Oct */, 6, 15),
|
|
15
|
-
]);
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
it('accepts timestamps', () => {
|
|
19
|
-
const result = eachHourOfInterval({
|
|
20
|
-
start: new Date(2014, 9 /* Oct */, 6, 12).getTime(),
|
|
21
|
-
end: new Date(2014, 9 /* Oct */, 6, 15).getTime(),
|
|
22
|
-
});
|
|
23
|
-
expect(result).toEqual([
|
|
24
|
-
new Date(2014, 9 /* Oct */, 6, 12),
|
|
25
|
-
new Date(2014, 9 /* Oct */, 6, 13),
|
|
26
|
-
new Date(2014, 9 /* Oct */, 6, 14),
|
|
27
|
-
new Date(2014, 9 /* Oct */, 6, 15),
|
|
28
|
-
]);
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
it('handles the hours that are not starts of hours', () => {
|
|
32
|
-
const result = eachHourOfInterval({
|
|
33
|
-
start: new Date(2014, 9 /* Oct */, 6, 12, 59, 59, 999),
|
|
34
|
-
end: new Date(2014, 9 /* Oct */, 6, 15, 59, 59, 999),
|
|
35
|
-
});
|
|
36
|
-
expect(result).toEqual([
|
|
37
|
-
new Date(2014, 9 /* Oct */, 6, 12),
|
|
38
|
-
new Date(2014, 9 /* Oct */, 6, 13),
|
|
39
|
-
new Date(2014, 9 /* Oct */, 6, 14),
|
|
40
|
-
new Date(2014, 9 /* Oct */, 6, 15),
|
|
41
|
-
]);
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
it('returns one hour if the both arguments are on the same hour', () => {
|
|
45
|
-
const result = eachHourOfInterval({
|
|
46
|
-
start: new Date(2014, 9 /* Oct */, 6, 12, 35),
|
|
47
|
-
end: new Date(2014, 9 /* Oct */, 6, 12, 47),
|
|
48
|
-
});
|
|
49
|
-
expect(result).toEqual([new Date(2014, 9 /* Oct */, 6, 12)]);
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
it('returns one hour if the both arguments are the same', () => {
|
|
53
|
-
const result = eachHourOfInterval({
|
|
54
|
-
start: new Date(2014, 9 /* Oct */, 6, 12, 35),
|
|
55
|
-
end: new Date(2014, 9 /* Oct */, 6, 12, 35),
|
|
56
|
-
});
|
|
57
|
-
expect(result).toEqual([new Date(2014, 9 /* Oct */, 6, 12)]);
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
it('returns reversed array if the start date is after the end date', () => {
|
|
61
|
-
const result = eachHourOfInterval({
|
|
62
|
-
start: new Date(2014, 9 /* Oct */, 6, 15),
|
|
63
|
-
end: new Date(2014, 9 /* Oct */, 6, 12),
|
|
64
|
-
});
|
|
65
|
-
expect(result).toEqual([
|
|
66
|
-
new Date(2014, 9 /* Oct */, 6, 15),
|
|
67
|
-
new Date(2014, 9 /* Oct */, 6, 14),
|
|
68
|
-
new Date(2014, 9 /* Oct */, 6, 13),
|
|
69
|
-
new Date(2014, 9 /* Oct */, 6, 12),
|
|
70
|
-
]);
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
it('returns an empty array if the start date is `Invalid Date`', () => {
|
|
74
|
-
const result = eachHourOfInterval({
|
|
75
|
-
start: new Date(NaN),
|
|
76
|
-
end: new Date(2014, 9 /* Oct */, 6, 12),
|
|
77
|
-
});
|
|
78
|
-
expect(result).toEqual([]);
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
it('returns an empty array if the end date is `Invalid Date`', () => {
|
|
82
|
-
const result = eachHourOfInterval({
|
|
83
|
-
start: new Date(2014, 9 /* Oct */, 12, 12),
|
|
84
|
-
end: new Date(NaN),
|
|
85
|
-
});
|
|
86
|
-
expect(result).toEqual([]);
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
it('returns an empty array if both of the properties are `Invalid Date`', () => {
|
|
90
|
-
const result = eachHourOfInterval({
|
|
91
|
-
start: new Date(NaN),
|
|
92
|
-
end: new Date(NaN),
|
|
93
|
-
});
|
|
94
|
-
expect(result).toEqual([]);
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
describe('options.step', () => {
|
|
98
|
-
const interval = {
|
|
99
|
-
start: new Date(2014, 9 /* Oct */, 6, 12),
|
|
100
|
-
end: new Date(2014, 9 /* Oct */, 6, 18),
|
|
101
|
-
};
|
|
102
|
-
|
|
103
|
-
it('returns an array with starts of hours from the hour of the start date to the hour of the end date with the given step', () => {
|
|
104
|
-
const result = eachHourOfInterval(interval, { step: 3 });
|
|
105
|
-
expect(result).toEqual([
|
|
106
|
-
new Date(2014, 9 /* Oct */, 6, 12),
|
|
107
|
-
new Date(2014, 9 /* Oct */, 6, 15),
|
|
108
|
-
new Date(2014, 9 /* Oct */, 6, 18),
|
|
109
|
-
]);
|
|
110
|
-
});
|
|
111
|
-
|
|
112
|
-
it('returns reversed array if `options.step` is negative', () => {
|
|
113
|
-
const result = eachHourOfInterval(
|
|
114
|
-
{
|
|
115
|
-
start: new Date(2014, 9 /* Oct */, 6, 12),
|
|
116
|
-
end: new Date(2014, 9 /* Oct */, 6, 15),
|
|
117
|
-
},
|
|
118
|
-
{ step: -1 },
|
|
119
|
-
);
|
|
120
|
-
expect(result).toEqual([
|
|
121
|
-
new Date(2014, 9 /* Oct */, 6, 15),
|
|
122
|
-
new Date(2014, 9 /* Oct */, 6, 14),
|
|
123
|
-
new Date(2014, 9 /* Oct */, 6, 13),
|
|
124
|
-
new Date(2014, 9 /* Oct */, 6, 12),
|
|
125
|
-
]);
|
|
126
|
-
});
|
|
127
|
-
|
|
128
|
-
it('reverses array twice if `options.step` is negative and the interval is negative too', () => {
|
|
129
|
-
const result = eachHourOfInterval(
|
|
130
|
-
{
|
|
131
|
-
start: new Date(2014, 9 /* Oct */, 6, 15),
|
|
132
|
-
end: new Date(2014, 9 /* Oct */, 6, 12),
|
|
133
|
-
},
|
|
134
|
-
{ step: -1 },
|
|
135
|
-
);
|
|
136
|
-
expect(result).toEqual([
|
|
137
|
-
new Date(2014, 9 /* Oct */, 6, 12),
|
|
138
|
-
new Date(2014, 9 /* Oct */, 6, 13),
|
|
139
|
-
new Date(2014, 9 /* Oct */, 6, 14),
|
|
140
|
-
new Date(2014, 9 /* Oct */, 6, 15),
|
|
141
|
-
]);
|
|
142
|
-
});
|
|
143
|
-
|
|
144
|
-
it('returns empty array if `options.step` is less than 1', () => {
|
|
145
|
-
const result = eachHourOfInterval(interval, { step: 0 });
|
|
146
|
-
expect(result).toEqual([]);
|
|
147
|
-
});
|
|
148
|
-
|
|
149
|
-
it('returns empty array if `options.step` is NaN', () => {
|
|
150
|
-
const result = eachHourOfInterval(interval, { step: NaN });
|
|
151
|
-
expect(result).toEqual([]);
|
|
152
|
-
});
|
|
153
|
-
});
|
|
154
|
-
});
|
|
@@ -1,159 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from 'vitest';
|
|
2
|
-
|
|
3
|
-
import { eachMinuteOfInterval } from './index';
|
|
4
|
-
|
|
5
|
-
describe('eachMinuteOfInterval', () => {
|
|
6
|
-
it('should return an array of Date objects containing a Date for each minute between the interval', () => {
|
|
7
|
-
const result = eachMinuteOfInterval({
|
|
8
|
-
start: new Date(2020, 10, 14, 13, 0),
|
|
9
|
-
end: new Date(2020, 10, 14, 13, 5),
|
|
10
|
-
});
|
|
11
|
-
|
|
12
|
-
expect(result).toEqual([
|
|
13
|
-
new Date(2020, 10, 14, 13, 0),
|
|
14
|
-
new Date(2020, 10, 14, 13, 1),
|
|
15
|
-
new Date(2020, 10, 14, 13, 2),
|
|
16
|
-
new Date(2020, 10, 14, 13, 3),
|
|
17
|
-
new Date(2020, 10, 14, 13, 4),
|
|
18
|
-
new Date(2020, 10, 14, 13, 5),
|
|
19
|
-
]);
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
it('should handle all the minutes that are not in the begining', () => {
|
|
23
|
-
const result = eachMinuteOfInterval({
|
|
24
|
-
start: new Date(2020, 10, 14, 13, 0, 33),
|
|
25
|
-
end: new Date(2020, 10, 14, 13, 2),
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
expect(result[0]).toEqual(new Date(2020, 10, 14, 13));
|
|
29
|
-
expect(result[2]).toEqual(new Date(2020, 10, 14, 13, 2));
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
it('should accept timestamps', () => {
|
|
33
|
-
const start = new Date(2020, 10, 14, 13, 0).getTime();
|
|
34
|
-
const end = new Date(2020, 10, 14, 13, 2).getTime();
|
|
35
|
-
|
|
36
|
-
const result = eachMinuteOfInterval({
|
|
37
|
-
start,
|
|
38
|
-
end,
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
expect(result).toEqual([
|
|
42
|
-
new Date(2020, 10, 14, 13, 0),
|
|
43
|
-
new Date(2020, 10, 14, 13, 1),
|
|
44
|
-
new Date(2020, 10, 14, 13, 2),
|
|
45
|
-
]);
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
it('treats intervals shorter than a minute as valid', () => {
|
|
49
|
-
const block = eachMinuteOfInterval.bind(null, {
|
|
50
|
-
start: new Date(2014, 10, 14, 10, 1, 0),
|
|
51
|
-
end: new Date(2014, 10, 14, 10, 1, 1),
|
|
52
|
-
});
|
|
53
|
-
expect(block).not.toThrow();
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
it('returns reversed array if the start date is after the end date', () => {
|
|
57
|
-
const result = eachMinuteOfInterval({
|
|
58
|
-
start: new Date(2020, 10, 14, 13, 5),
|
|
59
|
-
end: new Date(2020, 10, 14, 13, 0),
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
expect(result).toEqual([
|
|
63
|
-
new Date(2020, 10, 14, 13, 5),
|
|
64
|
-
new Date(2020, 10, 14, 13, 4),
|
|
65
|
-
new Date(2020, 10, 14, 13, 3),
|
|
66
|
-
new Date(2020, 10, 14, 13, 2),
|
|
67
|
-
new Date(2020, 10, 14, 13, 1),
|
|
68
|
-
new Date(2020, 10, 14, 13, 0),
|
|
69
|
-
]);
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
it('returns an empty array if the start date is `Invalid Date`', () => {
|
|
73
|
-
const result = eachMinuteOfInterval({
|
|
74
|
-
start: new Date(NaN),
|
|
75
|
-
end: new Date(2014, 9 /* Oct */, 6),
|
|
76
|
-
});
|
|
77
|
-
expect(result).toEqual([]);
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
it('returns an empty array if the end date is `Invalid Date`', () => {
|
|
81
|
-
const result = eachMinuteOfInterval({
|
|
82
|
-
start: new Date(2014, 9 /* Oct */, 12),
|
|
83
|
-
end: new Date(NaN),
|
|
84
|
-
});
|
|
85
|
-
expect(result).toEqual([]);
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
it('returns an empty array if both of the properties are `Invalid Date`', () => {
|
|
89
|
-
const result = eachMinuteOfInterval({
|
|
90
|
-
start: new Date(NaN),
|
|
91
|
-
end: new Date(NaN),
|
|
92
|
-
});
|
|
93
|
-
expect(result).toEqual([]);
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
describe('options.step', () => {
|
|
97
|
-
const interval = {
|
|
98
|
-
start: new Date(2020, 9, 14, 13, 1),
|
|
99
|
-
end: new Date(2020, 9, 14, 13, 7),
|
|
100
|
-
};
|
|
101
|
-
|
|
102
|
-
it('returns an array with starts of hours from the hour of the start date to the hour of the end date with the given step', () => {
|
|
103
|
-
const result = eachMinuteOfInterval(interval, { step: 3 });
|
|
104
|
-
expect(result).toEqual([
|
|
105
|
-
new Date(2020, 9, 14, 13, 1),
|
|
106
|
-
new Date(2020, 9, 14, 13, 4),
|
|
107
|
-
new Date(2020, 9, 14, 13, 7),
|
|
108
|
-
]);
|
|
109
|
-
});
|
|
110
|
-
|
|
111
|
-
it('returns reversed array if `options.step` is negative', () => {
|
|
112
|
-
const result = eachMinuteOfInterval(
|
|
113
|
-
{
|
|
114
|
-
start: new Date(2020, 10, 14, 13, 0),
|
|
115
|
-
end: new Date(2020, 10, 14, 13, 5),
|
|
116
|
-
},
|
|
117
|
-
{ step: -1 },
|
|
118
|
-
);
|
|
119
|
-
|
|
120
|
-
expect(result).toEqual([
|
|
121
|
-
new Date(2020, 10, 14, 13, 5),
|
|
122
|
-
new Date(2020, 10, 14, 13, 4),
|
|
123
|
-
new Date(2020, 10, 14, 13, 3),
|
|
124
|
-
new Date(2020, 10, 14, 13, 2),
|
|
125
|
-
new Date(2020, 10, 14, 13, 1),
|
|
126
|
-
new Date(2020, 10, 14, 13, 0),
|
|
127
|
-
]);
|
|
128
|
-
});
|
|
129
|
-
|
|
130
|
-
it('reverses array twice if `options.step` is negative and the interval is negative too', () => {
|
|
131
|
-
const result = eachMinuteOfInterval(
|
|
132
|
-
{
|
|
133
|
-
start: new Date(2020, 10, 14, 13, 5),
|
|
134
|
-
end: new Date(2020, 10, 14, 13, 0),
|
|
135
|
-
},
|
|
136
|
-
{ step: -1 },
|
|
137
|
-
);
|
|
138
|
-
|
|
139
|
-
expect(result).toEqual([
|
|
140
|
-
new Date(2020, 10, 14, 13, 0),
|
|
141
|
-
new Date(2020, 10, 14, 13, 1),
|
|
142
|
-
new Date(2020, 10, 14, 13, 2),
|
|
143
|
-
new Date(2020, 10, 14, 13, 3),
|
|
144
|
-
new Date(2020, 10, 14, 13, 4),
|
|
145
|
-
new Date(2020, 10, 14, 13, 5),
|
|
146
|
-
]);
|
|
147
|
-
});
|
|
148
|
-
|
|
149
|
-
it('returns empty array if `options.step` is less than 1', () => {
|
|
150
|
-
const result = eachMinuteOfInterval(interval, { step: 0 });
|
|
151
|
-
expect(result).toEqual([]);
|
|
152
|
-
});
|
|
153
|
-
|
|
154
|
-
it('returns empty array if `options.step` is NaN', () => {
|
|
155
|
-
const result = eachMinuteOfInterval(interval, { step: NaN });
|
|
156
|
-
expect(result).toEqual([]);
|
|
157
|
-
});
|
|
158
|
-
});
|
|
159
|
-
});
|