@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,196 +0,0 @@
1
- import { UTCDate } from '@date-fns/utc';
2
- import sinon from 'sinon';
3
- import { afterEach, beforeEach, describe, expect, it } from 'vitest';
4
- import type { FormatDistanceFn } from '../locale/types';
5
- import { formatDistanceToNow } from './index';
6
-
7
- describe('formatDistanceToNow', () => {
8
- let clock: sinon.SinonFakeTimers;
9
- beforeEach(() => {
10
- clock = sinon.useFakeTimers(new Date(1986, 3, 4, 10, 32, 0).getTime());
11
- });
12
-
13
- afterEach(() => {
14
- clock.restore();
15
- });
16
-
17
- describe('seconds', () => {
18
- describe('when the includeSeconds option is true', () => {
19
- it('less than 5 seconds', () => {
20
- const result = formatDistanceToNow(new Date(1986, 3, 4, 10, 31, 58), {
21
- includeSeconds: true,
22
- });
23
- expect(result).toBe('less than 5 seconds');
24
- });
25
-
26
- it('less than 10 seconds', () => {
27
- const result = formatDistanceToNow(new Date(1986, 3, 4, 10, 31, 52), {
28
- includeSeconds: true,
29
- });
30
- expect(result).toBe('less than 10 seconds');
31
- });
32
-
33
- it('less than 20 seconds', () => {
34
- const result = formatDistanceToNow(new Date(1986, 3, 4, 10, 31, 45), {
35
- includeSeconds: true,
36
- });
37
- expect(result).toBe('less than 20 seconds');
38
- });
39
-
40
- it('half a minute', () => {
41
- const result = formatDistanceToNow(new Date(1986, 3, 4, 10, 31, 35), {
42
- includeSeconds: true,
43
- });
44
- expect(result).toBe('half a minute');
45
- });
46
-
47
- it('less than a minute', () => {
48
- const result = formatDistanceToNow(new Date(1986, 3, 4, 10, 31, 15), {
49
- includeSeconds: true,
50
- });
51
- expect(result).toBe('less than a minute');
52
- });
53
-
54
- it('1 minute', () => {
55
- const result = formatDistanceToNow(new Date(1986, 3, 4, 10, 31, 0), {
56
- includeSeconds: true,
57
- });
58
- expect(result).toBe('1 minute');
59
- });
60
- });
61
- });
62
-
63
- describe('minutes', () => {
64
- it('less than a minute', () => {
65
- const result = formatDistanceToNow(new Date(1986, 3, 4, 10, 31, 40));
66
- expect(result).toBe('less than a minute');
67
- });
68
-
69
- it('1 minute', () => {
70
- const result = formatDistanceToNow(new Date(1986, 3, 4, 10, 31, 10));
71
- expect(result).toBe('1 minute');
72
- });
73
-
74
- it('n minutes', () => {
75
- const result = formatDistanceToNow(new Date(1986, 3, 4, 10, 29, 10));
76
- expect(result).toBe('3 minutes');
77
- });
78
- });
79
-
80
- describe('hours', () => {
81
- it('about 1 hour', () => {
82
- const result = formatDistanceToNow(new Date(1986, 3, 4, 9, 32, 0));
83
- expect(result).toBe('about 1 hour');
84
- });
85
-
86
- it('about n hours', () => {
87
- const result = formatDistanceToNow(new Date(1986, 3, 4, 7, 32, 0));
88
- expect(result).toBe('about 3 hours');
89
- });
90
- });
91
-
92
- describe('days', () => {
93
- it('1 day', () => {
94
- const result = formatDistanceToNow(new Date(1986, 3, 3, 10, 32, 0));
95
- expect(result).toBe('1 day');
96
- });
97
-
98
- it('n days', () => {
99
- const result = formatDistanceToNow(new Date(1986, 3, 1, 10, 32, 0));
100
- expect(result).toBe('3 days');
101
- });
102
- });
103
-
104
- describe('months', () => {
105
- it('about 1 month', () => {
106
- const result = formatDistanceToNow(new Date(1986, 2, 4, 10, 32, 0));
107
- expect(result).toBe('about 1 month');
108
- });
109
-
110
- it('n months', () => {
111
- const result = formatDistanceToNow(new Date(1986, 0, 4, 10, 32, 0));
112
- expect(result).toBe('3 months');
113
- });
114
- });
115
-
116
- describe('years', () => {
117
- it('about 1 year', () => {
118
- const result = formatDistanceToNow(new Date(1985, 3, 4, 10, 32, 0));
119
- expect(result).toBe('about 1 year');
120
- });
121
-
122
- it('over 1 year', () => {
123
- const result = formatDistanceToNow(new Date(1984, 10, 4, 10, 32, 0));
124
- expect(result).toBe('over 1 year');
125
- });
126
-
127
- it('almost n years', () => {
128
- const result = formatDistanceToNow(new Date(1983, 4, 4, 10, 32, 0));
129
- expect(result).toBe('almost 3 years');
130
- });
131
-
132
- it('about n years', () => {
133
- const result = formatDistanceToNow(new Date(1983, 3, 4, 10, 32, 0));
134
- expect(result).toBe('about 3 years');
135
- });
136
-
137
- it('over n years', () => {
138
- const result = formatDistanceToNow(new Date(1982, 10, 4, 10, 32, 0));
139
- expect(result).toBe('over 3 years');
140
- });
141
- });
142
-
143
- it('accepts a timestamp', () => {
144
- const result = formatDistanceToNow(new Date(1986, 3, 4, 10, 31, 40).getTime());
145
- expect(result).toBe('less than a minute');
146
- });
147
-
148
- describe('when the addSuffix option is true', () => {
149
- it('adds a past suffix', () => {
150
- const result = formatDistanceToNow(new Date(1986, 3, 4, 10, 31, 35), {
151
- includeSeconds: true,
152
- addSuffix: true,
153
- });
154
- expect(result).toBe('half a minute ago');
155
- });
156
-
157
- it('adds a future suffix', () => {
158
- const result = formatDistanceToNow(new Date(1986, 3, 4, 11, 32, 0), {
159
- addSuffix: true,
160
- });
161
- expect(result).toBe('in about 1 hour');
162
- });
163
- });
164
-
165
- describe('custom locale', () => {
166
- it('can be passed to the function', () => {
167
- const localizeDistance: FormatDistanceFn = (token, count, options) => {
168
- expect(token).toBe('aboutXHours');
169
- expect(count).toBe(1);
170
- expect(options!.addSuffix).toBe(true);
171
- expect(options!.comparison!).toBeGreaterThan(0);
172
- return 'It works!';
173
- };
174
-
175
- const customLocale = {
176
- formatDistance: localizeDistance,
177
- };
178
-
179
- const result = formatDistanceToNow(new Date(1986, 3, 4, 11, 32, 0), {
180
- addSuffix: true,
181
- locale: customLocale,
182
- });
183
-
184
- expect(result).toBe('It works!');
185
- });
186
- });
187
-
188
- it('throws RangeError if the passed date is `Invalid Date`', function () {
189
- expect(formatDistanceToNow.bind(null, new Date(NaN))).toThrow(RangeError);
190
- });
191
-
192
- it('respects date extensions', () => {
193
- const result = formatDistanceToNow(new UTCDate(+new Date(1986, 3, 4, 9, 32, 0)));
194
- expect(result).toBe('about 1 hour');
195
- });
196
- });
@@ -1,293 +0,0 @@
1
- import { UTCDate } from '@date-fns/utc';
2
- import sinon from 'sinon';
3
- import { afterEach, beforeEach, describe, expect, it } from 'vitest';
4
- import type { FormatDistanceFn } from '../locale/types';
5
- import { formatDistanceToNowStrict } from './index';
6
-
7
- describe('formatDistanceToNowStrict', () => {
8
- let clock: sinon.SinonFakeTimers;
9
- beforeEach(() => {
10
- clock = sinon.useFakeTimers(new Date(1986, 3, 4, 10, 32, 0).getTime());
11
- });
12
-
13
- afterEach(() => {
14
- clock.restore();
15
- });
16
-
17
- describe('seconds', () => {
18
- describe('when no unit is set', () => {
19
- it('0 seconds', () => {
20
- const result = formatDistanceToNowStrict(new Date(1986, 3, 4, 10, 32, 0));
21
- expect(result).toBe('0 seconds');
22
- });
23
-
24
- it('5 seconds', () => {
25
- const result = formatDistanceToNowStrict(new Date(1986, 3, 4, 10, 32, 5));
26
- expect(result).toBe('5 seconds');
27
- });
28
- });
29
- });
30
-
31
- describe('minutes', () => {
32
- it('1 minute', () => {
33
- const result = formatDistanceToNowStrict(new Date(1986, 3, 4, 10, 33, 0));
34
- expect(result).toBe('1 minute');
35
- });
36
-
37
- it('n minutes', () => {
38
- const result = formatDistanceToNowStrict(new Date(1986, 3, 4, 10, 35, 0));
39
- expect(result).toBe('3 minutes');
40
- });
41
- });
42
-
43
- describe('hours', () => {
44
- it('1 hour', () => {
45
- const result = formatDistanceToNowStrict(new Date(1986, 3, 4, 11, 32, 0));
46
- expect(result).toBe('1 hour');
47
- });
48
-
49
- it('n hours', () => {
50
- const result = formatDistanceToNowStrict(new Date(1986, 3, 4, 13, 32, 0));
51
- expect(result).toBe('3 hours');
52
- });
53
- });
54
-
55
- describe('days', () => {
56
- it('1 day', () => {
57
- const result = formatDistanceToNowStrict(new Date(1986, 3, 5, 10, 32, 0));
58
- expect(result).toBe('1 day');
59
- });
60
-
61
- it('n days', () => {
62
- const result = formatDistanceToNowStrict(new Date(1986, 3, 7, 10, 32, 0));
63
- expect(result).toBe('3 days');
64
- });
65
- });
66
-
67
- describe('months', () => {
68
- it('1 month', () => {
69
- const result = formatDistanceToNowStrict(new Date(1986, 4, 4, 10, 32, 0));
70
- expect(result).toBe('1 month');
71
- });
72
-
73
- it('n months', () => {
74
- const result = formatDistanceToNowStrict(new Date(1986, 6, 4, 10, 32, 0));
75
- expect(result).toBe('3 months');
76
- });
77
- });
78
-
79
- describe('years', () => {
80
- it('1 year', () => {
81
- const result = formatDistanceToNowStrict(new Date(1987, 3, 4, 10, 32, 0));
82
- expect(result).toBe('1 year');
83
- });
84
-
85
- it('n years', () => {
86
- const result = formatDistanceToNowStrict(new Date(1991, 3, 4, 10, 32, 0));
87
- expect(result).toBe('5 years');
88
- });
89
- });
90
-
91
- describe('when the unit option is supplied', () => {
92
- describe('second', () => {
93
- it('0 seconds', () => {
94
- const result = formatDistanceToNowStrict(new Date(1986, 3, 4, 10, 32, 0), { unit: 'second' });
95
- expect(result).toBe('0 seconds');
96
- });
97
-
98
- it('5 seconds', () => {
99
- const result = formatDistanceToNowStrict(new Date(1986, 3, 4, 10, 32, 5), { unit: 'second' });
100
- expect(result).toBe('5 seconds');
101
- });
102
-
103
- it('120 seconds', () => {
104
- const result = formatDistanceToNowStrict(new Date(1986, 3, 4, 10, 34, 0), { unit: 'second' });
105
- expect(result).toBe('120 seconds');
106
- });
107
- });
108
-
109
- describe('minute', () => {
110
- it('0 minutes', () => {
111
- const result = formatDistanceToNowStrict(new Date(1986, 3, 4, 10, 32, 0), { unit: 'minute' });
112
- expect(result).toBe('0 minutes');
113
- });
114
-
115
- it('5 minutes', () => {
116
- const result = formatDistanceToNowStrict(new Date(1986, 3, 4, 10, 37, 0), { unit: 'minute' });
117
- expect(result).toBe('5 minutes');
118
- });
119
-
120
- it('120 minutes', () => {
121
- const result = formatDistanceToNowStrict(new Date(1986, 3, 4, 12, 32, 0), { unit: 'minute' });
122
- expect(result).toBe('120 minutes');
123
- });
124
- });
125
-
126
- describe('hour', () => {
127
- it('0 hours', () => {
128
- const result = formatDistanceToNowStrict(new Date(1986, 3, 4, 10, 32, 0), { unit: 'hour' });
129
- expect(result).toBe('0 hours');
130
- });
131
-
132
- it('5 hours', () => {
133
- const result = formatDistanceToNowStrict(new Date(1986, 3, 4, 15, 32, 0), { unit: 'hour' });
134
- expect(result).toBe('5 hours');
135
- });
136
-
137
- it('48 hours', () => {
138
- const result = formatDistanceToNowStrict(new Date(1986, 3, 6, 10, 32, 0), { unit: 'hour' });
139
- expect(result).toBe('48 hours');
140
- });
141
- });
142
-
143
- describe('day', () => {
144
- it('0 days', () => {
145
- const result = formatDistanceToNowStrict(new Date(1986, 3, 4, 10, 32, 0), { unit: 'day' });
146
- expect(result).toBe('0 days');
147
- });
148
-
149
- it('5 days', () => {
150
- const result = formatDistanceToNowStrict(new Date(1986, 3, 9, 10, 32, 0), { unit: 'day' });
151
- expect(result).toBe('5 days');
152
- });
153
-
154
- it('60 days', () => {
155
- const result = formatDistanceToNowStrict(new Date(1986, 5, 3, 10, 32, 0), { unit: 'day' });
156
- expect(result).toBe('60 days');
157
- });
158
- });
159
- describe('month', () => {
160
- it('0 months', () => {
161
- const result = formatDistanceToNowStrict(new Date(1986, 3, 4, 10, 32, 0), { unit: 'month' });
162
- expect(result).toBe('0 months');
163
- });
164
-
165
- it('5 months', () => {
166
- const result = formatDistanceToNowStrict(new Date(1986, 7, 4, 10, 32, 0), { unit: 'month' });
167
- expect(result).toBe('4 months');
168
- });
169
-
170
- it('24 months', () => {
171
- const result = formatDistanceToNowStrict(new Date(1988, 3, 4, 10, 32, 0), { unit: 'month' });
172
- expect(result).toBe('24 months');
173
- });
174
- });
175
-
176
- describe('year', () => {
177
- it('returns `1 year` - see issue 2388', () => {
178
- const result = formatDistanceToNowStrict(new Date(1985, 3, 4, 10, 32, 0));
179
- expect(result).toBe('1 year');
180
- });
181
-
182
- it('returns `2 years` - see issue 2388', () => {
183
- const result = formatDistanceToNowStrict(new Date(1984, 3, 4, 10, 32, 0));
184
- expect(result).toBe('2 years');
185
- });
186
-
187
- it('0 years', () => {
188
- const result = formatDistanceToNowStrict(new Date(1986, 3, 4, 10, 32, 0), { unit: 'year' });
189
- expect(result).toBe('0 years');
190
- });
191
-
192
- it('5 years', () => {
193
- const result = formatDistanceToNowStrict(new Date(1991, 3, 4, 15, 32, 0), { unit: 'year' });
194
- expect(result).toBe('5 years');
195
- });
196
- });
197
- });
198
-
199
- it('accepts timestamps', () => {
200
- const result = formatDistanceToNowStrict(new Date(1986, 3, 4, 11, 32, 0).getTime());
201
- expect(result).toBe('1 hour');
202
- });
203
-
204
- describe('when the addSuffix option is true', () => {
205
- it('adds a past suffix', () => {
206
- const result = formatDistanceToNowStrict(new Date(1986, 3, 4, 10, 31, 35), {
207
- addSuffix: true,
208
- });
209
- expect(result).toBe('25 seconds ago');
210
- });
211
-
212
- it('adds a future suffix', () => {
213
- const result = formatDistanceToNowStrict(new Date(1986, 3, 4, 11, 32, 0), {
214
- addSuffix: true,
215
- });
216
- expect(result).toBe('in 1 hour');
217
- });
218
- });
219
-
220
- describe('when the roundingMethod option is supplied', () => {
221
- it('default is "round"', () => {
222
- const result = formatDistanceToNowStrict(new Date(1986, 3, 4, 10, 33, 59));
223
- expect(result).toBe('2 minutes');
224
- });
225
-
226
- it('"floor"', () => {
227
- const result = formatDistanceToNowStrict(new Date(1986, 3, 4, 10, 33, 59), {
228
- roundingMethod: 'floor',
229
- });
230
- expect(result).toBe('1 minute');
231
- });
232
-
233
- it('"ceil"', () => {
234
- const result = formatDistanceToNowStrict(new Date(1986, 3, 4, 10, 33, 1), {
235
- roundingMethod: 'ceil',
236
- });
237
- expect(result).toBe('2 minutes');
238
- });
239
-
240
- it('"round" (down)', () => {
241
- const result = formatDistanceToNowStrict(new Date(1986, 3, 4, 10, 33, 29), {
242
- roundingMethod: 'round',
243
- });
244
- expect(result).toBe('1 minute');
245
- });
246
-
247
- it('"round" (up)', () => {
248
- const result = formatDistanceToNowStrict(new Date(1986, 3, 4, 10, 33, 30), {
249
- roundingMethod: 'round',
250
- });
251
- expect(result).toBe('2 minutes');
252
- });
253
- });
254
-
255
- describe('custom locale', () => {
256
- it('can be passed to the function', () => {
257
- const localizeDistance: FormatDistanceFn = (token, count, options) => {
258
- expect(token).toBe('xSeconds');
259
- expect(count).toBe(15);
260
- expect(options!.addSuffix).toBe(true);
261
- expect(options!.comparison!).toBeLessThan(0);
262
- return 'It works!';
263
- };
264
-
265
- const customLocale = {
266
- formatDistance: localizeDistance,
267
- };
268
-
269
- const result = formatDistanceToNowStrict(new Date(1986, 3, 4, 10, 31, 45), {
270
- addSuffix: true,
271
- locale: customLocale,
272
- });
273
-
274
- expect(result).toBe('It works!');
275
- });
276
- });
277
-
278
- describe('edge cases', () => {
279
- it('detects unit correctly for short months', () => {
280
- const result = formatDistanceToNowStrict(new Date(1986, 2 /* Mar */, 7));
281
- expect(result).toBe('28 days');
282
- });
283
- });
284
-
285
- it('throws `RangeError` if the date is `Invalid Date`', () => {
286
- expect(formatDistanceToNowStrict.bind(null, new Date(NaN))).toThrow(RangeError);
287
- });
288
-
289
- it('respects date extensions', () => {
290
- const result = formatDistanceToNowStrict(new UTCDate(+new Date(1986, 3, 4, 10, 32, 5)));
291
- expect(result).toBe('5 seconds');
292
- });
293
- });
@@ -1,74 +0,0 @@
1
- import { describe, expect, it } from 'vitest';
2
- import { formatDuration } from './index';
3
-
4
- describe('formatDuration', () => {
5
- it('formats full duration', () => {
6
- expect(
7
- formatDuration({
8
- years: 2,
9
- months: 9,
10
- weeks: 1,
11
- days: 7,
12
- hours: 5,
13
- minutes: 9,
14
- seconds: 30,
15
- }),
16
- ).toBe('2 years 9 months 1 week 7 days 5 hours 9 minutes 30 seconds');
17
- });
18
-
19
- it('formats partial duration', () => {
20
- expect(formatDuration({ months: 9, days: 2 })).toBe('9 months 2 days');
21
- });
22
-
23
- it('allows to customize the format', () => {
24
- expect(
25
- formatDuration(
26
- {
27
- years: 2,
28
- months: 9,
29
- weeks: 1,
30
- days: 7,
31
- hours: 5,
32
- minutes: 9,
33
- seconds: 30,
34
- },
35
- { format: ['months', 'weeks'] },
36
- ),
37
- ).toBe('9 months 1 week');
38
- });
39
-
40
- it('does not include zeros by default', () => {
41
- expect(
42
- formatDuration({
43
- years: 0,
44
- months: 0,
45
- weeks: 1,
46
- days: 0,
47
- hours: 0,
48
- minutes: 0,
49
- seconds: 0,
50
- }),
51
- ).toBe('1 week');
52
- });
53
-
54
- it('allows to include zeros', () => {
55
- expect(
56
- formatDuration(
57
- {
58
- years: 0,
59
- months: 0,
60
- weeks: 1,
61
- days: 0,
62
- hours: 0,
63
- minutes: 0,
64
- seconds: 0,
65
- },
66
- { zero: true },
67
- ),
68
- ).toBe('0 years 0 months 1 week 0 days 0 hours 0 minutes 0 seconds');
69
- });
70
-
71
- it('allows to customize the delimiter', () => {
72
- expect(formatDuration({ months: 9, days: 2 }, { delimiter: ', ' })).toBe('9 months, 2 days');
73
- });
74
- });
@@ -1,55 +0,0 @@
1
- import { describe, expect, it } from 'vitest';
2
- import sinon from 'sinon';
3
- import { formatISO } from './index';
4
- import { generateOffset } from '../_lib/test/index';
5
-
6
- describe('formatISO', () => {
7
- it('formats ISO-8601 extended format', () => {
8
- const date = new Date(2019, 2 /* Mar */, 3, 19, 0, 52, 123);
9
- const tzOffsetExtended = generateOffset(date);
10
- expect(formatISO(date)).toBe(`2019-03-03T19:00:52${tzOffsetExtended}`);
11
-
12
- const getTimezoneOffsetStub = sinon.stub(Date.prototype, 'getTimezoneOffset');
13
-
14
- getTimezoneOffsetStub.returns(480);
15
- const tzNegativeOffsetExtended = generateOffset(date);
16
- expect(formatISO(date)).toBe(`2019-03-03T19:00:52${tzNegativeOffsetExtended}`);
17
-
18
- getTimezoneOffsetStub.returns(0);
19
- const tzZOffsetExtended = generateOffset(date);
20
- expect(formatISO(date)).toBe(`2019-03-03T19:00:52${tzZOffsetExtended}`);
21
-
22
- getTimezoneOffsetStub.restore();
23
- });
24
-
25
- it('accepts a timestamp', () => {
26
- const date = new Date(2019, 2 /* Mar */, 3, 19, 0, 52, 123).getTime();
27
- const tzOffsetExtended = generateOffset(new Date(date));
28
- expect(formatISO(date)).toBe(`2019-03-03T19:00:52${tzOffsetExtended}`);
29
- });
30
-
31
- it('formats ISO-8601 basic format', () => {
32
- const date = new Date(2019, 9 /* Oct */, 4, 12, 30, 13, 456);
33
- const tzOffsetBasic = generateOffset(date);
34
- expect(formatISO(date, { format: 'basic' })).toBe(`20191004T123013${tzOffsetBasic}`);
35
- });
36
-
37
- it('formats only date', () => {
38
- const date = new Date(2019, 11 /* Dec */, 11, 1, 0, 0, 789);
39
-
40
- expect(formatISO(date, { representation: 'date', format: 'extended' })).toBe('2019-12-11');
41
- expect(formatISO(date, { representation: 'date', format: 'basic' })).toBe('20191211');
42
- });
43
-
44
- it('formats only time', () => {
45
- const date = new Date(2019, 2 /* Mar */, 3, 19, 0, 52, 123);
46
- const tzOffset = generateOffset(date);
47
-
48
- expect(formatISO(date, { representation: 'time', format: 'extended' })).toBe(`19:00:52${tzOffset}`);
49
- expect(formatISO(date, { representation: 'time', format: 'basic' })).toBe(`190052${tzOffset}`);
50
- });
51
-
52
- it('throws RangeError if the time value is invalid', () => {
53
- expect(formatISO.bind(null, new Date(NaN))).toThrow(RangeError);
54
- });
55
- });
@@ -1,35 +0,0 @@
1
- import { describe, expect, it } from 'vitest';
2
- import { formatISO9075 } from './index';
3
-
4
- describe('formatISO9075', () => {
5
- it('formats ISO-9075 extended date format', () => {
6
- const date = new Date(2019, 2 /* Mar */, 3, 19, 0, 52, 123);
7
- expect(formatISO9075(date)).toBe('2019-03-03 19:00:52');
8
- });
9
-
10
- it('accepts a timestamp', () => {
11
- const date = new Date(2019, 2 /* Mar */, 3, 19, 0, 52, 123).getTime();
12
- expect(formatISO9075(date)).toBe('2019-03-03 19:00:52');
13
- });
14
-
15
- it('formats ISO-8601 basic date format', () => {
16
- const date = new Date(2019, 9 /* Oct */, 4, 12, 30, 13, 456);
17
- expect(formatISO9075(date, { format: 'basic' })).toBe('20191004 123013');
18
- });
19
-
20
- it('formats only date', () => {
21
- const date = new Date(2019, 11 /* Dec */, 11, 1, 0, 0, 789);
22
- expect(formatISO9075(date, { representation: 'date', format: 'extended' })).toBe('2019-12-11');
23
- expect(formatISO9075(date, { representation: 'date', format: 'basic' })).toBe('20191211');
24
- });
25
-
26
- it('formats only time', () => {
27
- const date = new Date(2019, 2 /* Mar */, 3, 19, 0, 52, 123);
28
- expect(formatISO9075(date, { representation: 'time', format: 'extended' })).toBe('19:00:52');
29
- expect(formatISO9075(date, { representation: 'time', format: 'basic' })).toBe('190052');
30
- });
31
-
32
- it('throws RangeError if the time value is invalid', () => {
33
- expect(formatISO9075.bind(null, new Date(NaN))).toThrow(RangeError);
34
- });
35
- });