@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.
Files changed (250) hide show
  1. package/README.md +0 -2
  2. package/package.json +1 -1
  3. package/src/date-fns/_lib/addLeadingZeros/test.mts +0 -12
  4. package/src/date-fns/_lib/getRoundingMethod/test.mts +0 -50
  5. package/src/date-fns/_lib/getTimezoneOffsetInMilliseconds/test.mts +0 -25
  6. package/src/date-fns/add/test.mts +0 -95
  7. package/src/date-fns/addBusinessDays/test.mts +0 -78
  8. package/src/date-fns/addDays/test.mts +0 -90
  9. package/src/date-fns/addHours/test.mts +0 -30
  10. package/src/date-fns/addISOWeekYears/test.mts +0 -41
  11. package/src/date-fns/addMilliseconds/test.mts +0 -30
  12. package/src/date-fns/addMinutes/test.mts +0 -30
  13. package/src/date-fns/addMonths/test.mts +0 -123
  14. package/src/date-fns/addQuarters/test.mts +0 -47
  15. package/src/date-fns/addSeconds/test.mts +0 -30
  16. package/src/date-fns/addWeeks/test.mts +0 -30
  17. package/src/date-fns/addYears/test.mts +0 -46
  18. package/src/date-fns/areIntervalsOverlapping/test.mts +0 -231
  19. package/src/date-fns/clamp/test.mts +0 -36
  20. package/src/date-fns/closestIndexTo/test.mts +0 -51
  21. package/src/date-fns/closestTo/test.mts +0 -49
  22. package/src/date-fns/compareAsc/test.mts +0 -58
  23. package/src/date-fns/compareDesc/test.mts +0 -58
  24. package/src/date-fns/constructFrom/test.mts +0 -47
  25. package/src/date-fns/constructNow/test.mts +0 -37
  26. package/src/date-fns/daysToWeeks/test.mts +0 -36
  27. package/src/date-fns/differenceInBusinessDays/test.mts +0 -102
  28. package/src/date-fns/differenceInCalendarDays/test.mts +0 -206
  29. package/src/date-fns/differenceInCalendarISOWeekYears/test.mts +0 -93
  30. package/src/date-fns/differenceInCalendarISOWeeks/test.mts +0 -89
  31. package/src/date-fns/differenceInCalendarMonths/test.mts +0 -82
  32. package/src/date-fns/differenceInCalendarQuarters/test.mts +0 -82
  33. package/src/date-fns/differenceInCalendarWeeks/test.mts +0 -136
  34. package/src/date-fns/differenceInCalendarYears/test.mts +0 -82
  35. package/src/date-fns/differenceInDays/test.mts +0 -175
  36. package/src/date-fns/differenceInHours/test.mts +0 -122
  37. package/src/date-fns/differenceInISOWeekYears/test.mts +0 -93
  38. package/src/date-fns/differenceInMilliseconds/test.mts +0 -53
  39. package/src/date-fns/differenceInMinutes/test.mts +0 -123
  40. package/src/date-fns/differenceInMonths/test.mts +0 -121
  41. package/src/date-fns/differenceInQuarters/test.mts +0 -109
  42. package/src/date-fns/differenceInSeconds/test.mts +0 -144
  43. package/src/date-fns/differenceInWeeks/test.mts +0 -111
  44. package/src/date-fns/differenceInYears/test.mts +0 -97
  45. package/src/date-fns/eachDayOfInterval/test.mts +0 -164
  46. package/src/date-fns/eachHourOfInterval/test.mts +0 -154
  47. package/src/date-fns/eachMinuteOfInterval/test.mts +0 -159
  48. package/src/date-fns/eachMonthOfInterval/test.mts +0 -151
  49. package/src/date-fns/eachQuarterOfInterval/test.mts +0 -136
  50. package/src/date-fns/eachWeekOfInterval/test.mts +0 -177
  51. package/src/date-fns/eachWeekendOfInterval/test.mts +0 -67
  52. package/src/date-fns/eachWeekendOfMonth/test.mts +0 -23
  53. package/src/date-fns/eachWeekendOfYear/test.mts +0 -18
  54. package/src/date-fns/eachYearOfInterval/test.mts +0 -136
  55. package/src/date-fns/endOfDay/test.mts +0 -27
  56. package/src/date-fns/endOfDecade/test.mts +0 -32
  57. package/src/date-fns/endOfHour/test.mts +0 -26
  58. package/src/date-fns/endOfISOWeek/test.mts +0 -27
  59. package/src/date-fns/endOfISOWeekYear/test.mts +0 -36
  60. package/src/date-fns/endOfMinute/test.mts +0 -26
  61. package/src/date-fns/endOfMonth/test.mts +0 -41
  62. package/src/date-fns/endOfQuarter/test.mts +0 -27
  63. package/src/date-fns/endOfSecond/test.mts +0 -26
  64. package/src/date-fns/endOfToday/test.mts +0 -19
  65. package/src/date-fns/endOfTomorrow/test.mts +0 -29
  66. package/src/date-fns/endOfWeek/test.mts +0 -86
  67. package/src/date-fns/endOfYear/test.mts +0 -27
  68. package/src/date-fns/endOfYesterday/test.mts +0 -29
  69. package/src/date-fns/format/test.mts +0 -909
  70. package/src/date-fns/formatDistance/test.mts +0 -189
  71. package/src/date-fns/formatDistanceStrict/test.mts +0 -329
  72. package/src/date-fns/formatDistanceToNow/test.mts +0 -196
  73. package/src/date-fns/formatDistanceToNowStrict/test.mts +0 -293
  74. package/src/date-fns/formatDuration/test.mts +0 -74
  75. package/src/date-fns/formatISO/test.mts +0 -55
  76. package/src/date-fns/formatISO9075/test.mts +0 -35
  77. package/src/date-fns/formatISODuration/test.mts +0 -75
  78. package/src/date-fns/formatRFC3339/test.mts +0 -41
  79. package/src/date-fns/formatRFC7231/test.mts +0 -18
  80. package/src/date-fns/formatRelative/test.mts +0 -92
  81. package/src/date-fns/fp/_lib/convertToFP/test.mts +0 -114
  82. package/src/date-fns/fromUnixTime/test.mts +0 -14
  83. package/src/date-fns/getDate/test.mts +0 -19
  84. package/src/date-fns/getDay/test.mts +0 -19
  85. package/src/date-fns/getDayOfYear/test.mts +0 -27
  86. package/src/date-fns/getDaysInMonth/test.mts +0 -33
  87. package/src/date-fns/getDaysInYear/test.mts +0 -35
  88. package/src/date-fns/getDecade/test.mts +0 -24
  89. package/src/date-fns/getDefaultOptions/test.mts +0 -58
  90. package/src/date-fns/getHours/test.mts +0 -19
  91. package/src/date-fns/getISODay/test.mts +0 -24
  92. package/src/date-fns/getISOWeek/test.mts +0 -54
  93. package/src/date-fns/getISOWeekYear/test.mts +0 -27
  94. package/src/date-fns/getISOWeeksInYear/test.mts +0 -37
  95. package/src/date-fns/getMilliseconds/test.mts +0 -19
  96. package/src/date-fns/getMinutes/test.mts +0 -19
  97. package/src/date-fns/getMonth/test.mts +0 -19
  98. package/src/date-fns/getOverlappingDaysInIntervals/test.mts +0 -243
  99. package/src/date-fns/getQuarter/test.mts +0 -19
  100. package/src/date-fns/getSeconds/test.mts +0 -19
  101. package/src/date-fns/getTime/test.mts +0 -21
  102. package/src/date-fns/getUnixTime/test.mts +0 -26
  103. package/src/date-fns/getWeek/test.mts +0 -56
  104. package/src/date-fns/getWeekOfMonth/test.mts +0 -75
  105. package/src/date-fns/getWeekYear/test.mts +0 -49
  106. package/src/date-fns/getWeeksInMonth/test.mts +0 -51
  107. package/src/date-fns/getYear/test.mts +0 -19
  108. package/src/date-fns/hoursToMilliseconds/test.mts +0 -23
  109. package/src/date-fns/hoursToMinutes/test.mts +0 -25
  110. package/src/date-fns/hoursToSeconds/test.mts +0 -25
  111. package/src/date-fns/interval/test.mts +0 -42
  112. package/src/date-fns/intervalToDuration/test.mts +0 -235
  113. package/src/date-fns/intlFormat/test.mts +0 -88
  114. package/src/date-fns/intlFormatDistance/test.mts +0 -588
  115. package/src/date-fns/isAfter/test.mts +0 -39
  116. package/src/date-fns/isBefore/test.mts +0 -39
  117. package/src/date-fns/isDate/test.mts +0 -72
  118. package/src/date-fns/isEqual/test.mts +0 -34
  119. package/src/date-fns/isExists/test.mts +0 -14
  120. package/src/date-fns/isFirstDayOfMonth/test.mts +0 -25
  121. package/src/date-fns/isFriday/test.mts +0 -24
  122. package/src/date-fns/isFuture/test.mts +0 -34
  123. package/src/date-fns/isLastDayOfMonth/test.mts +0 -25
  124. package/src/date-fns/isLeapYear/test.mts +0 -35
  125. package/src/date-fns/isMatch/test.mts +0 -27
  126. package/src/date-fns/isMonday/test.mts +0 -24
  127. package/src/date-fns/isPast/test.mts +0 -34
  128. package/src/date-fns/isSameDay/test.mts +0 -37
  129. package/src/date-fns/isSameHour/test.mts +0 -37
  130. package/src/date-fns/isSameISOWeek/test.mts +0 -34
  131. package/src/date-fns/isSameISOWeekYear/test.mts +0 -48
  132. package/src/date-fns/isSameMinute/test.mts +0 -37
  133. package/src/date-fns/isSameMonth/test.mts +0 -34
  134. package/src/date-fns/isSameQuarter/test.mts +0 -34
  135. package/src/date-fns/isSameSecond/test.mts +0 -43
  136. package/src/date-fns/isSameWeek/test.mts +0 -58
  137. package/src/date-fns/isSameYear/test.mts +0 -34
  138. package/src/date-fns/isSaturday/test.mts +0 -24
  139. package/src/date-fns/isSunday/test.mts +0 -24
  140. package/src/date-fns/isThisHour/test.mts +0 -34
  141. package/src/date-fns/isThisISOWeek/test.mts +0 -34
  142. package/src/date-fns/isThisMinute/test.mts +0 -34
  143. package/src/date-fns/isThisMonth/test.mts +0 -34
  144. package/src/date-fns/isThisQuarter/test.mts +0 -34
  145. package/src/date-fns/isThisSecond/test.mts +0 -34
  146. package/src/date-fns/isThisWeek/test.mts +0 -39
  147. package/src/date-fns/isThisYear/test.mts +0 -34
  148. package/src/date-fns/isThursday/test.mts +0 -24
  149. package/src/date-fns/isToday/test.mts +0 -34
  150. package/src/date-fns/isTomorrow/test.mts +0 -34
  151. package/src/date-fns/isTuesday/test.mts +0 -24
  152. package/src/date-fns/isValid/test.mts +0 -24
  153. package/src/date-fns/isWednesday/test.mts +0 -24
  154. package/src/date-fns/isWeekend/test.mts +0 -24
  155. package/src/date-fns/isWithinInterval/test.mts +0 -92
  156. package/src/date-fns/isYesterday/test.mts +0 -34
  157. package/src/date-fns/lastDayOfDecade/test.mts +0 -32
  158. package/src/date-fns/lastDayOfISOWeek/test.mts +0 -27
  159. package/src/date-fns/lastDayOfISOWeekYear/test.mts +0 -36
  160. package/src/date-fns/lastDayOfMonth/test.mts +0 -41
  161. package/src/date-fns/lastDayOfQuarter/test.mts +0 -27
  162. package/src/date-fns/lastDayOfWeek/test.mts +0 -86
  163. package/src/date-fns/lastDayOfYear/test.mts +0 -27
  164. package/src/date-fns/lightFormat/test.mts +0 -126
  165. package/src/date-fns/max/test.mts +0 -34
  166. package/src/date-fns/milliseconds/test.mts +0 -62
  167. package/src/date-fns/millisecondsToHours/test.mts +0 -24
  168. package/src/date-fns/millisecondsToMinutes/test.mts +0 -24
  169. package/src/date-fns/millisecondsToSeconds/test.mts +0 -24
  170. package/src/date-fns/min/test.mts +0 -34
  171. package/src/date-fns/minutesToHours/test.mts +0 -24
  172. package/src/date-fns/minutesToMilliseconds/test.mts +0 -23
  173. package/src/date-fns/minutesToSeconds/test.mts +0 -23
  174. package/src/date-fns/monthsToQuarters/test.mts +0 -24
  175. package/src/date-fns/monthsToYears/test.mts +0 -24
  176. package/src/date-fns/nextDay/test.mts +0 -44
  177. package/src/date-fns/nextFriday/test.mts +0 -24
  178. package/src/date-fns/nextMonday/test.mts +0 -24
  179. package/src/date-fns/nextSaturday/test.mts +0 -24
  180. package/src/date-fns/nextSunday/test.mts +0 -24
  181. package/src/date-fns/nextThursday/test.mts +0 -24
  182. package/src/date-fns/nextTuesday/test.mts +0 -23
  183. package/src/date-fns/nextWednesday/test.mts +0 -24
  184. package/src/date-fns/parse/test.mts +0 -2202
  185. package/src/date-fns/parseISO/test.mts +0 -362
  186. package/src/date-fns/parseJSON/test.mts +0 -129
  187. package/src/date-fns/previousDay/test.mts +0 -42
  188. package/src/date-fns/previousFriday/test.mts +0 -22
  189. package/src/date-fns/previousMonday/test.mts +0 -22
  190. package/src/date-fns/previousSaturday/test.mts +0 -22
  191. package/src/date-fns/previousSunday/test.mts +0 -22
  192. package/src/date-fns/previousThursday/test.mts +0 -22
  193. package/src/date-fns/previousTuesday/test.mts +0 -22
  194. package/src/date-fns/previousWednesday/test.mts +0 -22
  195. package/src/date-fns/quartersToMonths/test.mts +0 -24
  196. package/src/date-fns/quartersToYears/test.mts +0 -24
  197. package/src/date-fns/roundToNearestHours/test.mts +0 -200
  198. package/src/date-fns/roundToNearestMinutes/test.mts +0 -208
  199. package/src/date-fns/secondsToHours/test.mts +0 -24
  200. package/src/date-fns/secondsToMilliseconds/test.mts +0 -14
  201. package/src/date-fns/secondsToMinutes/test.mts +0 -24
  202. package/src/date-fns/set/test.mts +0 -121
  203. package/src/date-fns/setDate/test.mts +0 -30
  204. package/src/date-fns/setDay/test.mts +0 -112
  205. package/src/date-fns/setDayOfYear/test.mts +0 -30
  206. package/src/date-fns/setDefaultOptions/test.mts +0 -498
  207. package/src/date-fns/setHours/test.mts +0 -30
  208. package/src/date-fns/setISODay/test.mts +0 -59
  209. package/src/date-fns/setISOWeek/test.mts +0 -41
  210. package/src/date-fns/setISOWeekYear/test.mts +0 -50
  211. package/src/date-fns/setMilliseconds/test.mts +0 -30
  212. package/src/date-fns/setMinutes/test.mts +0 -30
  213. package/src/date-fns/setMonth/test.mts +0 -46
  214. package/src/date-fns/setQuarter/test.mts +0 -46
  215. package/src/date-fns/setSeconds/test.mts +0 -30
  216. package/src/date-fns/setWeek/test.mts +0 -63
  217. package/src/date-fns/setWeekYear/test.mts +0 -72
  218. package/src/date-fns/setYear/test.mts +0 -30
  219. package/src/date-fns/startOfDay/test.mts +0 -27
  220. package/src/date-fns/startOfDecade/test.mts +0 -32
  221. package/src/date-fns/startOfHour/test.mts +0 -27
  222. package/src/date-fns/startOfISOWeek/test.mts +0 -27
  223. package/src/date-fns/startOfISOWeekYear/test.mts +0 -41
  224. package/src/date-fns/startOfMinute/test.mts +0 -27
  225. package/src/date-fns/startOfMonth/test.mts +0 -27
  226. package/src/date-fns/startOfQuarter/test.mts +0 -27
  227. package/src/date-fns/startOfSecond/test.mts +0 -27
  228. package/src/date-fns/startOfToday/test.mts +0 -19
  229. package/src/date-fns/startOfTomorrow/test.mts +0 -29
  230. package/src/date-fns/startOfWeek/test.mts +0 -86
  231. package/src/date-fns/startOfWeekYear/test.mts +0 -58
  232. package/src/date-fns/startOfYear/test.mts +0 -38
  233. package/src/date-fns/startOfYesterday/test.mts +0 -29
  234. package/src/date-fns/sub/test.mts +0 -83
  235. package/src/date-fns/subBusinessDays/test.mts +0 -40
  236. package/src/date-fns/subDays/test.mts +0 -30
  237. package/src/date-fns/subHours/test.mts +0 -30
  238. package/src/date-fns/subISOWeekYears/test.mts +0 -41
  239. package/src/date-fns/subMilliseconds/test.mts +0 -30
  240. package/src/date-fns/subMinutes/test.mts +0 -30
  241. package/src/date-fns/subMonths/test.mts +0 -47
  242. package/src/date-fns/subQuarters/test.mts +0 -47
  243. package/src/date-fns/subSeconds/test.mts +0 -30
  244. package/src/date-fns/subWeeks/test.mts +0 -30
  245. package/src/date-fns/subYears/test.mts +0 -46
  246. package/src/date-fns/toDate/test.mts +0 -35
  247. package/src/date-fns/weeksToDays/test.mts +0 -24
  248. package/src/date-fns/yearsToDays/test.mts +0 -24
  249. package/src/date-fns/yearsToMonths/test.mts +0 -24
  250. package/src/date-fns/yearsToQuarters/test.mts +0 -24
