@checkdigit/time 4.0.0-PR.18-81a3 → 4.0.0-PR.18-df76

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 +1 -3
  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
package/README.md CHANGED
@@ -20,7 +20,7 @@ The [`date-fns`](https://date-fns.org) library is included. The only locale curr
20
20
  available functionality as of v3.6.0.
21
21
 
22
22
  Additionally, the [`date-fns-tz`](https://github.com/marnusw/date-fns-tz) library is included. Contains all
23
- available functionality as of v1.3.7 except fp.
23
+ available functionality as of v1.3.7 except that the code in `fp` folder is excluded, which contains functional programming related stuff that is not used at the moment.
24
24
 
25
25
  ### `formatUtc`
26
26
 
@@ -85,5 +85,3 @@ When updating the latest code from the original repositories, except making all
85
85
  - nanosecond support
86
86
 
87
87
  Please search for `[PATCH:]` in the existing codebase.
88
-
89
- The date-fns tests files are renamed from `test.ts` to `test.mts` so that they can be excluded from being processed by builder bundling. It's a workaround until a better approach is available to have unified control over both regular compilation and bundling.
package/package.json CHANGED
@@ -1 +1 @@
1
- {"name":"@checkdigit/time","version":"4.0.0-PR.18-81a3","description":"Standard time handling","author":"Check Digit, LLC","license":"MIT","bugs":{"url":"https://github.com/checkdigit/time/issues"},"homepage":"https://github.com/checkdigit/time#readme","repository":{"type":"git","url":"git+https://github.com/checkdigit/time.git"},"engines":{"node":">=20.11"},"type":"module","sideEffects":false,"exports":{".":{"types":"./dist-types/index.d.ts","import":"./dist-mjs/index.mjs","default":"./dist-mjs/index.mjs"}},"files":["src","dist-types","dist-mjs","!src/**/*.test.ts","!src/**/*.spec.ts","!dist-types/**/*.test.d.ts","!dist-types/**/*.spec.d.ts","!dist-mjs/**/*.test.mjs","!dist-mjs/**/*.spec.mjs","SECURITY.md"],"devDependencies":{"@checkdigit/eslint-config":"^9.2.0","@checkdigit/jest-config":"^6.0.0","@checkdigit/prettier-config":"^5.3.0","@checkdigit/typescript-config":"^7.0.0","@date-fns/utc":"^1.2.0","@js-temporal/polyfill":"^0.4.4","fp-ts":"^2.16.2","js-fns":"^2.5.1","rimraf":"^5.0.5","sinon":"^7.4.1","vitest":"^1.3.1"},"scripts":{"prepublishOnly":"npm run build:dist-types && npm run build:dist-mjs","build:dist-types":"rimraf dist-types && npx builder --type=types --outDir=dist-types","build:dist-mjs":"rimraf dist-mjs && npx builder --type=module --sourceMap --outDir=dist-mjs && node dist-mjs/index.mjs","lint":"eslint --max-warnings 0 --ignore-path .gitignore .","lint:fix":"eslint --ignore-path .gitignore . --fix","prettier":"prettier --ignore-path .gitignore --list-different .","prettier:fix":"prettier --ignore-path .gitignore --write .","test":"npm run ci:compile && npm run ci:test && npm run ci:lint && npm run ci:style","ci:compile":"tsc --noEmit","ci:test":"NODE_OPTIONS=\"--disable-warning ExperimentalWarning --experimental-vm-modules\" jest --coverage=false && vitest --config ./vitest.config.test.ts run","ci:coverage":"NODE_OPTIONS=\"--disable-warning ExperimentalWarning --experimental-vm-modules\" jest --coverage=true && vitest --config ./vitest.config.test.ts run","ci:lint":"npm run lint","ci:style":"npm run prettier"},"jest":{"preset":"@checkdigit/jest-config"},"eslintConfig":{"extends":["@checkdigit/eslint-config"],"ignorePatterns":["src/date-fns/**","src/date-fns-tz/**"]},"prettier":"@checkdigit/prettier-config"}
1
+ {"name":"@checkdigit/time","version":"4.0.0-PR.18-df76","description":"Standard time handling","author":"Check Digit, LLC","license":"MIT","bugs":{"url":"https://github.com/checkdigit/time/issues"},"homepage":"https://github.com/checkdigit/time#readme","repository":{"type":"git","url":"git+https://github.com/checkdigit/time.git"},"engines":{"node":">=20.11"},"type":"module","sideEffects":false,"exports":{".":{"types":"./dist-types/index.d.ts","import":"./dist-mjs/index.mjs","default":"./dist-mjs/index.mjs"}},"files":["src","dist-types","dist-mjs","!src/**/*.test.ts","!src/**/*.spec.ts","!dist-types/**/*.test.d.ts","!dist-types/**/*.spec.d.ts","!dist-mjs/**/*.test.mjs","!dist-mjs/**/*.spec.mjs","SECURITY.md"],"devDependencies":{"@checkdigit/eslint-config":"^9.2.0","@checkdigit/jest-config":"^6.0.0","@checkdigit/prettier-config":"^5.3.0","@checkdigit/typescript-config":"^7.0.1","@js-temporal/polyfill":"^0.4.4","rimraf":"^5.0.5"},"scripts":{"prepublishOnly":"npm run build:dist-types && npm run build:dist-mjs","build:dist-types":"rimraf dist-types && npx builder --type=types --outDir=dist-types","build:dist-mjs":"rimraf dist-mjs && npx builder --type=module --sourceMap --outDir=dist-mjs && node dist-mjs/index.mjs","lint":"eslint --max-warnings 0 --ignore-path .gitignore .","lint:fix":"eslint --ignore-path .gitignore . --fix","prettier":"prettier --ignore-path .gitignore --list-different .","prettier:fix":"prettier --ignore-path .gitignore --write .","test":"npm run ci:compile && npm run ci:test && npm run ci:lint && npm run ci:style","ci:compile":"tsc --noEmit","ci:test":"NODE_OPTIONS=\"--disable-warning ExperimentalWarning --experimental-vm-modules\" jest --coverage=false","ci:coverage":"NODE_OPTIONS=\"--disable-warning ExperimentalWarning --experimental-vm-modules\" jest --coverage=true","ci:lint":"npm run lint","ci:style":"npm run prettier"},"jest":{"preset":"@checkdigit/jest-config"},"eslintConfig":{"extends":["@checkdigit/eslint-config"],"ignorePatterns":["src/date-fns/**","src/date-fns-tz/**"]},"prettier":"@checkdigit/prettier-config"}
@@ -1,12 +0,0 @@
1
- import { describe, expect, it } from 'vitest';
2
- import { addLeadingZeros } from './index';
3
-
4
- describe('addLeadingZeros', () => {
5
- it('adds leading zeros when number has fewer digits than target length', () => {
6
- expect(addLeadingZeros(7, 3)).toBe('007');
7
- expect(addLeadingZeros(7, 2)).toBe('07');
8
- expect(addLeadingZeros(7, 1)).toBe('7');
9
- expect(addLeadingZeros(7, 0)).toBe('7');
10
- expect(addLeadingZeros(7, -1)).toBe('7');
11
- });
12
- });
@@ -1,50 +0,0 @@
1
- import { describe, expect, it } from 'vitest';
2
- import { getRoundingMethod } from '.';
3
-
4
- describe('getRoundingMethod', () => {
5
- it('rounds with truncate by default', () => {
6
- expect(getRoundingMethod(undefined)(2.9)).toBe(2);
7
- expect(getRoundingMethod(undefined)(1.5)).toBe(1);
8
- expect(getRoundingMethod(undefined)(-3.9)).toBe(-3);
9
- expect(getRoundingMethod(undefined)(-14.1)).toBe(-14);
10
- });
11
-
12
- it('allows to specify "trunc" rounding method', () => {
13
- expect(getRoundingMethod('trunc')(2.9)).toBe(2);
14
- expect(getRoundingMethod('trunc')(1.5)).toBe(1);
15
- expect(getRoundingMethod('trunc')(-3.9)).toBe(-3);
16
- expect(getRoundingMethod('trunc')(-14.1)).toBe(-14);
17
- });
18
-
19
- it('allows to specify "ceil" rounding method', () => {
20
- expect(getRoundingMethod('ceil')(2.9)).toBe(3);
21
- expect(getRoundingMethod('ceil')(1.5)).toBe(2);
22
- expect(getRoundingMethod('ceil')(-3.9)).toBe(-3);
23
- expect(getRoundingMethod('ceil')(-14.1)).toBe(-14);
24
- });
25
-
26
- it('allows to specify "floor" rounding method', () => {
27
- expect(getRoundingMethod('floor')(2.9)).toBe(2);
28
- expect(getRoundingMethod('floor')(1.5)).toBe(1);
29
- expect(getRoundingMethod('floor')(-3.9)).toBe(-4);
30
- expect(getRoundingMethod('floor')(-14.1)).toBe(-15);
31
- });
32
-
33
- it('allows to specify "round" rounding method', () => {
34
- expect(getRoundingMethod('round')(2.9)).toBe(3);
35
- expect(getRoundingMethod('round')(1.5)).toBe(2);
36
- expect(getRoundingMethod('round')(-3.9)).toBe(-4);
37
- expect(getRoundingMethod('round')(-14.1)).toBe(-14);
38
- });
39
-
40
- it('prevents negative zero', () => {
41
- expect(!isNegativeZero(getRoundingMethod('trunc')(-0.01))).toBe(true);
42
- expect(!isNegativeZero(getRoundingMethod('floor')(-0.0))).toBe(true);
43
- expect(!isNegativeZero(getRoundingMethod('ceil')(-0.9))).toBe(true);
44
- expect(!isNegativeZero(getRoundingMethod('round')(-0.1))).toBe(true);
45
- });
46
- });
47
-
48
- function isNegativeZero(x: number): boolean {
49
- return x === 0 && 1 / x < 0;
50
- }
@@ -1,25 +0,0 @@
1
- import { describe, expect, it } from 'vitest';
2
- import { getTimezoneOffsetInMilliseconds } from './index';
3
-
4
- describe('getTimezoneOffsetInMilliseconds', () => {
5
- it('works for a modern date', () => {
6
- const date = new Date(2018, 0 /* Jan */, 1, 12, 34, 56, 789);
7
- const result = date.getTime() - getTimezoneOffsetInMilliseconds(date);
8
- const expectedResult = Date.UTC(2018, 0 /* Jan */, 1, 12, 34, 56, 789);
9
- expect(result).toBe(expectedResult);
10
- });
11
-
12
- it('works for a date before standardized timezones', () => {
13
- const date = new Date(1800, 0 /* Jan */, 1, 12, 34, 56, 789);
14
- const result = date.getTime() - getTimezoneOffsetInMilliseconds(date);
15
- const expectedResult = Date.UTC(1800, 0 /* Jan */, 1, 12, 34, 56, 789);
16
- expect(result).toBe(expectedResult);
17
- });
18
-
19
- it('works for a date BC', () => {
20
- const date = new Date(-500, 0 /* Jan */, 1, 12, 34, 56, 789);
21
- const result = date.getTime() - getTimezoneOffsetInMilliseconds(date);
22
- const expectedResult = Date.UTC(-500, 0 /* Jan */, 1, 12, 34, 56, 789);
23
- expect(result).toBe(expectedResult);
24
- });
25
- });
@@ -1,95 +0,0 @@
1
- import { describe, expect, it } from 'vitest';
2
- import { add } from './index';
3
- import { getDstTransitions } from '../_test/dst/tzOffsetTransitions';
4
-
5
- describe('add', () => {
6
- it('adds the values from the given object', () => {
7
- const result = add(new Date(2014, 8 /* Sep */, 1, 10, 19, 50), {
8
- years: 2,
9
- months: 9,
10
- weeks: 1,
11
- days: 7,
12
- hours: 5,
13
- minutes: 9,
14
- seconds: 30,
15
- });
16
- expect(result).toEqual(new Date(2017, 5 /* June */, 15, 15, 29, 20));
17
- });
18
-
19
- it('supports an undefined value in the duration object', () => {
20
- const result = add(new Date(2014, 8 /* Sep */, 1, 10, 19, 50), {
21
- years: undefined,
22
- months: 9,
23
- weeks: 1,
24
- days: 7,
25
- hours: 5,
26
- minutes: 9,
27
- seconds: 30,
28
- });
29
- expect(result).toEqual(new Date(2015, 5 /* June */, 15, 15, 29, 20));
30
- });
31
-
32
- it('returns same date object when passed empty duration values', () => {
33
- const result = add(new Date(2014, 8 /* Sep */, 1, 10).getTime(), {
34
- years: undefined,
35
- months: undefined,
36
- weeks: undefined,
37
- days: undefined,
38
- hours: undefined,
39
- minutes: undefined,
40
- seconds: undefined,
41
- });
42
- expect(result).toEqual(new Date(2014, 8 /* Sep */, 1, 10));
43
- });
44
-
45
- it('returns same date object when passed undefined duration values', () => {
46
- const result = add(new Date(2014, 8 /* Sep */, 1, 10).getTime(), {});
47
- expect(result).toEqual(new Date(2014, 8 /* Sep */, 1, 10));
48
- });
49
-
50
- it('accepts a timestamp', () => {
51
- const result = add(new Date(2014, 8 /* Sep */, 1, 10).getTime(), {
52
- hours: 4,
53
- });
54
- expect(result).toEqual(new Date(2014, 8 /* Sep */, 1, 14));
55
- });
56
-
57
- it('does not mutate the original date', () => {
58
- const date = new Date(2014, 8 /* Sep */, 1, 10);
59
- add(date, { hours: 4 });
60
- expect(date).toEqual(new Date(2014, 8 /* Sep */, 1, 10));
61
- });
62
-
63
- it('works well if the desired month has fewer days and the provided date is in the last day of a month', () => {
64
- const date = new Date(2014, 11 /* Dec */, 31);
65
- const result = add(date, { months: 9 });
66
- expect(result).toEqual(new Date(2015, 8 /* Sep */, 30));
67
- });
68
-
69
- const dstTransitions = getDstTransitions(2017);
70
- const dstOnly = dstTransitions.start && dstTransitions.end ? it : it.skip;
71
- const tz = Intl.DateTimeFormat().resolvedOptions().timeZone || process.env.tz;
72
- const HOUR = 1000 * 60 * 60;
73
-
74
- dstOnly(`works at DST-end boundary in local timezone: ${tz || '(unknown)'}`, () => {
75
- const date = dstTransitions.end;
76
- const result = add(date!, { hours: 1 });
77
- expect(result).toEqual(new Date(date!.getTime() + HOUR));
78
- });
79
-
80
- it('handles dates before 100 AD', () => {
81
- const initialDate = new Date(0);
82
- initialDate.setFullYear(-1, 10 /* Nov */, 30);
83
- initialDate.setHours(0, 0, 0, 0);
84
- const expectedResult = new Date(0);
85
- expectedResult.setFullYear(0, 1 /* Feb */, 29);
86
- expectedResult.setHours(0, 0, 0, 0);
87
- const result = add(initialDate, { months: 3 });
88
- expect(result).toEqual(expectedResult);
89
- });
90
-
91
- it('returns `Invalid Date` if the given date is invalid', () => {
92
- const result = add(new Date(NaN), { hours: 5 });
93
- expect(result instanceof Date && isNaN(result.getTime())).toBe(true);
94
- });
95
- });
@@ -1,78 +0,0 @@
1
- import { describe, expect, it } from 'vitest';
2
- import { addBusinessDays } from './index';
3
-
4
- describe('addBusinessDays', () => {
5
- it('adds the given number of business days', () => {
6
- const result = addBusinessDays(new Date(2014, 8 /* Sep */, 1), 10);
7
- expect(result).toEqual(new Date(2014, 8 /* Sep */, 15));
8
- });
9
-
10
- it('handles negative amount', () => {
11
- const result = addBusinessDays(new Date(2014, 8 /* Sep */, 15), -10);
12
- expect(result).toEqual(new Date(2014, 8 /* Sep */, 1));
13
- });
14
-
15
- it('returns the Monday when 1 day is added on the Friday', () => {
16
- expect(addBusinessDays(new Date(2020, 0 /* Jan */, 10), 1)).toEqual(
17
- // Friday
18
- // Monday
19
- new Date(2020, 0 /* Jan */, 13),
20
- );
21
- });
22
-
23
- it('returns the Monday when 1 day is added on the Satuday', () => {
24
- expect(addBusinessDays(new Date(2020, 0 /* Jan */, 11), 1)).toEqual(
25
- // Saturday
26
- // Monday
27
- new Date(2020, 0 /* Jan */, 13),
28
- );
29
- });
30
-
31
- it('returns the Monday when 1 day is added on the Sunday', () => {
32
- expect(addBusinessDays(new Date(2020, 0 /* Jan */, 12), 1)).toEqual(
33
- // Sunday
34
- // Monday
35
- new Date(2020, 0 /* Jan */, 13),
36
- );
37
- });
38
-
39
- it('can handle a large number of business days', () => {
40
- const result = addBusinessDays(new Date(2014, 0 /* Jan */, 1), 3387885);
41
- expect(result).toEqual(new Date(15000, 0 /* Jan */, 1));
42
- });
43
-
44
- it('accepts a timestamp', () => {
45
- const result = addBusinessDays(new Date(2014, 8 /* Sep */, 1).getTime(), 10);
46
- expect(result).toEqual(new Date(2014, 8 /* Sep */, 15));
47
- });
48
-
49
- it('does not mutate the original date', () => {
50
- const date = new Date(2014, 8 /* Sep */, 1);
51
- addBusinessDays(date, 11);
52
- expect(date).toEqual(new Date(2014, 8 /* Sep */, 1));
53
- });
54
-
55
- it('returns `Invalid Date` if the given date is invalid', () => {
56
- const result = addBusinessDays(new Date(NaN), 10);
57
- expect(result instanceof Date && isNaN(result.getTime())).toBe(true);
58
- });
59
-
60
- it('returns `Invalid Date` if the given amount is NaN', () => {
61
- const result = addBusinessDays(new Date(2014, 8 /* Sep */, 1), NaN);
62
- expect(result instanceof Date && isNaN(result.getTime())).toBe(true);
63
- });
64
-
65
- it('starting from a weekend day should land on a weekday when reducing a divisible by 5', () => {
66
- const substractResult = addBusinessDays(new Date(2019, 7, 18), -5);
67
- expect(substractResult).toEqual(new Date(2019, 7, 12));
68
-
69
- const subtractResultWeekend = addBusinessDays(new Date(2019, 7, 17), -5);
70
- expect(subtractResultWeekend).toEqual(new Date(2019, 7, 12));
71
-
72
- const addResult = addBusinessDays(new Date(2019, 7, 18), 5);
73
- expect(addResult).toEqual(new Date(2019, 7, 23));
74
-
75
- const addResultWeekend = addBusinessDays(new Date(2019, 7, 17), 5);
76
- expect(addResultWeekend).toEqual(new Date(2019, 7, 23));
77
- });
78
- });
@@ -1,90 +0,0 @@
1
- import { describe, expect, it } from 'vitest';
2
- import { addDays } from './index';
3
- import { getDstTransitions } from '../_test/dst/tzOffsetTransitions';
4
-
5
- describe('addDays', () => {
6
- it('adds the given number of days', () => {
7
- const result = addDays(new Date(2014, 8 /* Sep */, 1), 10);
8
- expect(result).toEqual(new Date(2014, 8 /* Sep */, 11));
9
- });
10
-
11
- it('accepts a timestamp', () => {
12
- const result = addDays(new Date(2014, 8 /* Sep */, 1).getTime(), 10);
13
- expect(result).toEqual(new Date(2014, 8 /* Sep */, 11));
14
- });
15
-
16
- it('does not mutate the original date', () => {
17
- const date = new Date(2014, 8 /* Sep */, 1);
18
- addDays(date, 11);
19
- expect(date).toEqual(new Date(2014, 8 /* Sep */, 1));
20
- });
21
-
22
- it('returns `Invalid Date` if the given date is invalid', () => {
23
- const result = addDays(new Date(NaN), 10);
24
- expect(result instanceof Date && isNaN(result.getTime())).toBe(true);
25
- });
26
-
27
- it('returns `Invalid Date` if the given amount is NaN', () => {
28
- const result = addDays(new Date(2014, 8 /* Sep */, 1), NaN);
29
- expect(result instanceof Date && isNaN(result.getTime())).toBe(true);
30
- });
31
-
32
- const dstTransitions = getDstTransitions(2017);
33
- const dstOnly = dstTransitions.start && dstTransitions.end ? it : it.skip;
34
- const tz = Intl.DateTimeFormat().resolvedOptions().timeZone || process.env.tz;
35
- const HOUR = 1000 * 60 * 60;
36
- const MINUTE = 1000 * 60;
37
- // It's usually 1 hour, but for some timezones, e.g. Australia/Lord_Howe, it is 30 minutes
38
- const dstOffset =
39
- dstTransitions.start && dstTransitions.end
40
- ? (dstTransitions.end.getTimezoneOffset() - dstTransitions.start.getTimezoneOffset()) * MINUTE
41
- : NaN;
42
-
43
- dstOnly(`works at DST-start boundary in local timezone: ${tz || '(unknown)'}`, () => {
44
- const date = dstTransitions.start;
45
- const result = addDays(date!, 1);
46
- expect(result).toEqual(new Date(date!.getTime() + 24 * HOUR));
47
- });
48
-
49
- dstOnly(`works at DST-start - 30 mins in local timezone: ${tz || '(unknown)'}`, () => {
50
- const date = new Date(dstTransitions.start!.getTime() - 0.5 * HOUR);
51
- const result = addDays(date, 1);
52
- // started before the transition so will only be 23 hours later in local time
53
- expect(result).toEqual(new Date(date.getTime() + 24 * HOUR - dstOffset));
54
- });
55
-
56
- dstOnly(`works at DST-start - 60 mins in local timezone: ${tz || '(unknown)'}`, () => {
57
- const date = new Date(dstTransitions.start!.getTime() - 1 * HOUR);
58
- const result = addDays(date, 1);
59
- // started before the transition so will only be 23 hours later in local time
60
- expect(result).toEqual(new Date(date.getTime() + 24 * HOUR - dstOffset));
61
- });
62
-
63
- dstOnly(`works at DST-end boundary in local timezone: ${tz || '(unknown)'}`, () => {
64
- const date = dstTransitions.end;
65
- const result = addDays(date!, 1);
66
- expect(result).toEqual(new Date(date!.getTime() + 24 * HOUR));
67
- });
68
-
69
- dstOnly(`works at DST-end - 30 mins in local timezone: ${tz || '(unknown)'}`, () => {
70
- const date = new Date(dstTransitions.end!.getTime() - 0.5 * HOUR);
71
- const result = addDays(date, 1);
72
- // started before the transition so will be 25 hours later in local
73
- // time because one hour repeats after DST ends.
74
- expect(result).toEqual(new Date(date.getTime() + 24 * HOUR + dstOffset));
75
- });
76
-
77
- dstOnly(`works at DST-end - 60 mins in local timezone: ${tz || '(unknown)'}`, () => {
78
- const date = new Date(dstTransitions.end!.getTime() - 1 * HOUR);
79
- const result = addDays(date, 1);
80
- // started before the transition so will be 25 hours later in local
81
- // time because one hour repeats after DST ends.
82
- expect(result).toEqual(new Date(date.getTime() + 24 * HOUR + dstOffset));
83
- });
84
-
85
- dstOnly(`doesn't mutate if zero increment is used: ${tz || '(unknown)'}`, () => {
86
- const date = new Date(dstTransitions.end!);
87
- const result = addDays(date, 0);
88
- expect(result).toEqual(date);
89
- });
90
- });
@@ -1,30 +0,0 @@
1
- import { describe, expect, it } from 'vitest';
2
- import { addHours } from './index';
3
-
4
- describe('addHours', () => {
5
- it('adds the given numbers of hours', () => {
6
- const result = addHours(new Date(2014, 6 /* Jul */, 10, 23, 0), 2);
7
- expect(result).toEqual(new Date(2014, 6 /* Jul */, 11, 1, 0));
8
- });
9
-
10
- it('accepts a timestamp', () => {
11
- const result = addHours(new Date(2014, 6 /* Jul */, 10, 23, 0).getTime(), 26);
12
- expect(result).toEqual(new Date(2014, 6 /* Jul */, 12, 1, 0));
13
- });
14
-
15
- it('does not mutate the original date', () => {
16
- const date = new Date(2014, 6 /* Jul */, 10, 23, 0);
17
- addHours(date, 10);
18
- expect(date).toEqual(new Date(2014, 6 /* Jul */, 10, 23, 0));
19
- });
20
-
21
- it('returns `Invalid Date` if the given date is invalid', () => {
22
- const result = addHours(new Date(NaN), 2);
23
- expect(result instanceof Date && isNaN(result.getTime())).toBe(true);
24
- });
25
-
26
- it('returns `Invalid Date` if the given amount is NaN', () => {
27
- const result = addHours(new Date(2014, 6 /* Jul */, 10, 23, 0), NaN);
28
- expect(result instanceof Date && isNaN(result.getTime())).toBe(true);
29
- });
30
- });
@@ -1,41 +0,0 @@
1
- import { describe, expect, it } from 'vitest';
2
- import { addISOWeekYears } from './index';
3
-
4
- describe('addISOWeekYears', () => {
5
- it('adds the given number of ISO week-numbering years', () => {
6
- const result = addISOWeekYears(new Date(2010, 6 /* Jul */, 2), 5);
7
- expect(result).toEqual(new Date(2015, 5 /* Jun */, 26));
8
- });
9
-
10
- it('accepts a timestamp', () => {
11
- const result = addISOWeekYears(new Date(2014, 8 /* Sep */, 1).getTime(), 12);
12
- expect(result).toEqual(new Date(2026, 7 /* Aug */, 31));
13
- });
14
-
15
- it('does not mutate the original date', () => {
16
- const date = new Date(2014, 8 /* Sep */, 1);
17
- addISOWeekYears(date, 12);
18
- expect(date).toEqual(new Date(2014, 8 /* Sep */, 1));
19
- });
20
-
21
- it('handles dates before 100 AD', () => {
22
- const initialDate = new Date(0);
23
- initialDate.setFullYear(10, 6 /* Jul */, 2);
24
- initialDate.setHours(0, 0, 0, 0);
25
- const expectedResult = new Date(0);
26
- expectedResult.setFullYear(15, 5 /* Jun */, 26);
27
- expectedResult.setHours(0, 0, 0, 0);
28
- const result = addISOWeekYears(initialDate, 5);
29
- expect(result).toEqual(expectedResult);
30
- });
31
-
32
- it('returns `Invalid Date` if the given date is invalid', () => {
33
- const result = addISOWeekYears(new Date(NaN), 5);
34
- expect(result instanceof Date && isNaN(result.getTime())).toBe(true);
35
- });
36
-
37
- it('returns `Invalid Date` if the given amount is NaN', () => {
38
- const result = addISOWeekYears(new Date(2010, 6 /* Jul */, 2), NaN);
39
- expect(result instanceof Date && isNaN(result.getTime())).toBe(true);
40
- });
41
- });
@@ -1,30 +0,0 @@
1
- import { describe, expect, it } from 'vitest';
2
- import { addMilliseconds } from './index';
3
-
4
- describe('addMilliseconds', () => {
5
- it('adds the given number of milliseconds', () => {
6
- const result = addMilliseconds(new Date(2014, 6 /* Jul */, 10, 12, 45, 30, 0), 750);
7
- expect(result).toEqual(new Date(2014, 6 /* Jul */, 10, 12, 45, 30, 750));
8
- });
9
-
10
- it('accepts a timestamp', () => {
11
- const result = addMilliseconds(new Date(2014, 6 /* Jul */, 10, 12, 45, 30, 0).getTime(), 500);
12
- expect(result).toEqual(new Date(2014, 6 /* Jul */, 10, 12, 45, 30, 500));
13
- });
14
-
15
- it('does not mutate the original date', () => {
16
- const date = new Date(2014, 6 /* Jul */, 10, 12, 45, 30, 0);
17
- addMilliseconds(date, 250);
18
- expect(date).toEqual(new Date(2014, 6 /* Jul */, 10, 12, 45, 30, 0));
19
- });
20
-
21
- it('returns `Invalid Date` if the given date is invalid', () => {
22
- const result = addMilliseconds(new Date(NaN), 750);
23
- expect(result instanceof Date && isNaN(result.getTime())).toBe(true);
24
- });
25
-
26
- it('returns `Invalid Date` if the given amount is NaN', () => {
27
- const result = addMilliseconds(new Date(2014, 6 /* Jul */, 10, 12, 45, 30, 0), NaN);
28
- expect(result instanceof Date && isNaN(result.getTime())).toBe(true);
29
- });
30
- });
@@ -1,30 +0,0 @@
1
- import { describe, expect, it } from 'vitest';
2
- import { addMinutes } from './index';
3
-
4
- describe('addMinutes', () => {
5
- it('adds the given number of minutes', () => {
6
- const result = addMinutes(new Date(2014, 6 /* Jul */, 10, 12, 0), 30);
7
- expect(result).toEqual(new Date(2014, 6 /* Jul */, 10, 12, 30));
8
- });
9
-
10
- it('accepts a timestamp', () => {
11
- const result = addMinutes(new Date(2014, 6 /* Jul */, 10, 12, 0).getTime(), 20);
12
- expect(result).toEqual(new Date(2014, 6 /* Jul */, 10, 12, 20));
13
- });
14
-
15
- it('does not mutate the original date', () => {
16
- const date = new Date(2014, 6 /* Jul */, 10, 12, 0);
17
- addMinutes(date, 25);
18
- expect(date).toEqual(new Date(2014, 6 /* Jul */, 10, 12, 0));
19
- });
20
-
21
- it('returns `Invalid Date` if the given date is invalid', () => {
22
- const result = addMinutes(new Date(NaN), 30);
23
- expect(result instanceof Date && isNaN(result.getTime())).toBe(true);
24
- });
25
-
26
- it('returns `Invalid Date` if the given amount is NaN', () => {
27
- const result = addMinutes(new Date(2014, 6 /* Jul */, 10, 12, 0), NaN);
28
- expect(result instanceof Date && isNaN(result.getTime())).toBe(true);
29
- });
30
- });
@@ -1,123 +0,0 @@
1
- import { describe, expect, it } from 'vitest';
2
- import { addMonths } from './index';
3
- import { getDstTransitions } from '../_test/dst/tzOffsetTransitions';
4
-
5
- describe('addMonths', () => {
6
- it('adds the given number of months', () => {
7
- const result = addMonths(new Date(2014, 8 /* Sep */, 1), 5);
8
- expect(result).toEqual(new Date(2015, 1 /* Feb */, 1));
9
- });
10
-
11
- it('accepts a timestamp', () => {
12
- const result = addMonths(new Date(2014, 8 /* Sep */, 1).getTime(), 12);
13
- expect(result).toEqual(new Date(2015, 8 /* Sep */, 1));
14
- });
15
-
16
- it('does not mutate the original date', () => {
17
- const date = new Date(2014, 8 /* Sep */, 1);
18
- addMonths(date, 12);
19
- expect(date).toEqual(new Date(2014, 8 /* Sep */, 1));
20
- });
21
-
22
- it('works well if the desired month has fewer days and the provided date is in the last day of a month', () => {
23
- const date = new Date(2014, 11 /* Dec */, 31);
24
- const result = addMonths(date, 2);
25
- expect(result).toEqual(new Date(2015, 1 /* Feb */, 28));
26
- });
27
-
28
- it('handles dates before 100 AD', () => {
29
- const initialDate = new Date(0);
30
- initialDate.setFullYear(0, 0 /* Jan */, 31);
31
- initialDate.setHours(0, 0, 0, 0);
32
- const expectedResult = new Date(0);
33
- expectedResult.setFullYear(0, 1 /* Feb */, 29);
34
- expectedResult.setHours(0, 0, 0, 0);
35
- const result = addMonths(initialDate, 1);
36
- expect(result).toEqual(expectedResult);
37
- });
38
-
39
- it('returns `Invalid Date` if the given date is invalid', () => {
40
- const result = addMonths(new Date(NaN), 5);
41
- expect(result instanceof Date && isNaN(result.getTime())).toBe(true);
42
- });
43
-
44
- it('returns `Invalid Date` if the given amount is NaN', () => {
45
- const result = addMonths(new Date(2014, 8 /* Sep */, 1), NaN);
46
- expect(result instanceof Date && isNaN(result.getTime())).toBe(true);
47
- });
48
-
49
- const dstTransitions = getDstTransitions(2017);
50
- const dstOnly = dstTransitions.start && dstTransitions.end ? it : it.skip;
51
- const tz = Intl.DateTimeFormat().resolvedOptions().timeZone || process.env.tz;
52
- const HOUR = 1000 * 60 * 60;
53
- const override = (
54
- base: Date,
55
- year = base.getFullYear(),
56
- month = base.getMonth(),
57
- day = base.getDate(),
58
- hour = base.getHours(),
59
- minute = base.getMinutes(),
60
- ) => new Date(year, month, day, hour, minute);
61
-
62
- dstOnly(`works at DST-start boundary in local timezone: ${tz || '(unknown)'}`, () => {
63
- const date = dstTransitions.start;
64
- const result = addMonths(date!, 2);
65
- expect(result).toEqual(override(date!, date!.getFullYear(), date!.getMonth() + 2));
66
- });
67
-
68
- dstOnly(`works at DST-start - 30 mins in local timezone: ${tz || '(unknown)'}`, () => {
69
- const date = new Date(dstTransitions.start!.getTime() - 0.5 * HOUR);
70
- const result = addMonths(date, 2);
71
- const expected = override(date, date.getFullYear(), date.getMonth() + 2);
72
- expect(result).toEqual(expected);
73
- });
74
-
75
- dstOnly(`works at DST-start - 60 mins in local timezone: ${tz || '(unknown)'}`, () => {
76
- const date = new Date(dstTransitions.start!.getTime() - 1 * HOUR);
77
- const result = addMonths(date, 2);
78
- const expected = override(date, date.getFullYear(), date.getMonth() + 2);
79
- expect(result).toEqual(expected);
80
- });
81
-
82
- dstOnly(`works at DST-end boundary in local timezone: ${tz || '(unknown)'}`, () => {
83
- const date = dstTransitions.end;
84
- const result = addMonths(date!, 2);
85
- expect(result).toEqual(
86
- override(
87
- date!,
88
- date!.getFullYear() + (date!.getMonth() >= 10 ? 1 : 0),
89
- (date!.getMonth() + 2) % 12, // protect against wrap for Nov.
90
- ),
91
- );
92
- });
93
-
94
- dstOnly(`works at DST-end - 30 mins in local timezone: ${tz || '(unknown)'}`, () => {
95
- const date = new Date(dstTransitions.end!.getTime() - 0.5 * HOUR);
96
- const result = addMonths(date, 2);
97
- expect(result).toEqual(
98
- override(
99
- date,
100
- date.getFullYear() + (date.getMonth() >= 10 ? 1 : 0),
101
- (date.getMonth() + 2) % 12, // protect against wrap for Nov.
102
- ),
103
- );
104
- });
105
-
106
- dstOnly(`works at DST-end - 60 mins in local timezone: ${tz || '(unknown)'}`, () => {
107
- const date = new Date(dstTransitions.end!.getTime() - 1 * HOUR);
108
- const result = addMonths(date, 2);
109
- expect(result).toEqual(
110
- override(
111
- date,
112
- date.getFullYear() + (date.getMonth() >= 10 ? 1 : 0),
113
- (date.getMonth() + 2) % 12, // protect against wrap for Nov.
114
- ),
115
- );
116
- });
117
-
118
- dstOnly(`doesn't mutate if zero increment is used: ${tz || '(unknown)'}`, () => {
119
- const date = new Date(dstTransitions.end!);
120
- const result = addMonths(date, 0);
121
- expect(result).toEqual(date);
122
- });
123
- });