@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,27 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from 'vitest';
|
|
2
|
-
import { getISOWeekYear } from './index';
|
|
3
|
-
|
|
4
|
-
describe('getISOWeekYear', () => {
|
|
5
|
-
it('returns the ISO week-numbering year of the given date', () => {
|
|
6
|
-
const result = getISOWeekYear(new Date(2007, 11 /* Dec */, 31));
|
|
7
|
-
expect(result).toBe(2008);
|
|
8
|
-
});
|
|
9
|
-
|
|
10
|
-
it('accepts a timestamp', () => {
|
|
11
|
-
const result = getISOWeekYear(new Date(2005, 0 /* Jan */, 1).getTime());
|
|
12
|
-
expect(result).toBe(2004);
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
it('handles dates before 100 AD', () => {
|
|
16
|
-
const initialDate = new Date(0);
|
|
17
|
-
initialDate.setFullYear(7, 11 /* Dec */, 31);
|
|
18
|
-
initialDate.setHours(0, 0, 0, 0);
|
|
19
|
-
const result = getISOWeekYear(initialDate);
|
|
20
|
-
expect(result).toBe(8);
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
it('returns NaN if the given date is invalid', () => {
|
|
24
|
-
const result = getISOWeekYear(new Date(NaN));
|
|
25
|
-
expect(isNaN(result)).toBe(true);
|
|
26
|
-
});
|
|
27
|
-
});
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from 'vitest';
|
|
2
|
-
import { getISOWeeksInYear } from './index';
|
|
3
|
-
|
|
4
|
-
describe('getISOWeeksInYear', () => {
|
|
5
|
-
it('returns the number of ISO weeks in the ISO week-numbering year of the given date', () => {
|
|
6
|
-
const result = getISOWeeksInYear(new Date(2015, 1 /* Feb */, 11));
|
|
7
|
-
expect(result).toBe(53);
|
|
8
|
-
});
|
|
9
|
-
|
|
10
|
-
it('accepts a timestamp', () => {
|
|
11
|
-
const date = new Date(2003, 11 /* Dec */, 30);
|
|
12
|
-
const result = getISOWeeksInYear(+date);
|
|
13
|
-
expect(result).toBe(53);
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
it('handles dates before 100 AD', () => {
|
|
17
|
-
const initialDate = new Date(0);
|
|
18
|
-
initialDate.setFullYear(4, 0 /* Jan */, 4);
|
|
19
|
-
initialDate.setHours(0, 0, 0, 0);
|
|
20
|
-
const result = getISOWeeksInYear(initialDate);
|
|
21
|
-
expect(result).toBe(53);
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
it('returns NaN if the given date is invalid', () => {
|
|
25
|
-
const result = getISOWeeksInYear(new Date(NaN));
|
|
26
|
-
expect(isNaN(result)).toBe(true);
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
it('properly works with negative numbers', () => {
|
|
30
|
-
expect(getISOWeeksInYear(new Date(2015, 1 /* Feb */, 11))).toBe(53);
|
|
31
|
-
// The number must differ. The Gregorian calendar repeats every 400 years,
|
|
32
|
-
// so the number of ISO weeks as well. -2015 corresponds to 385 AD where
|
|
33
|
-
// there was 52 ISO weeks.
|
|
34
|
-
expect(getISOWeeksInYear(new Date(-2015, 1 /* Feb */, 11))).toBe(52);
|
|
35
|
-
expect(getISOWeeksInYear(new Date(385, 1 /* Feb */, 11))).toBe(52);
|
|
36
|
-
});
|
|
37
|
-
});
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from 'vitest';
|
|
2
|
-
import { getMilliseconds } from './index';
|
|
3
|
-
|
|
4
|
-
describe('getMilliseconds', () => {
|
|
5
|
-
it('returns the milliseconds of the given date', () => {
|
|
6
|
-
const result = getMilliseconds(new Date(2012, 1 /* Feb */, 29, 11, 45, 5, 123));
|
|
7
|
-
expect(result).toBe(123);
|
|
8
|
-
});
|
|
9
|
-
|
|
10
|
-
it('accepts a timestamp', () => {
|
|
11
|
-
const result = getMilliseconds(new Date(2014, 3 /* Apr */, 2, 23, 30, 42, 500).getTime());
|
|
12
|
-
expect(result).toBe(500);
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
it('returns NaN if the given date is invalid', () => {
|
|
16
|
-
const result = getMilliseconds(new Date(NaN));
|
|
17
|
-
expect(isNaN(result)).toBe(true);
|
|
18
|
-
});
|
|
19
|
-
});
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from 'vitest';
|
|
2
|
-
import { getMinutes } from './index';
|
|
3
|
-
|
|
4
|
-
describe('getMinutes', () => {
|
|
5
|
-
it('returns the minutes of the given date', () => {
|
|
6
|
-
const result = getMinutes(new Date(2012, 1 /* Feb */, 29, 11, 45, 5));
|
|
7
|
-
expect(result).toBe(45);
|
|
8
|
-
});
|
|
9
|
-
|
|
10
|
-
it('accepts a timestamp', () => {
|
|
11
|
-
const result = getMinutes(new Date(2014, 3 /* Apr */, 2, 23, 30).getTime());
|
|
12
|
-
expect(result).toBe(30);
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
it('returns NaN if the given date is invalid', () => {
|
|
16
|
-
const result = getMinutes(new Date(NaN));
|
|
17
|
-
expect(isNaN(result)).toBe(true);
|
|
18
|
-
});
|
|
19
|
-
});
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from 'vitest';
|
|
2
|
-
import { getMonth } from './index';
|
|
3
|
-
|
|
4
|
-
describe('getMonth', () => {
|
|
5
|
-
it('returns the month of the given date', () => {
|
|
6
|
-
const result = getMonth(new Date(2012, 1 /* Feb */, 29));
|
|
7
|
-
expect(result).toBe(1);
|
|
8
|
-
});
|
|
9
|
-
|
|
10
|
-
it('accepts a timestamp', () => {
|
|
11
|
-
const result = getMonth(new Date(2014, 3 /* Apr */, 2).getTime());
|
|
12
|
-
expect(result).toBe(3);
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
it('returns NaN if the given date is invalid', () => {
|
|
16
|
-
const result = getMonth(new Date(NaN));
|
|
17
|
-
expect(isNaN(result)).toBe(true);
|
|
18
|
-
});
|
|
19
|
-
});
|
|
@@ -1,243 +0,0 @@
|
|
|
1
|
-
/* eslint-env mocha */
|
|
2
|
-
|
|
3
|
-
import { describe, expect, it } from 'vitest';
|
|
4
|
-
import { getOverlappingDaysInIntervals } from './index';
|
|
5
|
-
|
|
6
|
-
describe('getOverlappingDaysInIntervals', () => {
|
|
7
|
-
const initialIntervalStart = new Date(2016, 10, 10, 13, 0, 0);
|
|
8
|
-
const initialIntervalEnd = new Date(2016, 11, 3, 15, 0, 0);
|
|
9
|
-
|
|
10
|
-
describe("when the time intervals don't overlap", () => {
|
|
11
|
-
it('returns 0 for a valid non overlapping interval before another interval', () => {
|
|
12
|
-
const earlierIntervalStart = new Date(2016, 9, 25);
|
|
13
|
-
const earlierIntervalEnd = new Date(2016, 10, 9);
|
|
14
|
-
|
|
15
|
-
const numOverlappingDays = getOverlappingDaysInIntervals(
|
|
16
|
-
{ start: initialIntervalStart, end: initialIntervalEnd },
|
|
17
|
-
{ start: earlierIntervalStart, end: earlierIntervalEnd },
|
|
18
|
-
);
|
|
19
|
-
expect(numOverlappingDays).toBe(0);
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
it('returns 0 for a valid non overlapping interval after another interval', () => {
|
|
23
|
-
const laterIntervalStart = new Date(2016, 11, 4);
|
|
24
|
-
const laterIntervalEnd = new Date(2016, 11, 9);
|
|
25
|
-
|
|
26
|
-
const numOverlappingDays = getOverlappingDaysInIntervals(
|
|
27
|
-
{ start: initialIntervalStart, end: initialIntervalEnd },
|
|
28
|
-
{ start: laterIntervalStart, end: laterIntervalEnd },
|
|
29
|
-
);
|
|
30
|
-
expect(numOverlappingDays).toBe(0);
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
it('returns 0 for a non overlapping same-day interval', () => {
|
|
34
|
-
const sameDayIntervalStart = new Date(2016, 11, 4, 9, 0, 0);
|
|
35
|
-
const sameDayIntervalEnd = new Date(2016, 11, 4, 18, 0, 0);
|
|
36
|
-
|
|
37
|
-
const numOverlappingDays = getOverlappingDaysInIntervals(
|
|
38
|
-
{ start: initialIntervalStart, end: initialIntervalEnd },
|
|
39
|
-
{ start: sameDayIntervalStart, end: sameDayIntervalEnd },
|
|
40
|
-
);
|
|
41
|
-
expect(numOverlappingDays).toBe(0);
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
it('returns 0 for an interval differing by a few hours', () => {
|
|
45
|
-
const oneDayOverlappingIntervalStart = new Date(2016, 11, 3, 18, 0, 0);
|
|
46
|
-
const oneDayOverlappingIntervalEnd = new Date(2016, 11, 14, 13, 0, 0);
|
|
47
|
-
|
|
48
|
-
const numOverlappingDays = getOverlappingDaysInIntervals(
|
|
49
|
-
{ start: initialIntervalStart, end: initialIntervalEnd },
|
|
50
|
-
{
|
|
51
|
-
start: oneDayOverlappingIntervalStart,
|
|
52
|
-
end: oneDayOverlappingIntervalEnd,
|
|
53
|
-
},
|
|
54
|
-
);
|
|
55
|
-
expect(numOverlappingDays).toBe(0);
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
it("returns 0 for an interval with the same startDateTime as the initial time intervals's endDateTime", () => {
|
|
59
|
-
const oneDayOverlapIntervalStart = new Date(2016, 11, 3, 15, 0, 0);
|
|
60
|
-
const oneDayOverlapIntervalEnd = new Date(2016, 11, 14, 13, 0, 0);
|
|
61
|
-
|
|
62
|
-
const numOverlappingDays = getOverlappingDaysInIntervals(
|
|
63
|
-
{ start: initialIntervalStart, end: initialIntervalEnd },
|
|
64
|
-
{ start: oneDayOverlapIntervalStart, end: oneDayOverlapIntervalEnd },
|
|
65
|
-
);
|
|
66
|
-
expect(numOverlappingDays).toBe(0);
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
it("returns 0 for an interval with the same endDateTime as the initial time interval's startDateTime", () => {
|
|
70
|
-
const oneDayOverlapIntervalStart = new Date(2016, 10, 3, 15, 0, 0);
|
|
71
|
-
const oneDayOverlapIntervalEnd = new Date(2016, 10, 10, 13, 0, 0);
|
|
72
|
-
|
|
73
|
-
const numOverlappingDays = getOverlappingDaysInIntervals(
|
|
74
|
-
{ start: initialIntervalStart, end: initialIntervalEnd },
|
|
75
|
-
{ start: oneDayOverlapIntervalStart, end: oneDayOverlapIntervalEnd },
|
|
76
|
-
);
|
|
77
|
-
expect(numOverlappingDays).toBe(0);
|
|
78
|
-
});
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
describe('when the time intervals overlap', () => {
|
|
82
|
-
it('rounds up the result to include each started overlapping day', () => {
|
|
83
|
-
const includedIntervalStart = new Date(2016, 10, 14, 9, 0, 0);
|
|
84
|
-
const includedIntervalEnd = new Date(2016, 10, 15, 18, 0, 0);
|
|
85
|
-
|
|
86
|
-
const numOverlappingDays = getOverlappingDaysInIntervals(
|
|
87
|
-
{ start: initialIntervalStart, end: initialIntervalEnd },
|
|
88
|
-
{ start: includedIntervalStart, end: includedIntervalEnd },
|
|
89
|
-
);
|
|
90
|
-
expect(numOverlappingDays).toBe(2);
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
it('returns the correct value for an interval included within another interval', () => {
|
|
94
|
-
const includedIntervalStart = new Date(2016, 10, 14);
|
|
95
|
-
const includedIntervalEnd = new Date(2016, 10, 15);
|
|
96
|
-
|
|
97
|
-
const numOverlappingDays = getOverlappingDaysInIntervals(
|
|
98
|
-
{ start: initialIntervalStart, end: initialIntervalEnd },
|
|
99
|
-
{ start: includedIntervalStart, end: includedIntervalEnd },
|
|
100
|
-
);
|
|
101
|
-
expect(numOverlappingDays).toBe(1);
|
|
102
|
-
});
|
|
103
|
-
|
|
104
|
-
it('returns the correct value for an interval overlapping at the end', () => {
|
|
105
|
-
const endOverlappingIntervalStart = new Date(2016, 10, 5);
|
|
106
|
-
const endOverlappingIntervalEnd = new Date(2016, 10, 14);
|
|
107
|
-
|
|
108
|
-
const numOverlappingDays = getOverlappingDaysInIntervals(
|
|
109
|
-
{ start: initialIntervalStart, end: initialIntervalEnd },
|
|
110
|
-
{ start: endOverlappingIntervalStart, end: endOverlappingIntervalEnd },
|
|
111
|
-
);
|
|
112
|
-
expect(numOverlappingDays).toBe(4);
|
|
113
|
-
});
|
|
114
|
-
|
|
115
|
-
it('returns the correct value for an interval overlapping at the beginning', () => {
|
|
116
|
-
const startOverlappingIntervalStart = new Date(2016, 10, 20);
|
|
117
|
-
const startOverlappingIntervalEnd = new Date(2016, 11, 14);
|
|
118
|
-
|
|
119
|
-
const numOverlappingDays = getOverlappingDaysInIntervals(
|
|
120
|
-
{ start: initialIntervalStart, end: initialIntervalEnd },
|
|
121
|
-
{
|
|
122
|
-
start: startOverlappingIntervalStart,
|
|
123
|
-
end: startOverlappingIntervalEnd,
|
|
124
|
-
},
|
|
125
|
-
);
|
|
126
|
-
expect(numOverlappingDays).toBe(14);
|
|
127
|
-
});
|
|
128
|
-
|
|
129
|
-
it('returns the correct value for an interval including another interval', () => {
|
|
130
|
-
const includingIntervalStart = new Date(2016, 10, 5);
|
|
131
|
-
const includingIntervalEnd = new Date(2016, 11, 15);
|
|
132
|
-
|
|
133
|
-
const numOverlappingDays = getOverlappingDaysInIntervals(
|
|
134
|
-
{ start: initialIntervalStart, end: initialIntervalEnd },
|
|
135
|
-
{ start: includingIntervalStart, end: includingIntervalEnd },
|
|
136
|
-
);
|
|
137
|
-
expect(numOverlappingDays).toBe(24);
|
|
138
|
-
});
|
|
139
|
-
|
|
140
|
-
it('considers equal 0-lenght intervals not overlapping', () => {
|
|
141
|
-
const date = new Date(2016, 10, 15);
|
|
142
|
-
const numOverlappingDays = getOverlappingDaysInIntervals({ start: date, end: date }, { start: date, end: date });
|
|
143
|
-
expect(numOverlappingDays).toBe(0);
|
|
144
|
-
});
|
|
145
|
-
|
|
146
|
-
it('considers equal 1ms-length intervals overlapping', () => {
|
|
147
|
-
const start = new Date(2016, 10, 15);
|
|
148
|
-
const end = new Date(2016, 10, 15, 0, 0, 0, 1);
|
|
149
|
-
const numOverlappingDays = getOverlappingDaysInIntervals({ start, end }, { start, end });
|
|
150
|
-
expect(numOverlappingDays).toBe(1);
|
|
151
|
-
});
|
|
152
|
-
});
|
|
153
|
-
|
|
154
|
-
it('accepts a timestamp', () => {
|
|
155
|
-
const initialIntervalStart = new Date(2016, 10, 10, 13, 0, 0).getTime();
|
|
156
|
-
const initialIntervalEnd = new Date(2016, 11, 3, 15, 0, 0).getTime();
|
|
157
|
-
|
|
158
|
-
const endOverlappingIntervalStart = new Date(2016, 10, 5).getTime();
|
|
159
|
-
const endOverlappingIntervalEnd = new Date(2016, 10, 14).getTime();
|
|
160
|
-
|
|
161
|
-
const numOverlappingDays = getOverlappingDaysInIntervals(
|
|
162
|
-
{ start: initialIntervalStart, end: initialIntervalEnd },
|
|
163
|
-
{ start: endOverlappingIntervalStart, end: endOverlappingIntervalEnd },
|
|
164
|
-
);
|
|
165
|
-
expect(numOverlappingDays).toBe(4);
|
|
166
|
-
});
|
|
167
|
-
|
|
168
|
-
it('normalizes the left interval if its start date is after the end date', () => {
|
|
169
|
-
const initialIntervalStart = new Date(2016, 10, 10, 13, 0, 0);
|
|
170
|
-
const initialIntervalEnd = new Date(2016, 11, 3, 15, 0, 0);
|
|
171
|
-
|
|
172
|
-
const endOverlappingIntervalStart = new Date(2016, 10, 5);
|
|
173
|
-
const endOverlappingIntervalEnd = new Date(2016, 10, 14);
|
|
174
|
-
|
|
175
|
-
const numOverlappingDays = getOverlappingDaysInIntervals(
|
|
176
|
-
{ start: initialIntervalEnd, end: initialIntervalStart },
|
|
177
|
-
{ start: endOverlappingIntervalStart, end: endOverlappingIntervalEnd },
|
|
178
|
-
);
|
|
179
|
-
expect(numOverlappingDays).toBe(4);
|
|
180
|
-
});
|
|
181
|
-
|
|
182
|
-
it('normalizes the right interval if its start date is after the end date', () => {
|
|
183
|
-
const initialIntervalStart = new Date(2016, 10, 10, 13, 0, 0);
|
|
184
|
-
const initialIntervalEnd = new Date(2016, 11, 3, 15, 0, 0);
|
|
185
|
-
|
|
186
|
-
const endOverlappingIntervalStart = new Date(2016, 10, 5);
|
|
187
|
-
const endOverlappingIntervalEnd = new Date(2016, 10, 14);
|
|
188
|
-
|
|
189
|
-
const numOverlappingDays = getOverlappingDaysInIntervals(
|
|
190
|
-
{ start: initialIntervalStart, end: initialIntervalEnd },
|
|
191
|
-
{ start: endOverlappingIntervalEnd, end: endOverlappingIntervalStart },
|
|
192
|
-
);
|
|
193
|
-
expect(numOverlappingDays).toBe(4);
|
|
194
|
-
});
|
|
195
|
-
|
|
196
|
-
describe('one of the dates is `Invalid Date`', () => {
|
|
197
|
-
it('returns 0 if the start date of the initial time interval is `Invalid Date`', () => {
|
|
198
|
-
const numOverlappingDays = getOverlappingDaysInIntervals(
|
|
199
|
-
{ start: new Date(NaN), end: new Date(2016, 10, 3) },
|
|
200
|
-
{ start: new Date(2016, 10, 5), end: new Date(2016, 10, 15) },
|
|
201
|
-
);
|
|
202
|
-
expect(numOverlappingDays).toBe(0);
|
|
203
|
-
});
|
|
204
|
-
|
|
205
|
-
it('throws an exception if the end date of the initial time interval is `Invalid Date`', () => {
|
|
206
|
-
const numOverlappingDays = getOverlappingDaysInIntervals(
|
|
207
|
-
{ start: new Date(2016, 10, 3), end: new Date(NaN) },
|
|
208
|
-
{ start: new Date(2016, 10, 5), end: new Date(2016, 10, 15) },
|
|
209
|
-
);
|
|
210
|
-
expect(numOverlappingDays).toBe(0);
|
|
211
|
-
});
|
|
212
|
-
|
|
213
|
-
it('returns 0 if the start date of the compared time interval is `Invalid Date`', () => {
|
|
214
|
-
const numOverlappingDays = getOverlappingDaysInIntervals(
|
|
215
|
-
{ start: new Date(2016, 10, 3), end: new Date(2016, 10, 7) },
|
|
216
|
-
{ start: new Date(NaN), end: new Date(2016, 10, 5) },
|
|
217
|
-
);
|
|
218
|
-
expect(numOverlappingDays).toBe(0);
|
|
219
|
-
});
|
|
220
|
-
|
|
221
|
-
it('returns 0 if the end date of the compared time interval is `Invalid Date`', () => {
|
|
222
|
-
const numOverlappingDays = getOverlappingDaysInIntervals(
|
|
223
|
-
{ start: new Date(2016, 10, 3), end: new Date(2016, 10, 7) },
|
|
224
|
-
{ start: new Date(2016, 10, 5), end: new Date(NaN) },
|
|
225
|
-
);
|
|
226
|
-
expect(numOverlappingDays).toBe(0);
|
|
227
|
-
});
|
|
228
|
-
});
|
|
229
|
-
|
|
230
|
-
it('properly sorts the dates', () => {
|
|
231
|
-
const result = getOverlappingDaysInIntervals(
|
|
232
|
-
{
|
|
233
|
-
start: new Date(2001, 8 /* Sep */, 1, 16),
|
|
234
|
-
end: new Date(2023, 11 /* Dec */, 20, 16),
|
|
235
|
-
},
|
|
236
|
-
{
|
|
237
|
-
start: new Date(2023, 11 /* Dec */, 21, 16),
|
|
238
|
-
end: new Date(2001, 8 /* Sep */, 9, 16),
|
|
239
|
-
},
|
|
240
|
-
);
|
|
241
|
-
expect(result).toBe(8137);
|
|
242
|
-
});
|
|
243
|
-
});
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from 'vitest';
|
|
2
|
-
import { getQuarter } from './index';
|
|
3
|
-
|
|
4
|
-
describe('getQuarter', () => {
|
|
5
|
-
it('returns the quarter of the given date', () => {
|
|
6
|
-
const result = getQuarter(new Date(2014, 6 /* Jul */, 2));
|
|
7
|
-
expect(result).toBe(3);
|
|
8
|
-
});
|
|
9
|
-
|
|
10
|
-
it('accepts a timestamp', () => {
|
|
11
|
-
const result = getQuarter(new Date(2014, 3 /* Apr */, 2).getTime());
|
|
12
|
-
expect(result).toBe(2);
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
it('returns NaN if the given date is invalid', () => {
|
|
16
|
-
const result = getQuarter(new Date(NaN));
|
|
17
|
-
expect(isNaN(result)).toBe(true);
|
|
18
|
-
});
|
|
19
|
-
});
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from 'vitest';
|
|
2
|
-
import { getSeconds } from './index';
|
|
3
|
-
|
|
4
|
-
describe('getSeconds', () => {
|
|
5
|
-
it('returns the seconds of the given date', () => {
|
|
6
|
-
const result = getSeconds(new Date(2012, 1 /* Feb */, 29, 11, 45, 5, 123));
|
|
7
|
-
expect(result).toBe(5);
|
|
8
|
-
});
|
|
9
|
-
|
|
10
|
-
it('accepts a timestamp', () => {
|
|
11
|
-
const result = getSeconds(new Date(2014, 3 /* Apr */, 2, 23, 30, 42).getTime());
|
|
12
|
-
expect(result).toBe(42);
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
it('returns NaN if the given date is invalid', () => {
|
|
16
|
-
const result = getSeconds(new Date(NaN));
|
|
17
|
-
expect(isNaN(result)).toBe(true);
|
|
18
|
-
});
|
|
19
|
-
});
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from 'vitest';
|
|
2
|
-
import { getTime } from './index';
|
|
3
|
-
|
|
4
|
-
describe('getTime', () => {
|
|
5
|
-
it('returns the timestamp of the given date', () => {
|
|
6
|
-
const timestamp = 1483228800000;
|
|
7
|
-
const result = getTime(new Date(timestamp));
|
|
8
|
-
expect(result).toBe(timestamp);
|
|
9
|
-
});
|
|
10
|
-
|
|
11
|
-
it('accepts a timestamp (and returns it unchanged)', () => {
|
|
12
|
-
const timestamp = 804643200000;
|
|
13
|
-
const result = getTime(timestamp);
|
|
14
|
-
expect(result).toBe(timestamp);
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
it('returns NaN if the given date is invalid', () => {
|
|
18
|
-
const result = getTime(new Date(NaN));
|
|
19
|
-
expect(isNaN(result)).toBe(true);
|
|
20
|
-
});
|
|
21
|
-
});
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from 'vitest';
|
|
2
|
-
import { getUnixTime } from './index';
|
|
3
|
-
|
|
4
|
-
describe('getUnixTime', () => {
|
|
5
|
-
it('returns the timestamp of the given date', () => {
|
|
6
|
-
const timestamp = 1483228800000;
|
|
7
|
-
const result = getUnixTime(new Date(timestamp));
|
|
8
|
-
expect(result).toBe(1483228800);
|
|
9
|
-
});
|
|
10
|
-
|
|
11
|
-
it('accepts a timestamp (and returns it unchanged)', () => {
|
|
12
|
-
const timestamp = 804643200000;
|
|
13
|
-
const result = getUnixTime(timestamp);
|
|
14
|
-
expect(result).toBe(804643200);
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
it('returns NaN if the given date is invalid', () => {
|
|
18
|
-
const result = getUnixTime(new Date(NaN));
|
|
19
|
-
expect(isNaN(result)).toBe(true);
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
it('seconds timestamp handles negative numbers', () => {
|
|
23
|
-
expect(getUnixTime(new Date(1001))).toBe(1);
|
|
24
|
-
expect(getUnixTime(new Date(-1001))).toBe(-1);
|
|
25
|
-
});
|
|
26
|
-
});
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from 'vitest';
|
|
2
|
-
import { getWeek } from './index';
|
|
3
|
-
|
|
4
|
-
describe('getWeek', () => {
|
|
5
|
-
it('returns the local week of year of the given date', () => {
|
|
6
|
-
const result = getWeek(new Date(2005, 0 /* Jan */, 2));
|
|
7
|
-
expect(result).toBe(2);
|
|
8
|
-
});
|
|
9
|
-
|
|
10
|
-
it('accepts a timestamp', () => {
|
|
11
|
-
const result = getWeek(new Date(2008, 11 /* Dec */, 29).getTime());
|
|
12
|
-
expect(result).toBe(1);
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
it('handles dates before 100 AD', () => {
|
|
16
|
-
const initialDate = new Date(0);
|
|
17
|
-
initialDate.setFullYear(7, 11 /* Dec */, 30);
|
|
18
|
-
initialDate.setHours(0, 0, 0, 0);
|
|
19
|
-
const result = getWeek(initialDate);
|
|
20
|
-
expect(result).toBe(1);
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
it('properly works with negative numbers', () => {
|
|
24
|
-
expect(getWeek(new Date(2005, 0 /* Jan */, 4))).toBe(2);
|
|
25
|
-
// Calendars repeat every 400 years
|
|
26
|
-
expect(getWeek(new Date(395, 0 /* Jan */, 4))).toBe(1);
|
|
27
|
-
expect(getWeek(new Date(-2005, 0 /* Jan */, 4))).toBe(1);
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
it('returns NaN if the given date is invalid', () => {
|
|
31
|
-
const result = getWeek(new Date(NaN));
|
|
32
|
-
expect(isNaN(result)).toBe(true);
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
it('allows to specify `weekStartsOn` and `firstWeekContainsDate` in locale', () => {
|
|
36
|
-
const date = new Date(2005, 0 /* Jan */, 2);
|
|
37
|
-
const result = getWeek(date, {
|
|
38
|
-
locale: {
|
|
39
|
-
options: { weekStartsOn: 1, firstWeekContainsDate: 4 },
|
|
40
|
-
},
|
|
41
|
-
});
|
|
42
|
-
expect(result).toBe(53);
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
it('`options.weekStartsOn` overwrites the first day of the week specified in locale', () => {
|
|
46
|
-
const date = new Date(2005, 0 /* Jan */, 2);
|
|
47
|
-
const result = getWeek(date, {
|
|
48
|
-
weekStartsOn: 1,
|
|
49
|
-
firstWeekContainsDate: 4,
|
|
50
|
-
locale: {
|
|
51
|
-
options: { weekStartsOn: 0, firstWeekContainsDate: 1 },
|
|
52
|
-
},
|
|
53
|
-
});
|
|
54
|
-
expect(result).toBe(53);
|
|
55
|
-
});
|
|
56
|
-
});
|
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from 'vitest';
|
|
2
|
-
import { getWeekOfMonth } from './index';
|
|
3
|
-
|
|
4
|
-
describe('getWeekOfMonth', () => {
|
|
5
|
-
it('returns the week of the month of the given date', () => {
|
|
6
|
-
const result = getWeekOfMonth(new Date(2017, 10 /* Nov */, 15));
|
|
7
|
-
expect(result).toBe(3);
|
|
8
|
-
});
|
|
9
|
-
|
|
10
|
-
describe('edge cases', () => {
|
|
11
|
-
describe('when the given day is the first of a month', () => {
|
|
12
|
-
it('returns the week of the month of the given date', () => {
|
|
13
|
-
const result = getWeekOfMonth(new Date(2017, 10 /* Nov */, 1));
|
|
14
|
-
expect(result).toBe(1);
|
|
15
|
-
});
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
describe('when the given day is the last of a month #1', () => {
|
|
19
|
-
it('returns the week of the month of the given date', () => {
|
|
20
|
-
const result = getWeekOfMonth(new Date(2017, 10 /* Nov */, 30));
|
|
21
|
-
expect(result).toBe(5);
|
|
22
|
-
});
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
describe('when the given day is the last of a month #2', () => {
|
|
26
|
-
it('returns the week of the month of the given date', () => {
|
|
27
|
-
const result = getWeekOfMonth(new Date(2017, 9 /* Oct */, 31));
|
|
28
|
-
expect(result).toBe(5);
|
|
29
|
-
});
|
|
30
|
-
});
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
it('allows to specify which day is the first day of the week', () => {
|
|
34
|
-
const result = getWeekOfMonth(new Date(2017, 9 /* Oct */, 1), {
|
|
35
|
-
weekStartsOn: 1,
|
|
36
|
-
});
|
|
37
|
-
expect(result).toBe(1);
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
it('allows to specify which day is the first day of the week in locale', () => {
|
|
41
|
-
const result = getWeekOfMonth(new Date(2017, 9 /* Oct */, 31), {
|
|
42
|
-
locale: {
|
|
43
|
-
options: { weekStartsOn: 1 },
|
|
44
|
-
},
|
|
45
|
-
});
|
|
46
|
-
expect(result).toBe(6);
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
it('`options.weekStartsOn` overwrites the first day of the week specified in locale', () => {
|
|
50
|
-
const result = getWeekOfMonth(new Date(2017, 10 /* Nov */, 13), {
|
|
51
|
-
weekStartsOn: 1,
|
|
52
|
-
locale: {
|
|
53
|
-
options: { weekStartsOn: 0 },
|
|
54
|
-
},
|
|
55
|
-
});
|
|
56
|
-
expect(result).toBe(3);
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
it('accepts a timestamp', () => {
|
|
60
|
-
const result = getWeekOfMonth(new Date(2017, 10 /* Nov */, 1).getTime());
|
|
61
|
-
expect(result).toBe(1);
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
it('returns NaN if the given date is invalid', () => {
|
|
65
|
-
const result = getWeekOfMonth(new Date(NaN));
|
|
66
|
-
expect(isNaN(result)).toBe(true);
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
it('returns the week of the month of the given date, when the given date is sunday', () => {
|
|
70
|
-
const result = getWeekOfMonth(new Date(2019, 4 /* May */, 5), {
|
|
71
|
-
weekStartsOn: 1,
|
|
72
|
-
});
|
|
73
|
-
expect(result).toBe(1);
|
|
74
|
-
});
|
|
75
|
-
});
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from 'vitest';
|
|
2
|
-
import { getWeekYear } from './index';
|
|
3
|
-
|
|
4
|
-
describe('getWeekYear', () => {
|
|
5
|
-
it('returns the local week-numbering year of the given date', () => {
|
|
6
|
-
const result = getWeekYear(new Date(2004, 11 /* Dec */, 26));
|
|
7
|
-
expect(result).toBe(2005);
|
|
8
|
-
});
|
|
9
|
-
|
|
10
|
-
it('accepts a timestamp', () => {
|
|
11
|
-
const result = getWeekYear(new Date(2000, 11 /* Dec */, 30).getTime());
|
|
12
|
-
expect(result).toBe(2000);
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
it('handles dates before 100 AD', () => {
|
|
16
|
-
const initialDate = new Date(0);
|
|
17
|
-
initialDate.setFullYear(7, 11 /* Dec */, 31);
|
|
18
|
-
initialDate.setHours(0, 0, 0, 0);
|
|
19
|
-
const result = getWeekYear(initialDate);
|
|
20
|
-
expect(result).toBe(8);
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
it('returns NaN if the given date is invalid', () => {
|
|
24
|
-
const result = getWeekYear(new Date(NaN));
|
|
25
|
-
expect(isNaN(result)).toBe(true);
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
it('allows to specify `weekStartsOn` and `firstWeekContainsDate` in locale', () => {
|
|
29
|
-
const date = new Date(2004, 11 /* Dec */, 26);
|
|
30
|
-
const result = getWeekYear(date, {
|
|
31
|
-
locale: {
|
|
32
|
-
options: { weekStartsOn: 1, firstWeekContainsDate: 4 },
|
|
33
|
-
},
|
|
34
|
-
});
|
|
35
|
-
expect(result).toBe(2004);
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
it('`options.weekStartsOn` overwrites the first day of the week specified in locale', () => {
|
|
39
|
-
const date = new Date(2004, 11 /* Dec */, 26);
|
|
40
|
-
const result = getWeekYear(date, {
|
|
41
|
-
weekStartsOn: 1,
|
|
42
|
-
firstWeekContainsDate: 4,
|
|
43
|
-
locale: {
|
|
44
|
-
options: { weekStartsOn: 0, firstWeekContainsDate: 1 },
|
|
45
|
-
},
|
|
46
|
-
});
|
|
47
|
-
expect(result).toBe(2004);
|
|
48
|
-
});
|
|
49
|
-
});
|