@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,75 +0,0 @@
1
- import { describe, expect, it } from 'vitest';
2
- import { formatISODuration } from './index';
3
- import { intervalToDuration } from '../intervalToDuration/index';
4
-
5
- describe('formatISODuration', () => {
6
- it('Everything 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 = formatISODuration(intervalToDuration({ start, end }));
10
-
11
- expect(result).toBe('P39Y2M20DT7H5M0S');
12
- });
13
- it('Everything returns P1Y1M1DT1H1M1S (1 of everything)', () => {
14
- const start = new Date(2020, 2, 1, 12, 0, 0);
15
- const end = new Date(2021, 3, 2, 13, 1, 1);
16
- const result = formatISODuration(intervalToDuration({ start, end }));
17
-
18
- expect(result).toBe('P1Y1M1DT1H1M1S');
19
- });
20
- it('Returns P0Y0M0DT0H0M0S when the dates are the same', () => {
21
- const start = new Date(2020, 2, 1, 12, 0, 0);
22
- const end = new Date(2020, 2, 1, 12, 0, 0);
23
- const result = formatISODuration(intervalToDuration({ start, end }));
24
-
25
- expect(result).toBe('P0Y0M0DT0H0M0S');
26
- });
27
- it('Seconds returns P0Y0M0DT0H0M1S (1 second)', () => {
28
- const start = new Date(2020, 2, 1, 12, 0, 0);
29
- const end = new Date(2020, 2, 1, 12, 0, 1);
30
- const result = formatISODuration(intervalToDuration({ start, end }));
31
-
32
- expect(result).toBe('P0Y0M0DT0H0M1S');
33
- });
34
- it('Minutes returns P0Y0M0DT0H1M0S (1 minute)', () => {
35
- const start = new Date(2020, 2, 1, 12, 0, 0);
36
- const end = new Date(2020, 2, 1, 12, 1, 0);
37
- const result = formatISODuration(intervalToDuration({ start, end }));
38
-
39
- expect(result).toBe('P0Y0M0DT0H1M0S');
40
- });
41
- it('Hours returns P0Y0M0DT1H0M0S (1 hour)', () => {
42
- const start = new Date(2020, 2, 1, 12, 0, 0);
43
- const end = new Date(2020, 2, 1, 13, 0, 0);
44
- const result = formatISODuration(intervalToDuration({ start, end }));
45
-
46
- expect(result).toBe('P0Y0M0DT1H0M0S');
47
- });
48
- it('Days returns P0Y0M1DT0H0M0S (1 day)', () => {
49
- const start = new Date(2020, 2, 1, 12, 0, 0);
50
- const end = new Date(2020, 2, 2, 12, 0, 0);
51
- const result = formatISODuration(intervalToDuration({ start, end }));
52
-
53
- expect(result).toBe('P0Y0M1DT0H0M0S');
54
- });
55
- it('Months returns P0Y1M0DT0H0M0S (1 month)', () => {
56
- const start = new Date(2020, 2, 1, 12, 0, 0);
57
- const end = new Date(2020, 3, 1, 12, 0, 0);
58
- const result = formatISODuration(intervalToDuration({ start, end }));
59
-
60
- expect(result).toBe('P0Y1M0DT0H0M0S');
61
- });
62
- it('Years returns P1Y0M0DT0H0M1S (1 year)', () => {
63
- const start = new Date(2020, 2, 1, 12, 0, 0);
64
- const end = new Date(2021, 2, 1, 12, 0, 0);
65
- const result = formatISODuration(intervalToDuration({ start, end }));
66
-
67
- expect(result).toBe('P1Y0M0DT0H0M0S');
68
- });
69
-
70
- it('returns P0Y0M0DT0H0M0S when given an empty object', () => {
71
- const result = formatISODuration({});
72
-
73
- expect(result).toBe('P0Y0M0DT0H0M0S');
74
- });
75
- });
@@ -1,41 +0,0 @@
1
- import { describe, expect, it } from 'vitest';
2
- import sinon from 'sinon';
3
- import { formatRFC3339 } from './index';
4
- import { generateOffset } from '../_lib/test/index';
5
-
6
- describe('formatRFC3339', () => {
7
- it('formats RFC-3339 date string', () => {
8
- const date = new Date(2019, 2 /* Mar */, 3, 19, 0, 52, 123);
9
- expect(formatRFC3339(date)).toBe(`2019-03-03T19:00:52${generateOffset(date)}`);
10
-
11
- const getTimezoneOffsetStub = sinon.stub(Date.prototype, 'getTimezoneOffset');
12
-
13
- getTimezoneOffsetStub.returns(0);
14
- expect(formatRFC3339(date)).toBe('2019-03-03T19:00:52Z');
15
-
16
- getTimezoneOffsetStub.returns(480);
17
- expect(formatRFC3339(date)).toBe('2019-03-03T19:00:52-08:00');
18
-
19
- getTimezoneOffsetStub.restore();
20
- });
21
-
22
- it('accepts a timestamp', () => {
23
- const date = new Date(2019, 9 /* Oct */, 4, 12, 30, 13, 456);
24
- const time = date.getTime();
25
- expect(formatRFC3339(time)).toBe(`2019-10-04T12:30:13${generateOffset(date)}`);
26
- });
27
-
28
- it('allows to specify digits of second fractions', () => {
29
- const date = new Date(2019, 11 /* Dec */, 11, 1, 0, 0, 789);
30
- expect(formatRFC3339(date, { fractionDigits: 3 })).toBe(`2019-12-11T01:00:00.789${generateOffset(date)}`);
31
- });
32
-
33
- it('works when ms < 100', () => {
34
- const date = new Date(2019, 11 /* Dec */, 11, 1, 0, 0, 12);
35
- expect(formatRFC3339(date, { fractionDigits: 2 })).toBe(`2019-12-11T01:00:00.01${generateOffset(date)}`);
36
- });
37
-
38
- it('throws RangeError if the time value is invalid', () => {
39
- expect(formatRFC3339.bind(null, new Date(NaN))).toThrow(RangeError);
40
- });
41
- });
@@ -1,18 +0,0 @@
1
- import { describe, expect, it } from 'vitest';
2
- import { formatRFC7231 } from './index';
3
-
4
- describe('formatRFC7231', () => {
5
- it('formats RFC-7231 date string', () => {
6
- const date = new Date(Date.UTC(2019, 2, 3, 19, 0, 52));
7
- expect(formatRFC7231(date)).toBe('Sun, 03 Mar 2019 19:00:52 GMT');
8
- });
9
-
10
- it('accepts a timestamp', () => {
11
- const date = Date.UTC(2019, 9, 4, 12, 30, 13);
12
- expect(formatRFC7231(date)).toBe('Fri, 04 Oct 2019 12:30:13 GMT');
13
- });
14
-
15
- it('throws RangeError if the time value is invalid', () => {
16
- expect(formatRFC7231.bind(null, new Date(NaN))).toThrow(RangeError);
17
- });
18
- });
@@ -1,92 +0,0 @@
1
- import { describe, expect, it } from 'vitest';
2
- import { formatRelative } from './index';
3
-
4
- describe('formatRelative', () => {
5
- const baseDate = new Date(1986, 3 /* Apr */, 4, 10, 32, 0, 900);
6
-
7
- it('accepts a timestamp', () => {
8
- const date = new Date(2014, 3 /* Apr */, 4);
9
- expect(formatRelative(date.getTime(), baseDate.getTime())).toBe('04/04/2014');
10
- });
11
-
12
- it('before the last week', () => {
13
- const result = formatRelative(new Date(1986, 2 /* Mar */, 28, 16, 50), baseDate);
14
- expect(result).toBe('03/28/1986');
15
- });
16
-
17
- it('last week', () => {
18
- const result = formatRelative(new Date(1986, 3 /* Apr */, 1), baseDate);
19
- expect(result).toBe('last Tuesday at 12:00 AM');
20
- });
21
-
22
- it('yesterday', () => {
23
- const result = formatRelative(new Date(1986, 3 /* Apr */, 3, 22, 22), baseDate);
24
- expect(result).toBe('yesterday at 10:22 PM');
25
- });
26
-
27
- it('today', () => {
28
- const result = formatRelative(new Date(1986, 3 /* Apr */, 4, 16, 50), baseDate);
29
- expect(result).toBe('today at 4:50 PM');
30
- });
31
-
32
- it('tomorrow', () => {
33
- const result = formatRelative(new Date(1986, 3 /* Apr */, 5, 7, 30), baseDate);
34
- expect(result).toBe('tomorrow at 7:30 AM');
35
- });
36
-
37
- it('next week', () => {
38
- const result = formatRelative(new Date(1986, 3 /* Apr */, 6, 12, 0), baseDate);
39
- expect(result).toBe('Sunday at 12:00 PM');
40
- });
41
-
42
- it('after the next week', () => {
43
- const result = formatRelative(new Date(1986, 3 /* Apr */, 11, 16, 50), baseDate);
44
- expect(result).toBe('04/11/1986');
45
- });
46
-
47
- describe('edge cases', () => {
48
- it("throws RangeError if the date isn't valid", () => {
49
- expect(formatRelative.bind(null, new Date(NaN), baseDate)).toThrow(RangeError);
50
- });
51
-
52
- it("throws RangeError if the base date isn't valid", () => {
53
- expect(formatRelative.bind(null, new Date(2017, 0 /* Jan */, 1), new Date(NaN))).toThrow(RangeError);
54
- });
55
-
56
- it("throws RangeError if both dates aren't valid", () => {
57
- expect(formatRelative.bind(null, new Date(NaN), new Date(NaN))).toThrow(RangeError);
58
- });
59
-
60
- it('handles dates before 100 AD', () => {
61
- const date = new Date(0);
62
- date.setFullYear(7, 11 /* Dec */, 31);
63
- date.setHours(0, 0, 0, 0);
64
- expect(formatRelative(date, baseDate)).toBe('12/31/0007');
65
- });
66
- });
67
-
68
- describe('custom locale', () => {
69
- it('allows to pass a custom locale', () => {
70
- const customLocale = {
71
- localize: {
72
- month: () => {
73
- return 'works';
74
- },
75
- },
76
- formatLong: {
77
- date: () => {
78
- return "'It' MMMM";
79
- },
80
- },
81
- formatRelative: () => {
82
- return "P 'perfectly!'";
83
- },
84
- };
85
- const result = formatRelative(new Date(1986, 2 /* Mar */, 28, 16, 50), baseDate, {
86
- // @ts-expect-error - It's ok to have incomplete locale
87
- locale: customLocale,
88
- });
89
- expect(result).toBe('It works perfectly!');
90
- });
91
- });
92
- });
@@ -1,114 +0,0 @@
1
- import { pipe } from 'fp-ts/function';
2
- import { flow as jsFnsFlow } from 'js-fns';
3
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment -- Lodash types trip in different environemnts, so we can't put ts-expect-error
4
- // @ts-ignore - Lodash types are tripping ("Module '"lodash"' has no exported member 'flow'.ts(2305)")
5
- import { flow as lodashFlow } from 'lodash';
6
- import { describe, expect, it } from 'vitest';
7
- import { addDays, addHours, isEqual } from '../../index';
8
- import { convertToFP } from './index';
9
-
10
- describe('convertToFP', () => {
11
- function fn(a: unknown, b: unknown, c: unknown) {
12
- return 'a b c'.replace('a', String(a)).replace('b', String(b)).replace('c', String(c));
13
- }
14
-
15
- describe('arity of converted function === arity of initial function', () => {
16
- it('allows arguments to be curried (and reverses their order)', () => {
17
- const fpFn = convertToFP(fn, 3);
18
- expect(fpFn(3)(2)(1)).toBe('1 2 3');
19
- });
20
-
21
- it('allows to group arguments', () => {
22
- const fpFn = convertToFP(fn, 3);
23
- expect(fpFn(3, 2)(1)).toBe('1 2 3');
24
- expect(fpFn(3)(2, 1)).toBe('1 2 3');
25
- });
26
-
27
- it('allows the function to be called with all arguments in the reversed order', () => {
28
- const fpFn = convertToFP(fn, 3);
29
- expect(fpFn(3, 2, 1)).toBe('1 2 3');
30
- });
31
-
32
- it('ignores calls without curried arguments', () => {
33
- const fpFn = convertToFP(fn, 3);
34
- expect(fpFn()()(3, 2)()()(1)).toBe('1 2 3');
35
- });
36
-
37
- it('ignores extra curried arguments in the last group', () => {
38
- const fpFn = convertToFP(fn, 3);
39
- // @ts-expect-error - It's ok, we're testing the function
40
- expect(fpFn(3, 2, 1, 0, -1, -2)).toBe('1 2 3');
41
- // @ts-expect-error - It's ok, we're testing the function
42
- expect(fpFn(3)(2)(1, 0, -1, -2)).toBe('1 2 3');
43
- });
44
- });
45
-
46
- describe('arity of converted function < arity of initial function', () => {
47
- it('calls the initial function with a short list of arguments', () => {
48
- const fpFn = convertToFP(fn, 2);
49
- expect(fpFn(2)(1)).toBe('1 2 undefined');
50
- expect(fpFn(2, 1)).toBe('1 2 undefined');
51
- });
52
-
53
- it('ignores extra curried arguments in the last group', () => {
54
- const fpFn = convertToFP(fn, 2);
55
- // @ts-expect-error - It's ok, we're testing the function
56
- expect(fpFn(3)(2, 1)).toBe('2 3 undefined');
57
- // @ts-expect-error - It's ok, we're testing the function
58
- expect(fpFn(3, 2, 1)).toBe('2 3 undefined');
59
- });
60
- });
61
-
62
- describe('arity of converted function > arity of initial function', () => {
63
- it('works, but ignores the extra arguments', () => {
64
- const fpFn = convertToFP(fn, 4);
65
- // @ts-expect-error - It's ok, we're testing the function
66
- expect(fpFn(4)(3)(2)(1)).toBe('1 2 3');
67
- // @ts-expect-error - It's ok, we're testing the function
68
- expect(fpFn(4, 3, 2, 1)).toBe('1 2 3');
69
- });
70
- });
71
-
72
- describe('arity of converted function === 0', () => {
73
- it('returns the constant instead of function', () => {
74
- // @ts-expect-error - It's ok, we're testing the function
75
- const result = convertToFP(fn, 0);
76
- expect(result).toBe('undefined undefined undefined');
77
- });
78
- });
79
-
80
- describe('types', () => {
81
- it('resolves proper types', () => {
82
- const fn1 = addDays();
83
- const fn2 = fn1(1);
84
- const result = fn2(new Date(1987, 1));
85
- expect(result.getFullYear()).toBe(1987);
86
- });
87
- });
88
-
89
- describe('Lodash', () => {
90
- it('works with flow', () => {
91
- const fn = lodashFlow(addDays(1), addHours(1));
92
- const result = fn(new Date(1987, 1, 11));
93
- expect(result.getFullYear()).toBe(1987);
94
- expect(result).toEqual(new Date(1987, 1, 12, 1));
95
- });
96
- });
97
-
98
- describe('fp-ts', () => {
99
- it('works with pipe', () => {
100
- const result = pipe(new Date(1987, 1, 11), isEqual(new Date(1987, 1, 11)));
101
- const _assign: boolean = result;
102
- expect(result).toBe(true);
103
- });
104
- });
105
-
106
- describe('js-fns', () => {
107
- it('works with flow', () => {
108
- const fn = jsFnsFlow(addDays(1), addHours(1));
109
- const result = fn(new Date(1987, 1, 11));
110
- expect(result.getFullYear()).toBe(1987);
111
- expect(result).toEqual(new Date(1987, 1, 12, 1));
112
- });
113
- });
114
- });
@@ -1,14 +0,0 @@
1
- import { describe, expect, it } from 'vitest';
2
- import { fromUnixTime } from './index';
3
-
4
- describe('fromUnixTime', () => {
5
- it('returns the date derived from the given UNIX timestamp', () => {
6
- const result = fromUnixTime(1330515499);
7
- expect(result.getTime()).toBe(1330515499000);
8
- });
9
-
10
- it('returns invalid if the given timestamp is invalid', () => {
11
- const result = fromUnixTime(NaN);
12
- expect(isNaN(result.getTime())).toBe(true);
13
- });
14
- });
@@ -1,19 +0,0 @@
1
- import { describe, expect, it } from 'vitest';
2
- import { getDate } from './index';
3
-
4
- describe('getDate', () => {
5
- it('returns the day of the month of the given date', () => {
6
- const result = getDate(new Date(2012, 1 /* Feb */, 29));
7
- expect(result).toBe(29);
8
- });
9
-
10
- it('accepts a timestamp', () => {
11
- const result = getDate(new Date(2014, 11 /* Dec */, 31).getTime());
12
- expect(result).toBe(31);
13
- });
14
-
15
- it('returns NaN if the given date is invalid', () => {
16
- const result = getDate(new Date(NaN));
17
- expect(isNaN(result)).toBe(true);
18
- });
19
- });
@@ -1,19 +0,0 @@
1
- import { describe, expect, it } from 'vitest';
2
- import { getDay } from './index';
3
-
4
- describe('getDay', () => {
5
- it('returns the day of the week of the given date', () => {
6
- const result = getDay(new Date(2012, 1 /* Feb */, 29));
7
- expect(result).toBe(3);
8
- });
9
-
10
- it('accepts a timestamp', () => {
11
- const result = getDay(new Date(2014, 5 /* Jun */, 1).getTime());
12
- expect(result).toBe(0);
13
- });
14
-
15
- it('returns NaN if the given date is invalid', () => {
16
- const result = getDay(new Date(NaN));
17
- expect(isNaN(result)).toBe(true);
18
- });
19
- });
@@ -1,27 +0,0 @@
1
- import { describe, expect, it } from 'vitest';
2
- import { getDayOfYear } from './index';
3
-
4
- describe('getDayOfYear', () => {
5
- it('returns the day of the year of the given date', () => {
6
- const result = getDayOfYear(new Date(2014, 6 /* Jul */, 2));
7
- expect(result).toBe(183);
8
- });
9
-
10
- it('accepts a timestamp', () => {
11
- const result = getDayOfYear(new Date(2014, 0 /* Jan */, 2).getTime());
12
- expect(result).toBe(2);
13
- });
14
-
15
- it('handles dates before 100 AD', () => {
16
- const initialDate = new Date(0);
17
- initialDate.setFullYear(0, 11 /* Dec */, 31);
18
- initialDate.setHours(0, 0, 0, 0);
19
- const result = getDayOfYear(initialDate);
20
- expect(result).toBe(366);
21
- });
22
-
23
- it('returns NaN if the given date is invalid', () => {
24
- const result = getDayOfYear(new Date(NaN));
25
- expect(isNaN(result)).toBe(true);
26
- });
27
- });
@@ -1,33 +0,0 @@
1
- import { describe, expect, it } from 'vitest';
2
- import { getDaysInMonth } from './index';
3
-
4
- describe('getDaysInMonth', () => {
5
- it('returns the number of days in the month of the given date', () => {
6
- const result = getDaysInMonth(new Date(2100, 1 /* Feb */, 11));
7
- expect(result).toBe(28);
8
- });
9
-
10
- it('works for the February of a leap year', () => {
11
- const result = getDaysInMonth(new Date(2000, 1 /* Feb */, 11));
12
- expect(result).toBe(29);
13
- });
14
-
15
- it('accepts a timestamp', () => {
16
- const date = new Date(2014, 6 /* Jul */, 2).getTime();
17
- const result = getDaysInMonth(date);
18
- expect(result).toBe(31);
19
- });
20
-
21
- it('handles dates before 100 AD', () => {
22
- const date = new Date(0);
23
- date.setFullYear(0, 1 /* Feb */, 15);
24
- date.setHours(0, 0, 0, 0);
25
- const result = getDaysInMonth(date);
26
- expect(result).toBe(29);
27
- });
28
-
29
- it('returns NaN if the given date is invalid', () => {
30
- const result = getDaysInMonth(new Date(NaN));
31
- expect(isNaN(result)).toBe(true);
32
- });
33
- });
@@ -1,35 +0,0 @@
1
- import { describe, expect, it } from 'vitest';
2
- import { getDaysInYear } from './index';
3
-
4
- describe('getDaysInYear', () => {
5
- it('returns the number of days in the year of the given date', () => {
6
- const result = getDaysInYear(new Date(2014, 6 /* Jul */, 2));
7
- expect(result).toBe(365);
8
- });
9
-
10
- it('works for a leap year', () => {
11
- const result = getDaysInYear(new Date(2012, 6 /* Jul */, 2));
12
- expect(result).toBe(366);
13
- });
14
-
15
- it('works for the years divisible by 100 but not by 400', () => {
16
- const result = getDaysInYear(new Date(2100, 6 /* Jul */, 2));
17
- expect(result).toBe(365);
18
- });
19
-
20
- it('works for the years divisible by 400', () => {
21
- const result = getDaysInYear(new Date(2000, 6 /* Jul */, 2));
22
- expect(result).toBe(366);
23
- });
24
-
25
- it('accepts a timestamp', () => {
26
- const date = new Date(2012, 6 /* Jul */, 2).getTime();
27
- const result = getDaysInYear(date);
28
- expect(result).toBe(366);
29
- });
30
-
31
- it('returns NaN if the given date is invalid', () => {
32
- const result = getDaysInYear(new Date(NaN));
33
- expect(isNaN(result)).toBe(true);
34
- });
35
- });
@@ -1,24 +0,0 @@
1
- import { describe, expect, it } from 'vitest';
2
- import { getDecade } from './index';
3
-
4
- describe('getDecade', () => {
5
- it('returns the decade for a the given date', () => {
6
- const result = getDecade(new Date(1971, 10 /* Nov */, 8));
7
- expect(result).toBe(1970);
8
- });
9
-
10
- it('accepts a timestamp', () => {
11
- const result = getDecade(new Date(1969, 6 /* Jul */, 20).getTime());
12
- expect(result).toBe(1960);
13
- });
14
-
15
- it('returns NaN if the given date is invalid', () => {
16
- const result = getDecade(new Date(NaN));
17
- expect(isNaN(result)).toBe(true);
18
- });
19
-
20
- it('properly works with negative numbers', () => {
21
- expect(getDecade(new Date(2009, 0, 1))).toBe(2000);
22
- expect(getDecade(new Date(-2001, 0, 1))).toBe(-2010);
23
- });
24
- });
@@ -1,58 +0,0 @@
1
- import { afterEach, beforeAll, describe, expect, it } from 'vitest';
2
- import { getDefaultOptions } from './index';
3
- import { setDefaultOptions } from '../setDefaultOptions/index';
4
- import { startOfWeek } from '../startOfWeek/index';
5
- import {
6
- getDefaultOptions as getInternalDefaultOptions,
7
- setDefaultOptions as setInternalDefaultOptions,
8
- } from '../_lib/defaultOptions/index';
9
- import { resetDefaultOptions } from '../_lib/test/index';
10
- import { Locale } from '../types';
11
-
12
- describe.skip('getDefaultOptions', () => {
13
- afterEach(resetDefaultOptions);
14
-
15
- let eo: Locale;
16
- beforeAll(async () => {
17
- // @ts-expect-error
18
- ({ eo } = await import('../locale/eo/index'));
19
- });
20
-
21
- it('returns an empty object', () => {
22
- const result = getDefaultOptions();
23
- expect(result).toEqual({});
24
- });
25
-
26
- it('returns a clone of the original object', () => {
27
- setInternalDefaultOptions({ weekStartsOn: 1 });
28
- const result = getDefaultOptions();
29
- expect(getInternalDefaultOptions()).toEqual(result);
30
- });
31
-
32
- it('mutating the result does not affect functions that use options', () => {
33
- const defaultOptionsClone = getDefaultOptions();
34
- defaultOptionsClone.weekStartsOn = 1;
35
- const result = startOfWeek(new Date(2014, 8 /* Sep */, 2, 11, 55, 0));
36
- expect(result).toEqual(new Date(2014, 7 /* Aug */, 31));
37
-
38
- // Mutating the original object does affect `startOfWeek`
39
- const _defaultOptions = getInternalDefaultOptions();
40
- _defaultOptions.weekStartsOn = 1;
41
- const result2 = startOfWeek(new Date(2014, 8 /* Sep */, 2, 11, 55, 0));
42
- expect(result2).toEqual(new Date(2014, 8 /* Sep */, 1));
43
- });
44
-
45
- it('returns new values after setting them via `setDefaultOptions`', () => {
46
- setDefaultOptions({
47
- weekStartsOn: 1,
48
- firstWeekContainsDate: 4,
49
- locale: eo,
50
- });
51
- const result = getDefaultOptions();
52
- expect(result).toEqual({
53
- weekStartsOn: 1,
54
- firstWeekContainsDate: 4,
55
- locale: eo,
56
- });
57
- });
58
- });
@@ -1,19 +0,0 @@
1
- import { describe, expect, it } from 'vitest';
2
- import { getHours } from './index';
3
-
4
- describe('getHours', () => {
5
- it('returns the hours of the given date', () => {
6
- const result = getHours(new Date(2012, 1 /* Feb */, 29, 11, 45));
7
- expect(result).toBe(11);
8
- });
9
-
10
- it('accepts a timestamp', () => {
11
- const result = getHours(new Date(2014, 3 /* Apr */, 2, 23, 30).getTime());
12
- expect(result).toBe(23);
13
- });
14
-
15
- it('returns NaN if the given date is invalid', () => {
16
- const result = getHours(new Date(NaN));
17
- expect(isNaN(result)).toBe(true);
18
- });
19
- });
@@ -1,24 +0,0 @@
1
- import { describe, expect, it } from 'vitest';
2
- import { getISODay } from './index';
3
-
4
- describe('getISODay', () => {
5
- it('returns the day of the ISO week of the given date', () => {
6
- const result = getISODay(new Date(2012, 1 /* Feb */, 29));
7
- expect(result).toBe(3);
8
- });
9
-
10
- it('returns 7 if the given day is Sunday', () => {
11
- const result = getISODay(new Date(2014, 5 /* Jun */, 1));
12
- expect(result).toBe(7);
13
- });
14
-
15
- it('accepts a timestamp', () => {
16
- const result = getISODay(new Date(2014, 5 /* Jun */, 1).getTime());
17
- expect(result).toBe(7);
18
- });
19
-
20
- it('returns NaN if the given date is invalid', () => {
21
- const result = getISODay(new Date(NaN));
22
- expect(isNaN(result)).toBe(true);
23
- });
24
- });
@@ -1,54 +0,0 @@
1
- import { describe, expect, it } from 'vitest';
2
- import { getISOWeek } from './index';
3
-
4
- describe('getISOWeek', () => {
5
- it('returns the ISO week of the given date', () => {
6
- const result = getISOWeek(new Date(2005, 0 /* Jan */, 2));
7
- expect(result).toBe(53);
8
- });
9
-
10
- it('accepts a timestamp', () => {
11
- const result = getISOWeek(new Date(2008, 11 /* Dec */, 29).getTime());
12
- expect(result).toBe(1);
13
- });
14
-
15
- describe('edge cases', () => {
16
- it('returns the ISO week at 1 January 2016', () => {
17
- const result = getISOWeek(new Date(2016, 0 /* Jan */, 1));
18
- expect(result).toBe(53);
19
- });
20
-
21
- it('returns the ISO week at 1 May 2016', () => {
22
- const result = getISOWeek(new Date(2016, 4 /* May */, 1));
23
- expect(result).toBe(17);
24
- });
25
-
26
- it('returns the ISO week at 2 May 2016', () => {
27
- const result = getISOWeek(new Date(2016, 4 /* May */, 2));
28
- expect(result).toBe(18);
29
- });
30
-
31
- it('returns the ISO week at 31 May 2016', () => {
32
- const result = getISOWeek(new Date(2016, 4 /* May */, 31));
33
- expect(result).toBe(22);
34
- });
35
-
36
- it('properly works with negative numbers', () => {
37
- expect(getISOWeek(new Date(2014, 6 /* Jul */, 14))).toBe(29);
38
- expect(getISOWeek(new Date(-2014, 6 /* Jul */, 14))).toBe(29);
39
- });
40
- });
41
-
42
- it('handles dates before 100 AD', () => {
43
- const initialDate = new Date(0);
44
- initialDate.setFullYear(7, 11 /* Dec */, 30);
45
- initialDate.setHours(0, 0, 0, 0);
46
- const result = getISOWeek(initialDate);
47
- expect(result).toBe(52);
48
- });
49
-
50
- it('returns NaN if the given date is invalid', () => {
51
- const result = getISOWeek(new Date(NaN));
52
- expect(isNaN(result)).toBe(true);
53
- });
54
- });