@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,909 +0,0 @@
1
- import { afterEach, beforeEach, describe, expect, it, type SpyInstance, vi } from 'vitest';
2
- import sinon from 'sinon';
3
- import type { FormatPart } from '../types';
4
- import { format, formatDate } from './index';
5
-
6
- describe('format', () => {
7
- const date = new Date(1986, 3 /* Apr */, 4, 10, 32, 55, 123);
8
-
9
- const offset = date.getTimezoneOffset();
10
- const absoluteOffset = Math.abs(offset);
11
- const hours = Math.trunc(absoluteOffset / 60);
12
- const hoursLeadingZero = hours < 10 ? '0' : '';
13
- const minutes = absoluteOffset % 60;
14
- const minutesLeadingZero = minutes < 10 ? '0' : '';
15
- const sign = offset > 0 ? '-' : '+';
16
-
17
- const timezone = sign + hoursLeadingZero + hours + ':' + minutesLeadingZero + minutes;
18
- const timezoneShort = timezone.replace(':', '');
19
- const timezoneWithOptionalMinutesShort = minutes === 0 ? sign + hoursLeadingZero + hours : timezoneShort;
20
-
21
- const timezoneWithZ = offset === 0 ? 'Z' : timezone;
22
- const timezoneWithZShort = offset === 0 ? 'Z' : timezoneShort;
23
- const timezoneWithOptionalMinutesAndZShort = offset === 0 ? 'Z' : timezoneWithOptionalMinutesShort;
24
-
25
- const timezoneGMTShort =
26
- minutes === 0 ? 'GMT' + sign + hours : 'GMT' + sign + hours + ':' + minutesLeadingZero + minutes;
27
- const timezoneGMT = 'GMT' + timezone;
28
-
29
- const timestamp = date.getTime().toString();
30
- const secondsTimestamp = Math.trunc(date.getTime() / 1000).toString();
31
-
32
- it('accepts a timestamp', () => {
33
- const date = new Date(2014, 3, 4).getTime();
34
- expect(format(date, 'yyyy-MM-dd')).toBe('2014-04-04');
35
- });
36
-
37
- it('escapes characters between the single quote characters', () => {
38
- const result = format(date, "'yyyy-'MM-dd'THH:mm:ss.SSSX' yyyy-'MM-dd'");
39
- expect(result).toBe('yyyy-04-04THH:mm:ss.SSSX 1986-MM-dd');
40
- });
41
-
42
- it('two single quote characters are transformed into a "real" single quote', () => {
43
- const date = new Date(2014, 3, 4, 5);
44
- expect(format(date, "''h 'o''clock'''")).toBe("'5 o'clock'");
45
- });
46
-
47
- it('accepts new line charactor', () => {
48
- const date = new Date(2014, 3, 4, 5);
49
- expect(format(date, "yyyy-MM-dd'\n'HH:mm:ss")).toBe('2014-04-04\n05:00:00');
50
- });
51
-
52
- it('alias formatDate has same behavior as format', () => {
53
- const date = new Date(2014, 3, 4, 5);
54
- expect(formatDate(date, "yyyy-MM-dd'\n'HH:mm:ss")).toBe(format(date, "yyyy-MM-dd'\n'HH:mm:ss"));
55
- });
56
-
57
- describe('ordinal numbers', () => {
58
- it('ordinal day of an ordinal month', () => {
59
- const result = format(date, "do 'day of the' Mo 'month of' yyyy");
60
- expect(result).toBe('4th day of the 4th month of 1986');
61
- });
62
-
63
- it('should return a correct ordinal number', () => {
64
- const result = [];
65
- for (let i = 1; i <= 31; i++) {
66
- result.push(format(new Date(2015, 0, i), 'do'));
67
- }
68
- const expected = [
69
- '1st',
70
- '2nd',
71
- '3rd',
72
- '4th',
73
- '5th',
74
- '6th',
75
- '7th',
76
- '8th',
77
- '9th',
78
- '10th',
79
- '11th',
80
- '12th',
81
- '13th',
82
- '14th',
83
- '15th',
84
- '16th',
85
- '17th',
86
- '18th',
87
- '19th',
88
- '20th',
89
- '21st',
90
- '22nd',
91
- '23rd',
92
- '24th',
93
- '25th',
94
- '26th',
95
- '27th',
96
- '28th',
97
- '29th',
98
- '30th',
99
- '31st',
100
- ];
101
- expect(result).toEqual(expected);
102
- });
103
- });
104
-
105
- it('era', () => {
106
- const result = format(date, 'G GG GGG GGGG GGGGG');
107
- expect(result).toBe('AD AD AD Anno Domini A');
108
-
109
- const bcDate = new Date();
110
- bcDate.setFullYear(-1, 0 /* Jan */, 1);
111
- const bcResult = format(bcDate, 'G GG GGG GGGG GGGGG');
112
- expect(bcResult).toBe('BC BC BC Before Christ B');
113
- });
114
-
115
- describe('year', () => {
116
- describe('regular year', () => {
117
- it('works as expected', () => {
118
- const result = format(date, 'y yo yy yyy yyyy yyyyy');
119
- expect(result).toBe('1986 1986th 86 1986 1986 01986');
120
- });
121
-
122
- it('1 BC formats as 1', () => {
123
- const date = new Date(0);
124
- date.setFullYear(0, 0 /* Jan */, 1);
125
- date.setHours(0, 0, 0, 0);
126
- const result = format(date, 'y');
127
- expect(result).toBe('1');
128
- });
129
-
130
- it('2 BC formats as 2', () => {
131
- const date = new Date(0);
132
- date.setFullYear(-1, 0 /* Jan */, 1);
133
- date.setHours(0, 0, 0, 0);
134
- const result = format(date, 'y');
135
- expect(result).toBe('2');
136
- });
137
-
138
- it('2 BC formats as 2nd', () => {
139
- const date = new Date();
140
- date.setFullYear(-1, 0 /* Jan */, 1);
141
- date.setHours(0, 0, 0, 0);
142
- const result = format(date, 'yo');
143
- expect(result).toBe('2nd');
144
- });
145
- });
146
-
147
- describe('local week-numbering year', () => {
148
- it('works as expected', () => {
149
- const result = format(date, 'Y Yo YY YYY YYYY YYYYY', {
150
- useAdditionalWeekYearTokens: true,
151
- });
152
- expect(result).toBe('1986 1986th 86 1986 1986 01986');
153
- });
154
-
155
- it('the first week of the next year', () => {
156
- const result = format(new Date(2013, 11 /* Dec */, 29), 'YYYY', {
157
- useAdditionalWeekYearTokens: true,
158
- });
159
- expect(result).toBe('2014');
160
- });
161
-
162
- it('allows to specify `weekStartsOn` and `firstWeekContainsDate` in options', () => {
163
- const result = format(new Date(2013, 11 /* Dec */, 29), 'YYYY', {
164
- weekStartsOn: 1,
165
- firstWeekContainsDate: 4,
166
- useAdditionalWeekYearTokens: true,
167
- });
168
- expect(result).toBe('2013');
169
- });
170
-
171
- it('the first week of year', () => {
172
- const result = format(new Date(2016, 0 /* Jan */, 1), 'YYYY', {
173
- useAdditionalWeekYearTokens: true,
174
- });
175
- expect(result).toBe('2016');
176
- });
177
-
178
- it('1 BC formats as 1', () => {
179
- const date = new Date(0);
180
- date.setFullYear(0, 6 /* Jul */, 2);
181
- date.setHours(0, 0, 0, 0);
182
- const result = format(date, 'Y');
183
- expect(result).toBe('1');
184
- });
185
-
186
- it('2 BC formats as 2', () => {
187
- const date = new Date(0);
188
- date.setFullYear(-1, 6 /* Jul */, 2);
189
- date.setHours(0, 0, 0, 0);
190
- const result = format(date, 'Y');
191
- expect(result).toBe('2');
192
- });
193
- });
194
-
195
- describe('ISO week-numbering year', () => {
196
- it('works as expected', () => {
197
- const result = format(date, 'R RR RRR RRRR RRRRR');
198
- expect(result).toBe('1986 1986 1986 1986 01986');
199
- });
200
-
201
- it('the first week of the next year', () => {
202
- const result = format(new Date(2013, 11 /* Dec */, 30), 'RRRR');
203
- expect(result).toBe('2014');
204
- });
205
-
206
- it('the last week of the previous year', () => {
207
- const result = format(new Date(2016, 0 /* Jan */, 1), 'RRRR');
208
- expect(result).toBe('2015');
209
- });
210
-
211
- it('1 BC formats as 0', () => {
212
- const date = new Date(0);
213
- date.setFullYear(0, 6 /* Jul */, 2);
214
- date.setHours(0, 0, 0, 0);
215
- const result = format(date, 'R');
216
- expect(result).toBe('0');
217
- });
218
-
219
- it('2 BC formats as -1', () => {
220
- const date = new Date(0);
221
- date.setFullYear(-1, 6 /* Jul */, 2);
222
- date.setHours(0, 0, 0, 0);
223
- const result = format(date, 'R');
224
- expect(result).toBe('-1');
225
- });
226
- });
227
-
228
- describe('extended year', () => {
229
- it('works as expected', () => {
230
- const result = format(date, 'u uu uuu uuuu uuuuu');
231
- expect(result).toBe('1986 1986 1986 1986 01986');
232
- });
233
-
234
- it('1 BC formats as 0', () => {
235
- const date = new Date(0);
236
- date.setFullYear(0, 0, 1);
237
- date.setHours(0, 0, 0, 0);
238
- const result = format(date, 'u');
239
- expect(result).toBe('0');
240
- });
241
-
242
- it('2 BC formats as -1', () => {
243
- const date = new Date(0);
244
- date.setFullYear(-1, 0, 1);
245
- date.setHours(0, 0, 0, 0);
246
- const result = format(date, 'u');
247
- expect(result).toBe('-1');
248
- });
249
- });
250
- });
251
-
252
- describe('quarter', () => {
253
- it('formatting quarter', () => {
254
- const result = format(date, 'Q Qo QQ QQQ QQQQ QQQQQ');
255
- expect(result).toBe('2 2nd 02 Q2 2nd quarter 2');
256
- });
257
-
258
- it('stand-alone quarter', () => {
259
- const result = format(date, 'q qo qq qqq qqqq qqqqq');
260
- expect(result).toBe('2 2nd 02 Q2 2nd quarter 2');
261
- });
262
-
263
- it('returns a correct quarter for each month', () => {
264
- const result = [];
265
- for (let i = 0; i <= 11; i++) {
266
- result.push(format(new Date(1986, i, 1), 'Q'));
267
- }
268
- const expected = ['1', '1', '1', '2', '2', '2', '3', '3', '3', '4', '4', '4'];
269
- expect(result).toEqual(expected);
270
- });
271
- });
272
-
273
- describe('month', () => {
274
- it('formatting month', () => {
275
- const result = format(date, 'M Mo MM MMM MMMM MMMMM');
276
- expect(result).toBe('4 4th 04 Apr April A');
277
- });
278
-
279
- it('stand-alone month', () => {
280
- const result = format(date, 'L Lo LL LLL LLLL LLLLL');
281
- expect(result).toBe('4 4th 04 Apr April A');
282
- });
283
- });
284
-
285
- describe('week', () => {
286
- describe('local week of year', () => {
287
- it('works as expected', () => {
288
- const date = new Date(1986, 3 /* Apr */, 6);
289
- const result = format(date, 'w wo ww');
290
- expect(result).toBe('15 15th 15');
291
- });
292
-
293
- it('allows to specify `weekStartsOn` and `firstWeekContainsDate` in options', () => {
294
- const date = new Date(1986, 3 /* Apr */, 6);
295
- const result = format(date, 'w wo ww', {
296
- weekStartsOn: 1,
297
- firstWeekContainsDate: 4,
298
- });
299
- expect(result).toBe('14 14th 14');
300
- });
301
- });
302
-
303
- it('ISO week of year', () => {
304
- const date = new Date(1986, 3 /* Apr */, 6);
305
- const result = format(date, 'I Io II');
306
- expect(result).toBe('14 14th 14');
307
- });
308
- });
309
-
310
- describe('day', () => {
311
- it('date', () => {
312
- const result = format(date, 'd do dd');
313
- expect(result).toBe('4 4th 04');
314
- });
315
-
316
- describe('day of year', () => {
317
- it('works as expected', () => {
318
- const result = format(date, 'D Do DD DDD DDDDD', {
319
- useAdditionalDayOfYearTokens: true,
320
- });
321
- expect(result).toBe('94 94th 94 094 00094');
322
- });
323
-
324
- it('returns a correct day number for the last day of a leap year', () => {
325
- const result = format(new Date(1992, 11 /* Dec */, 31, 23, 59, 59, 999), 'D', {
326
- useAdditionalDayOfYearTokens: true,
327
- });
328
- expect(result).toBe('366');
329
- });
330
- });
331
- });
332
-
333
- describe('week day', () => {
334
- describe('day of week', () => {
335
- it('works as expected', () => {
336
- const result = format(date, 'E EE EEE EEEE EEEEE EEEEEE');
337
- expect(result).toBe('Fri Fri Fri Friday F Fr');
338
- });
339
- });
340
-
341
- describe('ISO day of week', () => {
342
- it('works as expected', () => {
343
- const result = format(date, 'i io ii iii iiii iiiii iiiiii');
344
- expect(result).toBe('5 5th 05 Fri Friday F Fr');
345
- });
346
-
347
- it('returns a correct day of an ISO week', () => {
348
- const result = [];
349
- for (let i = 1; i <= 7; i++) {
350
- result.push(format(new Date(1986, 8 /* Sep */, i), 'i'));
351
- }
352
- const expected = ['1', '2', '3', '4', '5', '6', '7'];
353
- expect(result).toEqual(expected);
354
- });
355
- });
356
-
357
- describe('formatting day of week', () => {
358
- it('works as expected', () => {
359
- const result = format(date, 'e eo ee eee eeee eeeee eeeeee');
360
- expect(result).toBe('6 6th 06 Fri Friday F Fr');
361
- });
362
-
363
- it('by default, 1 is Sunday, 2 is Monday, ...', () => {
364
- const result = [];
365
- for (let i = 7; i <= 13; i++) {
366
- result.push(format(new Date(1986, 8 /* Sep */, i), 'e'));
367
- }
368
- const expected = ['1', '2', '3', '4', '5', '6', '7'];
369
- expect(result).toEqual(expected);
370
- });
371
-
372
- it('allows to specify which day is the first day of the week', () => {
373
- const result = [];
374
- for (let i = 1; i <= 7; i++) {
375
- result.push(format(new Date(1986, 8 /* Sep */, i), 'e', { weekStartsOn: 1 }));
376
- }
377
- const expected = ['1', '2', '3', '4', '5', '6', '7'];
378
- expect(result).toEqual(expected);
379
- });
380
- });
381
-
382
- describe('stand-alone day of week', () => {
383
- it('works as expected', () => {
384
- const result = format(date, 'c co cc ccc cccc ccccc cccccc');
385
- expect(result).toBe('6 6th 06 Fri Friday F Fr');
386
- });
387
-
388
- it('by default, 1 is Sunday, 2 is Monday, ...', () => {
389
- const result = [];
390
- for (let i = 7; i <= 13; i++) {
391
- result.push(format(new Date(1986, 8 /* Sep */, i), 'c'));
392
- }
393
- const expected = ['1', '2', '3', '4', '5', '6', '7'];
394
- expect(result).toEqual(expected);
395
- });
396
-
397
- it('allows to specify which day is the first day of the week', () => {
398
- const result = [];
399
- for (let i = 1; i <= 7; i++) {
400
- result.push(format(new Date(1986, 8 /* Sep */, i), 'c', { weekStartsOn: 1 }));
401
- }
402
- const expected = ['1', '2', '3', '4', '5', '6', '7'];
403
- expect(result).toEqual(expected);
404
- });
405
- });
406
- });
407
-
408
- describe('day period and hour', () => {
409
- it('hour [1-12]', () => {
410
- const result = format(new Date(2018, 0 /* Jan */, 1, 0, 0, 0, 0), 'h ho hh');
411
- expect(result).toBe('12 12th 12');
412
- });
413
-
414
- it('hour [0-23]', () => {
415
- const result = format(new Date(2018, 0 /* Jan */, 1, 0, 0, 0, 0), 'H Ho HH');
416
- expect(result).toBe('0 0th 00');
417
- });
418
-
419
- it('hour [0-11]', () => {
420
- const result = format(new Date(2018, 0 /* Jan */, 1, 0, 0, 0, 0), 'K Ko KK');
421
- expect(result).toBe('0 0th 00');
422
- });
423
-
424
- it('hour [1-24]', () => {
425
- const result = format(new Date(2018, 0 /* Jan */, 1, 0, 0, 0, 0), 'k ko kk');
426
- expect(result).toBe('24 24th 24');
427
- });
428
-
429
- describe('AM, PM', () => {
430
- it('works as expected', () => {
431
- const result = format(new Date(2018, 0 /* Jan */, 1, 0, 0, 0, 0), 'a aa aaa aaaa aaaaa');
432
- expect(result).toBe('AM AM am a.m. a');
433
- });
434
-
435
- it('12 PM', () => {
436
- const date = new Date(1986, 3 /* Apr */, 4, 12, 0, 0, 900);
437
- expect(format(date, 'h H K k a')).toBe('12 12 0 12 PM');
438
- });
439
-
440
- it('12 AM', () => {
441
- const date = new Date(1986, 3 /* Apr */, 6, 0, 0, 0, 900);
442
- expect(format(date, 'h H K k a')).toBe('12 0 0 24 AM');
443
- });
444
- });
445
-
446
- describe('AM, PM, noon, midnight', () => {
447
- it('works as expected', () => {
448
- const result = format(new Date(1986, 3 /* Apr */, 6, 2, 0, 0, 900), 'b bb bbb bbbb bbbbb');
449
- expect(result).toBe('AM AM am a.m. a');
450
-
451
- const pmResult = format(new Date(1986, 3 /* Apr */, 6, 13, 0, 0, 900), 'b bb bbb bbbb bbbbb');
452
- expect(pmResult).toBe('PM PM pm p.m. p');
453
- });
454
-
455
- it('12 PM', () => {
456
- const date = new Date(1986, 3 /* Apr */, 4, 12, 0, 0, 900);
457
- expect(format(date, 'b bb bbb bbbb bbbbb')).toBe('noon noon noon noon n');
458
- });
459
-
460
- it('12 AM', () => {
461
- const date = new Date(1986, 3 /* Apr */, 6, 0, 0, 0, 900);
462
- expect(format(date, 'b bb bbb bbbb bbbbb')).toBe('midnight midnight midnight midnight mi');
463
- });
464
- });
465
-
466
- describe('flexible day periods', () => {
467
- it('works as expected', () => {
468
- const result = format(date, 'B, BB, BBB, BBBB, BBBBB');
469
- expect(result).toBe('in the morning, in the morning, in the morning, in the morning, in the morning');
470
- });
471
-
472
- it('12 PM', () => {
473
- const date = new Date(1986, 3 /* Apr */, 4, 12, 0, 0, 900);
474
- expect(format(date, 'h B')).toBe('12 in the afternoon');
475
- });
476
-
477
- it('5 PM', () => {
478
- const date = new Date(1986, 3 /* Apr */, 6, 17, 0, 0, 900);
479
- expect(format(date, 'h B')).toBe('5 in the evening');
480
- });
481
-
482
- it('12 AM', () => {
483
- const date = new Date(1986, 3 /* Apr */, 6, 0, 0, 0, 900);
484
- expect(format(date, 'h B')).toBe('12 at night');
485
- });
486
-
487
- it('4 AM', () => {
488
- const date = new Date(1986, 3 /* Apr */, 6, 4, 0, 0, 900);
489
- expect(format(date, 'h B')).toBe('4 in the morning');
490
- });
491
- });
492
- });
493
-
494
- it('minute', () => {
495
- const result = format(date, 'm mo mm');
496
- expect(result).toBe('32 32nd 32');
497
- });
498
-
499
- describe('second', () => {
500
- it('second', () => {
501
- const result = format(date, 's so ss');
502
- expect(result).toBe('55 55th 55');
503
- });
504
-
505
- it('fractional seconds', () => {
506
- const result = format(date, 'S SS SSS SSSS');
507
- expect(result).toBe('1 12 123 1230');
508
- });
509
- });
510
-
511
- describe('time zone', () => {
512
- it('ISO-8601 with Z', () => {
513
- const result = format(date, 'X XX XXX XXXX XXXXX');
514
- const expectedResult = [
515
- timezoneWithOptionalMinutesAndZShort,
516
- timezoneWithZShort,
517
- timezoneWithZ,
518
- timezoneWithZShort,
519
- timezoneWithZ,
520
- ].join(' ');
521
- expect(result).toBe(expectedResult);
522
-
523
- const getTimezoneOffsetStub = sinon.stub(Date.prototype, 'getTimezoneOffset');
524
- getTimezoneOffsetStub.returns(0);
525
- const resultZeroOffset = format(date, 'X XX XXX XXXX XXXXX');
526
- expect(resultZeroOffset).toBe('Z Z Z Z Z');
527
-
528
- getTimezoneOffsetStub.returns(480);
529
- const resultNegativeOffset = format(date, 'X XX XXX XXXX XXXXX');
530
- expect(resultNegativeOffset).toBe('-08 -0800 -08:00 -0800 -08:00');
531
-
532
- getTimezoneOffsetStub.returns(450);
533
- const resultNegative30Offset = format(date, 'X XX XXX XXXX XXXXX');
534
- expect(resultNegative30Offset).toBe('-0730 -0730 -07:30 -0730 -07:30');
535
-
536
- getTimezoneOffsetStub.restore();
537
- });
538
-
539
- it('ISO-8601 without Z', () => {
540
- const result = format(date, 'x xx xxx xxxx xxxxx');
541
- const expectedResult = [timezoneWithOptionalMinutesShort, timezoneShort, timezone, timezoneShort, timezone].join(
542
- ' ',
543
- );
544
- expect(result).toBe(expectedResult);
545
- });
546
-
547
- it('GMT', () => {
548
- const result = format(date, 'O OO OOO OOOO');
549
- const expectedResult = [timezoneGMTShort, timezoneGMTShort, timezoneGMTShort, timezoneGMT].join(' ');
550
- expect(result).toBe(expectedResult);
551
-
552
- const getTimezoneOffsetStub = sinon.stub(Date.prototype, 'getTimezoneOffset');
553
- getTimezoneOffsetStub.returns(480);
554
- const resultNegativeOffset = format(date, 'O OO OOO OOOO');
555
- expect(resultNegativeOffset).toBe('GMT-8 GMT-8 GMT-8 GMT-08:00');
556
-
557
- getTimezoneOffsetStub.returns(450);
558
- const resultNegative30Offset = format(date, 'O OO OOO OOOO');
559
- expect(resultNegative30Offset).toBe('GMT-7:30 GMT-7:30 GMT-7:30 GMT-07:30');
560
-
561
- getTimezoneOffsetStub.restore();
562
- });
563
-
564
- it('Specific non-location', () => {
565
- const result = format(date, 'z zz zzz zzzz');
566
- const expectedResult = [timezoneGMTShort, timezoneGMTShort, timezoneGMTShort, timezoneGMT].join(' ');
567
- expect(result).toBe(expectedResult);
568
- });
569
- });
570
-
571
- describe('timestamp', () => {
572
- it('seconds timestamp', () => {
573
- const result = format(date, 't');
574
- expect(result).toBe(secondsTimestamp);
575
- });
576
-
577
- it('milliseconds timestamp', () => {
578
- const result = format(date, 'T');
579
- expect(result).toBe(timestamp);
580
- });
581
-
582
- it('seconds timestamp handles negative numbers', () => {
583
- expect(format(new Date(1001), 't')).toBe('1');
584
- expect(format(new Date(-1001), 't')).toBe('-1');
585
- });
586
- });
587
-
588
- describe('long format', () => {
589
- it('short date', () => {
590
- const result = format(date, 'P');
591
- expect(result).toBe('04/04/1986');
592
- });
593
-
594
- it('medium date', () => {
595
- const result = format(date, 'PP');
596
- expect(result).toBe('Apr 4, 1986');
597
- });
598
-
599
- it('long date', () => {
600
- const result = format(date, 'PPP');
601
- expect(result).toBe('April 4th, 1986');
602
- });
603
-
604
- it('full date', () => {
605
- const result = format(date, 'PPPP');
606
- expect(result).toBe('Friday, April 4th, 1986');
607
- });
608
-
609
- it('short time', () => {
610
- const result = format(date, 'p');
611
- expect(result).toBe('10:32 AM');
612
- });
613
-
614
- it('medium time', () => {
615
- const result = format(date, 'pp');
616
- expect(result).toBe('10:32:55 AM');
617
- });
618
-
619
- it('long time', () => {
620
- const result = format(date, 'ppp');
621
- expect(result).toBe('10:32:55 AM ' + timezoneGMTShort);
622
- });
623
-
624
- it('full time', () => {
625
- const result = format(date, 'pppp');
626
- expect(result).toBe('10:32:55 AM ' + timezoneGMT);
627
- });
628
-
629
- it('short date + time', () => {
630
- const result = format(date, 'Pp');
631
- expect(result).toBe('04/04/1986, 10:32 AM');
632
- });
633
-
634
- it('medium date + time', () => {
635
- const result = format(date, 'PPpp');
636
- expect(result).toBe('Apr 4, 1986, 10:32:55 AM');
637
- });
638
-
639
- it('long date + time', () => {
640
- const result = format(date, 'PPPppp');
641
- expect(result).toBe('April 4th, 1986 at 10:32:55 AM ' + timezoneGMTShort);
642
- });
643
-
644
- it('full date + time', () => {
645
- const result = format(date, 'PPPPpppp');
646
- expect(result).toBe('Friday, April 4th, 1986 at 10:32:55 AM ' + timezoneGMT);
647
- });
648
-
649
- it('allows arbitrary combination of date and time', () => {
650
- const result = format(date, 'Ppppp');
651
- expect(result).toBe('04/04/1986, 10:32:55 AM ' + timezoneGMT);
652
- });
653
- });
654
-
655
- describe('edge cases', () => {
656
- it('throws RangeError if the time value is invalid', () => {
657
- expect(format.bind(null, new Date(NaN), 'MMMM d, yyyy')).toThrow(RangeError);
658
- });
659
-
660
- it('handles dates before 100 AD', () => {
661
- const initialDate = new Date(0);
662
- initialDate.setFullYear(7, 11 /* Dec */, 31);
663
- initialDate.setHours(0, 0, 0, 0);
664
- expect(format(initialDate, 'Y ww i')).toBe('8 01 1');
665
- });
666
- });
667
-
668
- describe('locale features', () => {
669
- it('allows to pass a custom locale', () => {
670
- const customLocale = {
671
- localize: {
672
- month: () => {
673
- return 'works';
674
- },
675
- },
676
- formatLong: {
677
- date: () => {
678
- return "'It' MMMM!";
679
- },
680
- },
681
- };
682
- const result = format(date, 'PPPP', {
683
- // @ts-expect-error - It's ok to have incomplete locale
684
- locale: customLocale,
685
- });
686
- expect(result).toBe('It works!');
687
- });
688
-
689
- it('allows a localize preprocessor', () => {
690
- const customLocale = {
691
- localize: {
692
- month: (v: number) => ['janvier'][v],
693
- ordinalNumber: (v: number) => String(v) + 'er',
694
-
695
- preprocessor: (date: Date, parts: FormatPart[]) => {
696
- // replace `do` tokens to `d` if not the first of the month
697
- if (date.getDate() === 1) return parts;
698
-
699
- return parts.map((part) => (part.isToken && part.value === 'do' ? { isToken: true, value: 'd' } : part));
700
- },
701
- },
702
- };
703
-
704
- let result = format(new Date(2024, 0, 1), 'do MMMM', {
705
- // @ts-expect-error - It's ok to have incomplete locale
706
- locale: customLocale,
707
- });
708
- expect(result).toEqual('1er janvier');
709
-
710
- result = format(new Date(2024, 0, 2), 'do MMMM', {
711
- // @ts-expect-error - It's ok to have incomplete locale
712
- locale: customLocale,
713
- });
714
- expect(result).toEqual('2 janvier');
715
- });
716
- });
717
-
718
- it('throws RangeError exception if the format string contains an unescaped latin alphabet character', () => {
719
- expect(format.bind(null, date, 'yyyy-MM-dd-nnnn')).toThrow(RangeError);
720
- });
721
-
722
- describe('useAdditionalWeekYearTokens and useAdditionalDayOfYearTokens options', () => {
723
- it('throws an error if D token is used', () => {
724
- expect(() => format(date, 'yyyy-MM-D')).toThrow('Use `d` instead of `D`');
725
- });
726
-
727
- it('allows D token if useAdditionalDayOfYearTokens is set to true', () => {
728
- const result = format(date, 'yyyy-MM-D', {
729
- useAdditionalDayOfYearTokens: true,
730
- });
731
- expect(result).toEqual('1986-04-94');
732
- });
733
-
734
- it('throws an error if DD token is used', () => {
735
- expect(() => format(date, 'yyyy-MM-DD')).toThrow('Use `dd` instead of `DD`');
736
- });
737
-
738
- it('allows DD token if useAdditionalDayOfYearTokens is set to true', () => {
739
- const result = format(date, 'yyyy-MM-DD', {
740
- useAdditionalDayOfYearTokens: true,
741
- });
742
- expect(result).toEqual('1986-04-94');
743
- });
744
-
745
- it('throws an error if YY token is used', () => {
746
- expect(() => format(date, 'YY-MM-dd')).toThrow('Use `yy` instead of `YY`');
747
- });
748
-
749
- it('allows YY token if useAdditionalWeekYearTokens is set to true', () => {
750
- const result = format(date, 'YY-MM-dd', {
751
- useAdditionalWeekYearTokens: true,
752
- });
753
- expect(result).toEqual('86-04-04');
754
- });
755
-
756
- it('throws an error if YYYY token is used', () => {
757
- expect(() => format(date, 'YYYY-MM-dd')).toThrow('Use `yyyy` instead of `YYYY`');
758
- });
759
-
760
- it('allows YYYY token if useAdditionalWeekYearTokens is set to true', () => {
761
- const result = format(date, 'YYYY-MM-dd', {
762
- useAdditionalWeekYearTokens: true,
763
- });
764
- expect(result).toEqual('1986-04-04');
765
- });
766
-
767
- describe('console.warn', () => {
768
- let warn: SpyInstance;
769
-
770
- beforeEach(() => {
771
- warn = vi.spyOn(console, 'warn').mockImplementation(() => undefined);
772
- });
773
-
774
- afterEach(() => {
775
- warn.mockRestore();
776
- });
777
-
778
- it('warns if "D" token is used', () => {
779
- try {
780
- format(date, 'yyyy-MM-D');
781
- } catch (_) {
782
- // Ignore the error
783
- }
784
- expect(warn).toBeCalledWith(
785
- 'Use `d` instead of `D` (in `yyyy-MM-D`) for formatting days of the month to the input `' +
786
- date +
787
- '`; see: https://github.com/date-fns/date-fns/blob/master/docs/unicodeTokens.md',
788
- );
789
- });
790
-
791
- it('warns if "DD" token is used', () => {
792
- try {
793
- format(date, 'yyyy-MM-DD');
794
- } catch (_) {
795
- // Ignore the error
796
- }
797
- expect(warn).toBeCalledWith(
798
- 'Use `dd` instead of `DD` (in `yyyy-MM-DD`) for formatting days of the month to the input `' +
799
- date +
800
- '`; see: https://github.com/date-fns/date-fns/blob/master/docs/unicodeTokens.md',
801
- );
802
- });
803
-
804
- it('warns if "DDD" token is used', () => {
805
- try {
806
- format(date, 'yyyy-MM-DDD');
807
- } catch (_) {
808
- // Ignore the error
809
- }
810
- expect(warn).toBeCalledWith(
811
- 'Use `ddd` instead of `DDD` (in `yyyy-MM-DDD`) for formatting days of the month to the input `' +
812
- date +
813
- '`; see: https://github.com/date-fns/date-fns/blob/master/docs/unicodeTokens.md',
814
- );
815
- });
816
-
817
- it('warns if "DDDD" token is used', () => {
818
- try {
819
- format(date, 'yyyy-MM-DDDD');
820
- } catch (_) {
821
- // Ignore the error
822
- }
823
- expect(warn).toBeCalledWith(
824
- 'Use `dddd` instead of `DDDD` (in `yyyy-MM-DDDD`) for formatting days of the month to the input `' +
825
- date +
826
- '`; see: https://github.com/date-fns/date-fns/blob/master/docs/unicodeTokens.md',
827
- );
828
- });
829
-
830
- it('warns if "DDDDD" token is used', () => {
831
- try {
832
- format(date, 'yyyy-MM-DDDDD');
833
- } catch (_) {
834
- // Ignore the error
835
- }
836
- expect(warn).toBeCalledWith(
837
- 'Use `ddddd` instead of `DDDDD` (in `yyyy-MM-DDDDD`) for formatting days of the month to the input `' +
838
- date +
839
- '`; see: https://github.com/date-fns/date-fns/blob/master/docs/unicodeTokens.md',
840
- );
841
- });
842
-
843
- it('warns if "Y" token is used', () => {
844
- try {
845
- format(date, 'Y-MM-dd');
846
- } catch (_) {
847
- // Ignore the error
848
- }
849
- expect(warn).toBeCalledWith(
850
- 'Use `y` instead of `Y` (in `Y-MM-dd`) for formatting years to the input `' +
851
- date +
852
- '`; see: https://github.com/date-fns/date-fns/blob/master/docs/unicodeTokens.md',
853
- );
854
- });
855
-
856
- it('warns if "YY" token is used', () => {
857
- try {
858
- format(date, 'YY-MM-dd');
859
- } catch (_) {
860
- // Ignore the error
861
- }
862
- expect(warn).toBeCalledWith(
863
- 'Use `yy` instead of `YY` (in `YY-MM-dd`) for formatting years to the input `' +
864
- date +
865
- '`; see: https://github.com/date-fns/date-fns/blob/master/docs/unicodeTokens.md',
866
- );
867
- });
868
-
869
- it('warns if "YYY" token is used', () => {
870
- try {
871
- format(date, 'YYY-MM-dd');
872
- } catch (_) {
873
- // Ignore the error
874
- }
875
- expect(warn).toBeCalledWith(
876
- 'Use `yyy` instead of `YYY` (in `YYY-MM-dd`) for formatting years to the input `' +
877
- date +
878
- '`; see: https://github.com/date-fns/date-fns/blob/master/docs/unicodeTokens.md',
879
- );
880
- });
881
-
882
- it('warns if "YYYY" token is used', () => {
883
- try {
884
- format(date, 'YYYY-MM-dd');
885
- } catch (_) {
886
- // Ignore the error
887
- }
888
- expect(warn).toBeCalledWith(
889
- 'Use `yyyy` instead of `YYYY` (in `YYYY-MM-dd`) for formatting years to the input `' +
890
- date +
891
- '`; see: https://github.com/date-fns/date-fns/blob/master/docs/unicodeTokens.md',
892
- );
893
- });
894
-
895
- it('warns if "YYYYY" token is used', () => {
896
- try {
897
- format(date, 'YYYYY-MM-dd');
898
- } catch (_) {
899
- // Ignore the error
900
- }
901
- expect(warn).toBeCalledWith(
902
- 'Use `yyyyy` instead of `YYYYY` (in `YYYYY-MM-dd`) for formatting years to the input `' +
903
- date +
904
- '`; see: https://github.com/date-fns/date-fns/blob/master/docs/unicodeTokens.md',
905
- );
906
- });
907
- });
908
- });
909
- });