@@ -1,51 +0,0 @@
1
- import { describe, expect, it } from 'vitest';
2
- import { getWeeksInMonth } from './index';
3
-
4
- describe('getWeeksInMonth', () => {
5
- it('returns the number of calendar weeks the month in the given date spans', () => {
6
- const result = getWeeksInMonth(new Date(2015, 1 /* Feb */, 8, 18, 0));
7
- expect(result).toBe(4);
8
- });
9
-
10
- it('allows to specify which day is the first day of the week', () => {
11
- const result = getWeeksInMonth(new Date(2015, 1 /* Feb */, 8, 18, 0), {
12
- weekStartsOn: 1,
13
- });
14
- expect(result).toBe(5);
15
- });
16
-
17
- it('allows to specify which day is the first day of the week in locale', () => {
18
- const result = getWeeksInMonth(new Date(2015, 1 /* Feb */, 8, 18, 0), {
19
- locale: {
20
- options: { weekStartsOn: 1 },
21
- },
22
- });
23
- expect(result).toBe(5);
24
- });
25
-
26
- it('`options.weekStartsOn` overwrites the first day of the week specified in locale', () => {
27
- const result = getWeeksInMonth(new Date(2015, 1 /* Feb */, 8, 18, 0), {
28
- weekStartsOn: 1,
29
- locale: {
30
- options: { weekStartsOn: 0 },
31
- },
32
- });
33
- expect(result).toBe(5);
34
- });
35
-
36
- it('accepts timestamps', () => {
37
- const result = getWeeksInMonth(new Date(2017, 3 /* Apr */, 8, 18, 0).getTime());
38
- expect(result).toBe(6);
39
- });
40
-
41
- it('does not mutate the original date', () => {
42
- const date = new Date(2014, 8 /* Sep */, 2, 11, 55, 0);
43
- getWeeksInMonth(date);
44
- expect(date).toEqual(new Date(2014, 8 /* Sep */, 2, 11, 55, 0));
45
- });
46
-
47
- it('returns NaN if the date is `Invalid Date`', () => {
48
- const result = getWeeksInMonth(new Date(NaN));
49
- expect(isNaN(result)).toBe(true);
50
- });
51
- });
@@ -1,19 +0,0 @@
1
- import { describe, expect, it } from 'vitest';
2
- import { getYear } from './index';
3
-
4
- describe('getYear', () => {
5
- it('returns the year of the given date', () => {
6
- const result = getYear(new Date(2014, 6 /* Jul */, 2));
7
- expect(result).toBe(2014);
8
- });
9
-
10
- it('accepts a timestamp', () => {
11
- const result = getYear(new Date(2000, 3 /* Apr */, 2).getTime());
12
- expect(result).toBe(2000);
13
- });
14
-
15
- it('returns NaN if the given date is invalid', () => {
16
- const result = getYear(new Date(NaN));
17
- expect(isNaN(result)).toBe(true);
18
- });
19
- });
@@ -1,23 +0,0 @@
1
- import { describe, expect, it } from 'vitest';
2
- import { hoursToMilliseconds } from './index';
3
-
4
- describe('hoursToMilliseconds', () => {
5
- it('converts hours to milliseconds', () => {
6
- expect(hoursToMilliseconds(1)).toBe(3600000);
7
- expect(hoursToMilliseconds(2)).toBe(7200000);
8
- });
9
-
10
- it('uses floor rounding', () => {
11
- expect(hoursToMilliseconds(0.123456)).toBe(444441);
12
- });
13
-
14
- it('handles border values', () => {
15
- expect(hoursToMilliseconds(1.5)).toBe(5400000);
16
- expect(hoursToMilliseconds(0)).toBe(0);
17
- });
18
-
19
- it('works with negative numbers properly', () => {
20
- expect(hoursToMilliseconds(1.234567)).toBe(4444441);
21
- expect(hoursToMilliseconds(-1.234567)).toBe(-4444441);
22
- });
23
- });
@@ -1,25 +0,0 @@
1
- import { describe, expect, it } from 'vitest';
2
- import { hoursToMinutes } from './index';
3
-
4
- describe('hoursToMinutes', () => {
5
- it('converts hours to minutes', () => {
6
- expect(hoursToMinutes(1)).toBe(60);
7
- expect(hoursToMinutes(2)).toBe(120);
8
- });
9
-
10
- it('uses floor rounding', () => {
11
- expect(hoursToMinutes(0.123)).toBe(7);
12
- });
13
-
14
- it('handles border values', () => {
15
- expect(hoursToMinutes(1.5)).toBe(90);
16
- expect(hoursToMinutes(0)).toBe(0);
17
- });
18
-
19
- it('properly works with negative numbers', () => {
20
- expect(hoursToMinutes(1.11)).toBe(66);
21
- expect(hoursToMinutes(1.44)).toBe(86);
22
- expect(hoursToMinutes(-1.11)).toBe(-66);
23
- expect(hoursToMinutes(-1.44)).toBe(-86);
24
- });
25
- });
@@ -1,25 +0,0 @@
1
- import { describe, expect, it } from 'vitest';
2
- import { hoursToSeconds } from './index';
3
-
4
- describe('hoursToSeconds', () => {
5
- it('converts hours to seconds', () => {
6
- expect(hoursToSeconds(1)).toBe(3600);
7
- expect(hoursToSeconds(2)).toBe(7200);
8
- });
9
-
10
- it('uses floor rounding', () => {
11
- expect(hoursToSeconds(0.123)).toBe(442);
12
- });
13
-
14
- it('handles border values', () => {
15
- expect(hoursToSeconds(1.5)).toBe(5400);
16
- expect(hoursToSeconds(0)).toBe(0);
17
- });
18
-
19
- it('properly works with negative numbers', () => {
20
- expect(hoursToSeconds(1.11)).toBe(3996);
21
- expect(hoursToSeconds(1.44)).toBe(5184);
22
- expect(hoursToSeconds(-1.11)).toBe(-3996);
23
- expect(hoursToSeconds(-1.44)).toBe(-5184);
24
- });
25
- });
@@ -1,42 +0,0 @@
1
- import { describe, expect, it } from 'vitest';
2
- import { interval } from './index';
3
-
4
- describe('Interval', () => {
5
- it('exposes start and end', () => {
6
- const result = interval(new Date(2000, 0), new Date(2023, 0));
7
- expect(result.start).toEqual(new Date(2000, 0));
8
- expect(result.end).toEqual(new Date(2023, 0));
9
- });
10
-
11
- it('normalizes the dates', () => {
12
- const result = interval(+new Date(2000, 0), new Date(2023, 0).toISOString());
13
- expect(result.start).toEqual(new Date(2000, 0));
14
- expect(result.end).toEqual(new Date(2023, 0));
15
- });
16
-
17
- it('throws an error if one of the arguments is invalid', () => {
18
- expect(() => {
19
- interval(new Date(2000, 0), new Date(NaN));
20
- }).toThrow(new TypeError('End date is invalid'));
21
-
22
- expect(() => {
23
- interval(new Date(NaN), new Date(2000, 0));
24
- }).toThrow(new TypeError('Start date is invalid'));
25
- });
26
-
27
- it('throws an error if the interval is not positive', () => {
28
- // Should be ok
29
- interval(new Date(2023, 0), new Date(2000, 0));
30
-
31
- expect(() => {
32
- interval(new Date(2023, 0), new Date(2000, 0), {
33
- assertPositive: true,
34
- });
35
- }).toThrow(new TypeError('End date must be after start date'));
36
-
37
- // Should be ok too
38
- interval(new Date(2000, 0), new Date(2000, 0), {
39
- assertPositive: true,
40
- });
41
- });
42
- });
@@ -1,235 +0,0 @@
1
- import { describe, expect, it } from 'vitest';
2
- import { intervalToDuration } from './index';
3
- import { addMonths } from '../addMonths/index';
4
-
5
- describe('intervalToDuration', () => {
6
- it('returns correct duration for arbitrary dates', () => {
7
- const start = new Date(1929, 0, 15, 12, 0, 0);
8
- const end = new Date(1968, 3, 4, 19, 5, 0);
9
- const result = intervalToDuration({ start, end });
10
-
11
- expect(result).toEqual({
12
- years: 39,
13
- months: 2,
14
- days: 20,
15
- hours: 7,
16
- minutes: 5,
17
- });
18
- });
19
-
20
- it('returns correct duration (1 of everything)', () => {
21
- const start = new Date(2020, 2, 1, 12, 0, 0);
22
- const end = new Date(2021, 3, 2, 13, 1, 1);
23
- const result = intervalToDuration({ start, end });
24
-
25
- expect(result).toEqual({
26
- years: 1,
27
- months: 1,
28
- days: 1,
29
- hours: 1,
30
- minutes: 1,
31
- seconds: 1,
32
- });
33
- });
34
-
35
- it('returns duration of 0 when the dates are the same', () => {
36
- const start = new Date(2020, 2, 1, 12, 0, 0);
37
- const end = new Date(2020, 2, 1, 12, 0, 0);
38
- const result = intervalToDuration({ start, end });
39
-
40
- expect(result).toEqual({});
41
- });
42
-
43
- it("returns a negative duration if interval's start date is greater than its end date", () => {
44
- const interval = {
45
- start: new Date(2020, 3, 1),
46
- end: new Date(2020, 2, 1),
47
- };
48
- const result = intervalToDuration(interval);
49
-
50
- expect(result).toEqual({ months: -1 });
51
- });
52
-
53
- it("returns an empty object if interval's start date invalid", () => {
54
- const interval = {
55
- start: new Date(NaN),
56
- end: new Date(2020, 0, 1),
57
- };
58
- const result = intervalToDuration(interval);
59
-
60
- expect(result).toEqual({});
61
- });
62
-
63
- it("returns an empty object if interval's end date invalid", () => {
64
- const interval = {
65
- start: new Date(2020, 0, 1),
66
- end: new Date(NaN),
67
- };
68
- const result = intervalToDuration(interval);
69
-
70
- expect(result).toEqual({});
71
- });
72
-
73
- describe('edge cases', () => {
74
- it('returns correct duration for dates in the end of Feb - issue 2255', () => {
75
- expect(
76
- intervalToDuration({
77
- start: new Date(2012, 1 /* Feb */, 28, 9, 0, 0),
78
- end: new Date(2012, 1 /* Feb */, 29, 10, 0, 0),
79
- }),
80
- ).toEqual({
81
- days: 1,
82
- hours: 1,
83
- });
84
-
85
- expect(
86
- intervalToDuration({
87
- start: new Date(2012, 1 /* Feb */, 29, 9, 0, 0),
88
- end: new Date(2012, 1 /* Feb */, 29, 10, 0, 0),
89
- }),
90
- ).toEqual({
91
- hours: 1,
92
- });
93
-
94
- expect(
95
- intervalToDuration({
96
- start: new Date(2012, 1 /* Feb */, 28, 9, 0, 0),
97
- end: new Date(2012, 1 /* Feb */, 28, 10, 0, 0),
98
- }),
99
- ).toEqual({
100
- hours: 1,
101
- });
102
-
103
- // Issue 2261
104
- expect(
105
- intervalToDuration({
106
- start: new Date(2021, 1 /* Feb */, 28, 7, 23, 7),
107
- end: new Date(2021, 1 /* Feb */, 28, 7, 38, 18),
108
- }),
109
- ).toEqual({
110
- minutes: 15,
111
- seconds: 11,
112
- });
113
- });
114
-
115
- it('returns correct duration for end of month start dates - issue 2611', () => {
116
- const start = new Date(2021, 7, 31);
117
- const end = addMonths(start, 1);
118
-
119
- expect(end).toEqual(new Date(2021, 8, 30));
120
-
121
- const duration = intervalToDuration({ start, end });
122
- const expectedDuration = {
123
- months: 1,
124
- };
125
-
126
- expect(duration).toEqual(expectedDuration);
127
- });
128
-
129
- it('returns correct duration for Feb 29 on leap year + 1 month - issue 1778', () => {
130
- const duration = intervalToDuration({
131
- start: new Date(2020, 1, 29),
132
- end: new Date(2020, 2, 29),
133
- });
134
- const expectedDuration = {
135
- months: 1,
136
- };
137
-
138
- expect(duration).toEqual(expectedDuration);
139
- });
140
-
141
- it('returns correct duration for Feb 28 to Apr 30 interval - issue 2910', () => {
142
- const duration = intervalToDuration({
143
- start: new Date(2022, 1, 28),
144
- end: new Date(2022, 3, 30),
145
- });
146
- const expectedDuration = {
147
- months: 2,
148
- days: 2,
149
- };
150
-
151
- expect(duration).toEqual(expectedDuration);
152
- });
153
-
154
- describe('issue 2470', () => {
155
- it('returns correct duration for Feb 28 to Aug 31 interval', () => {
156
- const duration = intervalToDuration({
157
- start: new Date(2021, 1, 28),
158
- end: new Date(2021, 7, 31),
159
- });
160
- const expectedDuration = {
161
- months: 6,
162
- days: 3,
163
- };
164
-
165
- expect(duration).toEqual(expectedDuration);
166
- });
167
-
168
- it('returns correct duration for Feb 28 to Aug 30 interval', () => {
169
- const duration = intervalToDuration({
170
- start: new Date(2021, 1, 28),
171
- end: new Date(2021, 7, 30),
172
- });
173
- const expectedDuration = {
174
- months: 6,
175
- days: 2,
176
- };
177
-
178
- expect(duration).toEqual(expectedDuration);
179
- });
180
-
181
- it('returns correct duration for Feb 28 to Aug 29 interval', () => {
182
- const duration = intervalToDuration({
183
- start: new Date(2021, 1, 28),
184
- end: new Date(2021, 7, 29),
185
- });
186
- const expectedDuration = {
187
- months: 6,
188
- days: 1,
189
- };
190
-
191
- expect(duration).toEqual(expectedDuration);
192
- });
193
-
194
- it('returns correct duration for Feb 28 to Aug 28 interval', () => {
195
- const duration = intervalToDuration({
196
- start: new Date(2021, 1, 28),
197
- end: new Date(2021, 7, 28),
198
- });
199
- const expectedDuration = {
200
- months: 6,
201
- };
202
-
203
- expect(duration).toEqual(expectedDuration);
204
- });
205
-
206
- it('returns correct duration for Feb 28 to Aug 27 interval', () => {
207
- // Feb 28 to July 28 is 5 months, July 28 to Aug 27 is 30 days
208
-
209
- const duration = intervalToDuration({
210
- start: new Date(2021, 1, 28),
211
- end: new Date(2021, 7, 27),
212
- });
213
- const expectedDuration = {
214
- months: 5,
215
- days: 30,
216
- };
217
-
218
- expect(duration).toEqual(expectedDuration);
219
- });
220
-
221
- it('returns correct duration for Apr 30 to May 31 interval', () => {
222
- const duration = intervalToDuration({
223
- start: new Date(2021, 3, 30),
224
- end: new Date(2021, 4, 31),
225
- });
226
- const expectedDuration = {
227
- months: 1,
228
- days: 1,
229
- };
230
-
231
- expect(duration).toEqual(expectedDuration);
232
- });
233
- });
234
- });
235
- });
@@ -1,88 +0,0 @@
1
- import { describe, expect, it } from 'vitest';
2
- import { intlFormat } from './index';
3
-
4
- // Before Node version 13.0.0, only the locale data for en-US is available by default.
5
- const hasFullICU = () => {
6
- try {
7
- const january = new Date(9e8);
8
- const spanish = new Intl.DateTimeFormat('es', { month: 'long' });
9
- return spanish.format(january) === 'enero';
10
- } catch (err) {
11
- return false;
12
- }
13
- };
14
-
15
- const fullICUOnly = hasFullICU() ? it : it.skip;
16
-
17
- const getOperationSystemLocale = () => {
18
- // https://stackoverflow.com/questions/46072248/node-js-how-to-detect-user-language/46072415
19
- return Intl.DateTimeFormat().resolvedOptions().locale;
20
- };
21
-
22
- describe('intlFormat', () => {
23
- describe('formats date', () => {
24
- fullICUOnly("should work without format's options and locale's options", () => {
25
- const date = new Date(2019, 9 /* Oct */, 4, 12, 30, 13, 456);
26
- const result = intlFormat(date);
27
- const localeResult = intlFormat(date, {
28
- locale: getOperationSystemLocale(),
29
- });
30
-
31
- expect(result).toBe(localeResult);
32
- });
33
-
34
- fullICUOnly("should work with only format's options", () => {
35
- const date = new Date(2019, 9 /* Oct */, 4, 12, 30, 13, 456);
36
- const formatOptions: Intl.DateTimeFormatOptions = {
37
- year: 'numeric',
38
- month: 'numeric',
39
- day: 'numeric',
40
- hour: 'numeric',
41
- minute: 'numeric',
42
- second: 'numeric',
43
- hour12: false,
44
- timeZone: 'America/Los_Angeles',
45
- };
46
-
47
- const result = intlFormat(date, formatOptions);
48
- const localeResult = intlFormat(date, formatOptions, {
49
- locale: getOperationSystemLocale(),
50
- });
51
-
52
- expect(result).toBe(localeResult);
53
- });
54
-
55
- fullICUOnly("should work with only locale's options", () => {
56
- const date = new Date(2019, 9 /* Oct */, 4, 12, 30, 13, 456);
57
- // Korean uses year-month-day order
58
- const localeOptions = {
59
- locale: 'ko-KR',
60
- };
61
-
62
- const result = intlFormat(date, localeOptions);
63
-
64
- expect(result).toBe('2019. 10. 4.');
65
- });
66
-
67
- fullICUOnly("should work with format's options and locale's options", () => {
68
- const date = new Date(2019, 9 /* Oct */, 4, 12, 30, 13, 456);
69
- const formatOptions: Intl.DateTimeFormatOptions = {
70
- weekday: 'long',
71
- year: 'numeric',
72
- month: 'long',
73
- day: 'numeric',
74
- };
75
- const localeOptions = {
76
- locale: 'de-DE',
77
- };
78
-
79
- const result = intlFormat(date, formatOptions, localeOptions);
80
-
81
- expect(result).toBe('Freitag, 4. Oktober 2019');
82
- });
83
- });
84
-
85
- it('throws RangeError if the date value is invalid', () => {
86
- expect(() => intlFormat(new Date(NaN))).toThrow(RangeError);
87
- });
88
- });