@powerlines/plugin-date 0.12.67 → 0.12.68

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 (184) hide show
  1. package/dist/_virtual/rolldown_runtime.cjs +1 -0
  2. package/dist/{chunk-BGGBqwuQ.mjs → _virtual/rolldown_runtime.mjs} +1 -1
  3. package/dist/alloy/src/core/components/output.cjs +1 -0
  4. package/dist/alloy/src/core/components/output.mjs +1 -0
  5. package/dist/alloy/src/core/components/single-line-comment.cjs +1 -0
  6. package/dist/alloy/src/core/components/single-line-comment.mjs +1 -0
  7. package/dist/alloy/src/core/components/source-file.cjs +1 -0
  8. package/dist/alloy/src/core/components/source-file.mjs +1 -0
  9. package/dist/alloy/src/core/contexts/context.cjs +1 -0
  10. package/dist/alloy/src/core/contexts/context.mjs +1 -0
  11. package/dist/alloy/src/core/contexts/reflection.cjs +1 -0
  12. package/dist/alloy/src/core/contexts/reflection.mjs +1 -0
  13. package/dist/alloy/src/create-plugin.cjs +2 -0
  14. package/dist/alloy/src/create-plugin.mjs +2 -0
  15. package/dist/alloy/src/helpers/refkey.cjs +1 -0
  16. package/dist/alloy/src/helpers/refkey.mjs +1 -0
  17. package/dist/alloy/src/markdown/components/markdown-file.cjs +1 -0
  18. package/dist/alloy/src/markdown/components/markdown-file.mjs +1 -0
  19. package/dist/alloy/src/markdown/components/markdown-table.cjs +1 -0
  20. package/dist/alloy/src/markdown/components/markdown-table.mjs +1 -0
  21. package/dist/alloy/src/markdown/contexts/markdown-table.cjs +1 -0
  22. package/dist/alloy/src/markdown/contexts/markdown-table.mjs +1 -0
  23. package/dist/alloy/src/typescript/components/builtin-file.cjs +1 -0
  24. package/dist/alloy/src/typescript/components/builtin-file.mjs +1 -0
  25. package/dist/alloy/src/typescript/components/tsdoc-reflection.cjs +1 -0
  26. package/dist/alloy/src/typescript/components/tsdoc-reflection.mjs +1 -0
  27. package/dist/alloy/src/typescript/components/tsdoc.cjs +1 -0
  28. package/dist/alloy/src/typescript/components/tsdoc.mjs +1 -0
  29. package/dist/alloy/src/typescript/components/typescript-file.cjs +1 -0
  30. package/dist/alloy/src/typescript/components/typescript-file.mjs +1 -0
  31. package/dist/alloy/src/typescript/components/typescript-interface.cjs +1 -0
  32. package/dist/alloy/src/typescript/components/typescript-interface.mjs +1 -0
  33. package/dist/alloy/src/typescript/components/typescript-object.cjs +1 -0
  34. package/dist/alloy/src/typescript/components/typescript-object.mjs +1 -0
  35. package/dist/components/date-fns.cjs +513 -0
  36. package/dist/components/date-fns.d.cts +13 -0
  37. package/dist/components/date-fns.d.mts +13 -0
  38. package/dist/components/date-fns.mjs +513 -0
  39. package/dist/components/dayjs.cjs +458 -0
  40. package/dist/components/dayjs.d.cts +13 -0
  41. package/dist/components/dayjs.d.mts +13 -0
  42. package/dist/components/dayjs.mjs +458 -0
  43. package/dist/components/index.cjs +1 -0
  44. package/dist/components/index.d.mts +4 -0
  45. package/dist/components/index.mjs +1 -0
  46. package/dist/components/luxon.cjs +462 -0
  47. package/dist/components/luxon.d.cts +13 -0
  48. package/dist/components/luxon.d.mts +13 -0
  49. package/dist/components/luxon.mjs +462 -0
  50. package/dist/components/moment.cjs +448 -0
  51. package/dist/components/moment.d.cts +13 -0
  52. package/dist/components/moment.d.mts +13 -0
  53. package/dist/components/moment.mjs +448 -0
  54. package/dist/deepkit/schemas/reflection.cjs +1 -0
  55. package/dist/deepkit/schemas/reflection.d.cts +1560 -0
  56. package/dist/deepkit/schemas/reflection.d.mts +1560 -0
  57. package/dist/deepkit/schemas/reflection.mjs +1 -0
  58. package/dist/deepkit/schemas/reflection2.cjs +1 -0
  59. package/dist/deepkit/schemas/reflection2.mjs +1 -0
  60. package/dist/deepkit/src/capnp.cjs +1 -0
  61. package/dist/deepkit/src/capnp.mjs +1 -0
  62. package/dist/deepkit/src/reflect-type.cjs +1 -0
  63. package/dist/deepkit/src/reflect-type.mjs +1 -0
  64. package/dist/deepkit/src/resolve-reflections.cjs +1 -0
  65. package/dist/deepkit/src/resolve-reflections.mjs +1 -0
  66. package/dist/deepkit/src/types.d.cts +10 -0
  67. package/dist/deepkit/src/types.d.mts +10 -0
  68. package/dist/deepkit/src/utilities.cjs +1 -0
  69. package/dist/deepkit/src/utilities.mjs +1 -0
  70. package/dist/deepkit/src/vendor/type.cjs +1 -0
  71. package/dist/deepkit/src/vendor/type.d.cts +7 -0
  72. package/dist/deepkit/src/vendor/type.d.mts +7 -0
  73. package/dist/deepkit/src/vendor/type.mjs +1 -0
  74. package/dist/index.cjs +1 -1953
  75. package/dist/index.d.cts +7 -40
  76. package/dist/index.d.mts +9 -40
  77. package/dist/index.mjs +1 -1950
  78. package/dist/plugin-babel/src/helpers/ast-utils.cjs +1 -0
  79. package/dist/plugin-babel/src/helpers/ast-utils.mjs +1 -0
  80. package/dist/plugin-babel/src/helpers/create-plugin.cjs +1 -0
  81. package/dist/plugin-babel/src/helpers/create-plugin.mjs +1 -0
  82. package/dist/plugin-babel/src/helpers/filters.cjs +1 -0
  83. package/dist/plugin-babel/src/helpers/filters.mjs +1 -0
  84. package/dist/plugin-babel/src/helpers/index.cjs +1 -0
  85. package/dist/plugin-babel/src/helpers/index.mjs +1 -0
  86. package/dist/plugin-babel/src/helpers/module-helpers.cjs +1 -0
  87. package/dist/plugin-babel/src/helpers/module-helpers.mjs +1 -0
  88. package/dist/plugin-babel/src/helpers/options.cjs +1 -0
  89. package/dist/plugin-babel/src/helpers/options.mjs +1 -0
  90. package/dist/plugin-babel/src/index.cjs +1 -0
  91. package/dist/plugin-babel/src/index.mjs +1 -0
  92. package/dist/plugin-babel/src/types/index.d.mts +1 -0
  93. package/dist/plugin-babel/src/types/plugin.d.cts +15 -0
  94. package/dist/plugin-babel/src/types/plugin.d.mts +15 -0
  95. package/dist/plugin-env/src/babel/index.cjs +1 -0
  96. package/dist/plugin-env/src/babel/index.mjs +1 -0
  97. package/dist/plugin-env/src/babel/plugin.cjs +5 -0
  98. package/dist/plugin-env/src/babel/plugin.mjs +5 -0
  99. package/dist/plugin-env/src/components/docs.cjs +1 -0
  100. package/dist/plugin-env/src/components/docs.mjs +1 -0
  101. package/dist/plugin-env/src/components/env.cjs +34 -0
  102. package/dist/plugin-env/src/components/env.mjs +31 -0
  103. package/dist/plugin-env/src/components/index.cjs +1 -0
  104. package/dist/plugin-env/src/components/index.mjs +1 -0
  105. package/dist/plugin-env/src/helpers/create-reflection-resource.cjs +1 -0
  106. package/dist/plugin-env/src/helpers/create-reflection-resource.mjs +1 -0
  107. package/dist/plugin-env/src/helpers/index.cjs +1 -0
  108. package/dist/plugin-env/src/helpers/index.mjs +1 -0
  109. package/dist/plugin-env/src/helpers/load.cjs +1 -0
  110. package/dist/plugin-env/src/helpers/load.mjs +1 -0
  111. package/dist/plugin-env/src/helpers/persistence.cjs +1 -0
  112. package/dist/plugin-env/src/helpers/persistence.mjs +1 -0
  113. package/dist/plugin-env/src/helpers/reflect.cjs +1 -0
  114. package/dist/plugin-env/src/helpers/reflect.mjs +1 -0
  115. package/dist/plugin-env/src/helpers/source-file-env.cjs +1 -0
  116. package/dist/plugin-env/src/helpers/source-file-env.mjs +1 -0
  117. package/dist/plugin-env/src/helpers/template-helpers.cjs +1 -0
  118. package/dist/plugin-env/src/helpers/template-helpers.mjs +1 -0
  119. package/dist/plugin-env/src/index.cjs +16 -0
  120. package/dist/plugin-env/src/index.mjs +16 -0
  121. package/dist/plugin-env/src/types/plugin.d.cts +135 -0
  122. package/dist/plugin-env/src/types/plugin.d.mts +136 -0
  123. package/dist/plugin-env/src/types/runtime.d.cts +792 -0
  124. package/dist/plugin-env/src/types/runtime.d.mts +792 -0
  125. package/dist/powerlines/src/lib/build/esbuild.cjs +14 -0
  126. package/dist/powerlines/src/lib/build/esbuild.mjs +14 -0
  127. package/dist/powerlines/src/lib/entry.cjs +1 -0
  128. package/dist/powerlines/src/lib/entry.mjs +1 -0
  129. package/dist/powerlines/src/lib/logger.cjs +1 -0
  130. package/dist/powerlines/src/lib/logger.mjs +1 -0
  131. package/dist/powerlines/src/lib/utilities/bundle.cjs +1 -0
  132. package/dist/powerlines/src/lib/utilities/bundle.mjs +1 -0
  133. package/dist/powerlines/src/lib/utilities/file-header.cjs +10 -0
  134. package/dist/powerlines/src/lib/utilities/file-header.mjs +10 -0
  135. package/dist/powerlines/src/lib/utilities/resolve.cjs +1 -0
  136. package/dist/powerlines/src/lib/utilities/resolve.mjs +1 -0
  137. package/dist/powerlines/src/plugin-utils/helpers.cjs +1 -0
  138. package/dist/powerlines/src/plugin-utils/helpers.mjs +1 -0
  139. package/dist/powerlines/src/plugin-utils/paths.cjs +1 -0
  140. package/dist/powerlines/src/plugin-utils/paths.mjs +1 -0
  141. package/dist/powerlines/src/types/babel.d.cts +22 -0
  142. package/dist/powerlines/src/types/babel.d.mts +22 -0
  143. package/dist/powerlines/src/types/build.d.cts +139 -0
  144. package/dist/powerlines/src/types/build.d.mts +139 -0
  145. package/dist/powerlines/src/types/commands.d.cts +8 -0
  146. package/dist/powerlines/src/types/commands.d.mts +9 -0
  147. package/dist/powerlines/src/types/config.d.cts +356 -0
  148. package/dist/powerlines/src/types/config.d.mts +357 -0
  149. package/dist/powerlines/src/types/context.d.cts +358 -0
  150. package/dist/powerlines/src/types/context.d.mts +360 -0
  151. package/dist/powerlines/src/types/fs.d.cts +458 -0
  152. package/dist/powerlines/src/types/fs.d.mts +458 -0
  153. package/dist/powerlines/src/types/hooks.d.mts +2 -0
  154. package/dist/powerlines/src/types/plugin.d.cts +232 -0
  155. package/dist/powerlines/src/types/plugin.d.mts +232 -0
  156. package/dist/powerlines/src/types/resolved.d.cts +82 -0
  157. package/dist/powerlines/src/types/resolved.d.mts +82 -0
  158. package/dist/powerlines/src/types/tsconfig.d.cts +69 -0
  159. package/dist/powerlines/src/types/tsconfig.d.mts +69 -0
  160. package/dist/types/index.cjs +0 -1
  161. package/dist/types/index.d.cts +2 -3
  162. package/dist/types/index.d.mts +2 -3
  163. package/dist/types/index.mjs +1 -1
  164. package/dist/types/plugin.cjs +0 -1
  165. package/dist/types/plugin.d.cts +42 -1
  166. package/dist/types/plugin.d.mts +42 -1
  167. package/dist/types/plugin.mjs +1 -1
  168. package/dist/types/runtime.cjs +0 -1
  169. package/dist/types/runtime.d.cts +710 -1
  170. package/dist/types/runtime.d.mts +710 -1
  171. package/dist/types/runtime.mjs +1 -1
  172. package/package.json +7 -7
  173. package/dist/index-CmCelmEL.d.cts +0 -1
  174. package/dist/index-ColiPbLk.d.mts +0 -1
  175. package/dist/plugin-D3G0L2i6.d.mts +0 -4208
  176. package/dist/plugin-DHXHjv16.cjs +0 -0
  177. package/dist/plugin-DNkZTQrj.d.cts +0 -4209
  178. package/dist/plugin-alze5tBm.mjs +0 -1
  179. package/dist/runtime-0ZpEtv0G.mjs +0 -1
  180. package/dist/runtime-B8LVkjWB.d.cts +0 -711
  181. package/dist/runtime-D4zTdSwv.cjs +0 -0
  182. package/dist/runtime-DPe0V01H.d.mts +0 -711
  183. package/dist/types-CBTc19th.cjs +0 -0
  184. package/dist/types-CZFQnkin.mjs +0 -1
@@ -0,0 +1,513 @@
1
+ import{getFileHeader as e}from"../powerlines/src/lib/utilities/file-header.mjs";function t(t){return`
2
+ /**
3
+ * The Date module provides utility functions for date manipulation and formatting
4
+ *
5
+ * @module ${t.config.output.builtinPrefix}:date
6
+ */
7
+
8
+ ${e(t)}
9
+
10
+ import { DateFormats, TimeUnit } from "@powerlines/plugin-date/types/runtime";
11
+ import { addDays as dateFnsAddDays } from "date-fns/addDays";
12
+ import { addHours as dateFnsAddHours } from "date-fns/addHours";
13
+ import { addMinutes as dateFnsAddMinutes } from "date-fns/addMinutes";
14
+ import { addMonths as dateFnsAddMonths } from "date-fns/addMonths";
15
+ import { addSeconds as dateFnsAddSeconds } from "date-fns/addSeconds";
16
+ import { addWeeks as dateFnsAddWeeks } from "date-fns/addWeeks";
17
+ import { addYears as dateFnsAddYears } from "date-fns/addYears";
18
+ import { differenceInDays } from "date-fns/differenceInDays";
19
+ import { differenceInHours } from "date-fns/differenceInHours";
20
+ import { differenceInMilliseconds } from "date-fns/differenceInMilliseconds";
21
+ import { differenceInMinutes } from "date-fns/differenceInMinutes";
22
+ import { differenceInMonths } from "date-fns/differenceInMonths";
23
+ import { differenceInQuarters } from "date-fns/differenceInQuarters";
24
+ import { differenceInSeconds } from "date-fns/differenceInSeconds";
25
+ import { differenceInWeeks } from "date-fns/differenceInWeeks";
26
+ import { differenceInYears } from "date-fns/differenceInYears";
27
+ import { eachDayOfInterval } from "date-fns/eachDayOfInterval";
28
+ import { endOfDay as dateFnsEndOfDay } from "date-fns/endOfDay";
29
+ import { endOfMonth as dateFnsEndOfMonth } from "date-fns/endOfMonth";
30
+ import { endOfWeek as dateFnsEndOfWeek } from "date-fns/endOfWeek";
31
+ import { endOfYear as dateFnsEndOfYear } from "date-fns/endOfYear";
32
+ import { format as dateFnsFormat, longFormatters } from "date-fns/format";
33
+ import { formatISO } from "date-fns/formatISO";
34
+ import { getDate as dateFnsGetDate } from "date-fns/getDate";
35
+ import { getDay as dateFnsGetDay } from "date-fns/getDay";
36
+ import { getDaysInMonth as dateFnsGetDaysInMonth } from "date-fns/getDaysInMonth";
37
+ import { getHours as dateFnsGetHours } from "date-fns/getHours";
38
+ import { getMinutes as dateFnsGetMinutes } from "date-fns/getMinutes";
39
+ import { getMonth as dateFnsGetMonth } from "date-fns/getMonth";
40
+ import { getSeconds as dateFnsGetSeconds } from "date-fns/getSeconds";
41
+ import { getWeek as dateFnsGetWeek } from "date-fns/getWeek";
42
+ import { getYear as dateFnsGetYear } from "date-fns/getYear";
43
+ import { isAfter as dateFnsIsAfter } from "date-fns/isAfter";
44
+ import { isBefore as dateFnsIsBefore } from "date-fns/isBefore";
45
+ import { isEqual as dateFnsIsEqual } from "date-fns/isEqual";
46
+ import { isSameDay as dateFnsIsSameDay } from "date-fns/isSameDay";
47
+ import { isSameHour as dateFnsIsSameHour } from "date-fns/isSameHour";
48
+ import { isSameMonth as dateFnsIsSameMonth } from "date-fns/isSameMonth";
49
+ import { isSameYear as dateFnsIsSameYear } from "date-fns/isSameYear";
50
+ import { isValid as dateFnsIsValid } from "date-fns/isValid";
51
+ import { isWithinInterval } from "date-fns/isWithinInterval";
52
+ import { Locale } from "date-fns/locale";
53
+ import { ${t.env.parsed.DEFAULT_LOCALE?.replaceAll(`-`,``)||`enUS`} as defaultLocale } from "date-fns/locale/${t.env.parsed.DEFAULT_LOCALE||`en-US`}";
54
+ import { parse as dateFnsParse } from "date-fns/parse";
55
+ import { parseISO as dateFnsParseISO } from "date-fns/parseISO";
56
+ import { setDate as dateFnsSetDate } from "date-fns/setDate";
57
+ import { setHours as dateFnsSetHours } from "date-fns/setHours";
58
+ import { setMinutes as dateFnsSetMinutes } from "date-fns/setMinutes";
59
+ import { setMonth as dateFnsSetMonth } from "date-fns/setMonth";
60
+ import { setSeconds as dateFnsSetSeconds } from "date-fns/setSeconds";
61
+ import { setYear as dateFnsSetYear } from "date-fns/setYear";
62
+ import { startOfDay as dateFnsStartOfDay } from "date-fns/startOfDay";
63
+ import { startOfMonth as dateFnsStartOfMonth } from "date-fns/startOfMonth";
64
+ import { startOfWeek as dateFnsStartOfWeek } from "date-fns/startOfWeek";
65
+ import { startOfYear as dateFnsStartOfYear } from "date-fns/startOfYear";
66
+
67
+ export const formats: DateFormats = {
68
+ dayOfMonth: "d",
69
+ fullDate: "PP",
70
+ fullDateWithWeekday: "PPPP",
71
+ fullDateTime: "PP p",
72
+ fullDateTime12h: "PP hh:mm aa",
73
+ fullDateTime24h: "PP HH:mm",
74
+ fullTime: "p",
75
+ fullTime12h: "hh:mm aa",
76
+ fullTime24h: "HH:mm",
77
+ hours12h: "hh",
78
+ hours24h: "HH",
79
+ keyboardDate: "P",
80
+ keyboardDateTime: "P p",
81
+ keyboardDateTime12h: "P hh:mm aa",
82
+ keyboardDateTime24h: "P HH:mm",
83
+ systemDateTime: "P HH:mm:ss.SSS",
84
+ filePathDateTime: "P_HH-mm-ss-SSS",
85
+ minutes: "mm",
86
+ month: "LLLL",
87
+ monthAndDate: "MMMM d",
88
+ monthAndYear: "LLLL yyyy",
89
+ monthShort: "MMM",
90
+ weekday: "EEEE",
91
+ weekdayShort: "EEE",
92
+ normalDate: "d MMMM",
93
+ normalDateWithWeekday: "EEE, MMM d",
94
+ seconds: "ss",
95
+ shortDate: "MMM d",
96
+ year: "yyyy"
97
+ };
98
+
99
+ export const locale: Locale = defaultLocale;
100
+
101
+ /**
102
+ * Creates a date object using the provided value.
103
+ *
104
+ * @remarks
105
+ * This function creates a date object using the provided value. If the value is \`null\`, it returns \`null\`. If the value is \`undefined\`, it returns the current date. If the value is a string, it parses the string as a date. If the value is a number, it treats it as a timestamp. If the value is a date object, it returns the date object.
106
+ *
107
+ * @example
108
+ * \`\`\`ts
109
+ * import { createDate } from "storm:date";
110
+ *
111
+ * const date = createDate("2023-10-01");
112
+ * console.log(date.format("YYYY-MM-DD")); // Outputs: 2023-10-01
113
+ * \`\`\`
114
+ *
115
+ * @param value - The value to create the date object from.
116
+ * @returns A date object or \`null\` if the value is \`null\`.
117
+ */
118
+ export function createDate<
119
+ TArg = undefined,
120
+ TResultingDate = TArg extends null
121
+ ? null
122
+ : TArg extends undefined
123
+ ? Date
124
+ : Date | null
125
+ >(value?: TArg): TResultingDate {
126
+ if (typeof value === "undefined") {
127
+ return new Date() as TResultingDate;
128
+ }
129
+ if (value === null) {
130
+ return null as TResultingDate;
131
+ }
132
+ return new Date(value as string | number) as TResultingDate;
133
+ }
134
+
135
+ export const type = "date-fns";
136
+
137
+ // Note: date-fns input types are more lenient than this adapter, so we need to expose our more
138
+ // strict signature and delegate to the more lenient signature. Otherwise, we have downstream type errors upon usage.
139
+ export function is12HourCycleInCurrentLocale(): boolean {
140
+ if (locale) {
141
+ return /a/.test(locale.formatLong?.time({}));
142
+ }
143
+
144
+ // By default date-fns is using en-US locale with am/pm enabled
145
+ return true;
146
+ }
147
+
148
+ export function getFormatHelperText(format: string) {
149
+ // @see https://github.com/date-fns/date-fns/blob/master/src/format/index.js#L31
150
+ const longFormatRegexp = /P+p+|P+|p+|''|'(?:''|[^'])+(?:'|$)|./g;
151
+ const _locale = locale || defaultLocale;
152
+
153
+ return (
154
+ format
155
+ .match(longFormatRegexp)
156
+ ?.map(token => {
157
+ const firstCharacter = token[0];
158
+ if (firstCharacter === "p" || firstCharacter === "P") {
159
+ const longFormatter = longFormatters[firstCharacter]!;
160
+
161
+ return longFormatter(token, _locale.formatLong);
162
+ }
163
+
164
+ return token;
165
+ })
166
+ .join("")
167
+ .replace(/aaa|aa|a/g, "(a|p)m")
168
+ .toLocaleLowerCase() ?? format
169
+ );
170
+ }
171
+
172
+ export function parseISO(isoString: string) {
173
+ return dateFnsParseISO(isoString);
174
+ }
175
+
176
+ export function toISO(value: Date) {
177
+ return formatISO(value, {
178
+ format: "extended"
179
+ });
180
+ }
181
+
182
+ export function getCurrentLocaleCode() {
183
+ return locale?.code || $storm.env.DEFAULT_LOCALE;
184
+ }
185
+
186
+ export function addSeconds(value: Date, count: number) {
187
+ return dateFnsAddSeconds(value, count);
188
+ }
189
+
190
+ export function addMinutes(value: Date, count: number) {
191
+ return dateFnsAddMinutes(value, count);
192
+ }
193
+
194
+ export function addHours(value: Date, count: number) {
195
+ return dateFnsAddHours(value, count);
196
+ }
197
+
198
+ export function addDays(value: Date, count: number) {
199
+ return dateFnsAddDays(value, count);
200
+ }
201
+
202
+ export function addWeeks(value: Date, count: number) {
203
+ return dateFnsAddWeeks(value, count);
204
+ }
205
+
206
+ export function addMonths(value: Date, count: number) {
207
+ return dateFnsAddMonths(value, count);
208
+ }
209
+
210
+ export function addYears(value: Date, count: number) {
211
+ return dateFnsAddYears(value, count);
212
+ }
213
+
214
+ export function isValid(value: any) {
215
+ return dateFnsIsValid(createDate(value));
216
+ }
217
+
218
+ export function getDiff(
219
+ value: Date,
220
+ comparing: Date | string,
221
+ unit?: TimeUnit
222
+ ) {
223
+ // we output 0 if the compare date is string and parsing is not valid
224
+ const dateToCompare = createDate(comparing) ?? value;
225
+ if (!isValid(dateToCompare)) {
226
+ return 0;
227
+ }
228
+
229
+ switch (unit) {
230
+ case "years":
231
+ return differenceInYears(value, dateToCompare);
232
+ case "quarters":
233
+ return differenceInQuarters(value, dateToCompare);
234
+ case "months":
235
+ return differenceInMonths(value, dateToCompare);
236
+ case "weeks":
237
+ return differenceInWeeks(value, dateToCompare);
238
+ case "days":
239
+ return differenceInDays(value, dateToCompare);
240
+ case "hours":
241
+ return differenceInHours(value, dateToCompare);
242
+ case "minutes":
243
+ return differenceInMinutes(value, dateToCompare);
244
+ case "seconds":
245
+ return differenceInSeconds(value, dateToCompare);
246
+ case "milliseconds":
247
+ case undefined:
248
+ default:
249
+ return differenceInMilliseconds(value, dateToCompare);
250
+ }
251
+ }
252
+
253
+ export function isAfter(value: Date, comparing: Date) {
254
+ return dateFnsIsAfter(value, comparing);
255
+ }
256
+
257
+ export function isBefore(value: Date, comparing: Date) {
258
+ return dateFnsIsBefore(value, comparing);
259
+ }
260
+
261
+ export function startOfDay(value: Date) {
262
+ return dateFnsStartOfDay(value);
263
+ }
264
+
265
+ export function endOfDay(value: Date) {
266
+ return dateFnsEndOfDay(value);
267
+ }
268
+
269
+ export function getHours(value: Date) {
270
+ return dateFnsGetHours(value);
271
+ }
272
+
273
+ export function setHours(value: Date, count: number) {
274
+ return dateFnsSetHours(value, count);
275
+ }
276
+
277
+ export function setMinutes(value: Date, count: number) {
278
+ return dateFnsSetMinutes(value, count);
279
+ }
280
+
281
+ export function getSeconds(value: Date) {
282
+ return dateFnsGetSeconds(value);
283
+ }
284
+
285
+ export function setSeconds(value: Date, count: number) {
286
+ return dateFnsSetSeconds(value, count);
287
+ }
288
+
289
+ export function isSameDay(value: Date, comparing: Date) {
290
+ return dateFnsIsSameDay(value, comparing);
291
+ }
292
+
293
+ export function isSameMonth(value: Date, comparing: Date) {
294
+ return dateFnsIsSameMonth(value, comparing);
295
+ }
296
+
297
+ export function isSameYear(value: Date, comparing: Date) {
298
+ return dateFnsIsSameYear(value, comparing);
299
+ }
300
+
301
+ export function isSameHour(value: Date, comparing: Date) {
302
+ return dateFnsIsSameHour(value, comparing);
303
+ }
304
+
305
+ export function startOfYear(value: Date) {
306
+ return dateFnsStartOfYear(value);
307
+ }
308
+
309
+ export function endOfYear(value: Date) {
310
+ return dateFnsEndOfYear(value);
311
+ }
312
+
313
+ export function startOfMonth(value: Date) {
314
+ return dateFnsStartOfMonth(value);
315
+ }
316
+
317
+ export function endOfMonth(value: Date) {
318
+ return dateFnsEndOfMonth(value);
319
+ }
320
+
321
+ export function startOfWeek(value: Date) {
322
+ return dateFnsStartOfWeek(value, {
323
+ locale
324
+ });
325
+ }
326
+
327
+ export function endOfWeek(value: Date) {
328
+ return dateFnsEndOfWeek(value, {
329
+ locale
330
+ });
331
+ }
332
+
333
+ export function getYear(value: Date) {
334
+ return dateFnsGetYear(value);
335
+ }
336
+
337
+ export function setYear(value: Date, count: number) {
338
+ return dateFnsSetYear(value, count);
339
+ }
340
+
341
+ export function toJsDate(value: Date) {
342
+ return value;
343
+ }
344
+
345
+ export function parse(value: string, formatString: string) {
346
+ if (value === "") {
347
+ return null;
348
+ }
349
+ return dateFnsParse(value, formatString, new Date(), {
350
+ locale
351
+ });
352
+ }
353
+
354
+ export function format(date: Date, formatKey: keyof DateFormats) {
355
+ return formatByString(date, formats[formatKey]);
356
+ }
357
+
358
+ export function formatByString(date: Date, formatString: string) {
359
+ return dateFnsFormat(date, formatString, {
360
+ locale
361
+ });
362
+ }
363
+
364
+ export function isEqual(date: any, comparing: any) {
365
+ if (date === null && comparing === null) {
366
+ return true;
367
+ }
368
+ return dateFnsIsEqual(date, comparing);
369
+ }
370
+
371
+ export function isNull(date: Date) {
372
+ return date === null;
373
+ }
374
+
375
+ export function isAfterDay(date: Date, value: Date) {
376
+ return isAfter(date, endOfDay(value));
377
+ }
378
+
379
+ export function isBeforeDay(date: Date, value: Date) {
380
+ return isBefore(date, startOfDay(value));
381
+ }
382
+
383
+ export function isBeforeYear(date: Date, value: Date) {
384
+ return isBefore(date, startOfYear(value));
385
+ }
386
+
387
+ export function isBeforeMonth(value: Date, comparing: Date): boolean {
388
+ return isBefore(value, startOfMonth(comparing));
389
+ }
390
+
391
+ export function isAfterMonth(value: Date, comparing: Date): boolean {
392
+ return isAfter(value, startOfMonth(comparing));
393
+ }
394
+
395
+ export function isAfterYear(date: Date, value: Date) {
396
+ return isAfter(date, endOfYear(value));
397
+ }
398
+
399
+ export function isWithinRange(date: Date, [start, end]: [Date, Date]) {
400
+ return isWithinInterval(date, {
401
+ start,
402
+ end
403
+ });
404
+ }
405
+
406
+ export function formatNumber(numberToFormat: string) {
407
+ return numberToFormat;
408
+ }
409
+
410
+ export function getMinutes(date: Date) {
411
+ return dateFnsGetMinutes(date);
412
+ }
413
+
414
+ export function getDate(date: Date) {
415
+ return dateFnsGetDate(date);
416
+ }
417
+
418
+ export function setDate(date: Date, count: number) {
419
+ return dateFnsSetDate(date, count);
420
+ }
421
+
422
+ export function getWeek(date: Date) {
423
+ return dateFnsGetWeek(date);
424
+ }
425
+
426
+ export function getMonth(date: Date) {
427
+ return dateFnsGetMonth(date);
428
+ }
429
+
430
+ export function getDaysInMonth(date: Date) {
431
+ return dateFnsGetDaysInMonth(date);
432
+ }
433
+
434
+ export function setMonth(date: Date, count: number) {
435
+ return dateFnsSetMonth(date, count);
436
+ }
437
+
438
+ export function getMeridiemText(meridiem: "am" | "pm") {
439
+ return meridiem === "am" ? "AM" : "PM";
440
+ }
441
+
442
+ export function getNextMonth(date: Date) {
443
+ return addMonths(date, 1);
444
+ }
445
+
446
+ export function getPreviousMonth(date: Date) {
447
+ return addMonths(date, -1);
448
+ }
449
+
450
+ export function getMonthArray(date: Date) {
451
+ const firstMonth = startOfYear(date);
452
+ const monthArray = [firstMonth];
453
+
454
+ while (monthArray.length < 12) {
455
+ const prevMonth = monthArray[monthArray.length - 1]!;
456
+ monthArray.push(getNextMonth(prevMonth));
457
+ }
458
+
459
+ return monthArray;
460
+ }
461
+
462
+ export function mergeDateAndTime(date: Date, time: Date) {
463
+ return setSeconds(
464
+ setMinutes(setHours(date, getHours(time)), getMinutes(time)),
465
+ getSeconds(time)
466
+ );
467
+ }
468
+
469
+ export function getWeekdays() {
470
+ const now = new Date();
471
+
472
+ return eachDayOfInterval({
473
+ start: startOfWeek(now),
474
+ end: endOfWeek(now)
475
+ }).map(day => formatByString(day, "EEEEEE"));
476
+ }
477
+
478
+ export function getWeekArray(date: Date) {
479
+ const start = startOfWeek(startOfMonth(date));
480
+ const end = endOfWeek(endOfMonth(date));
481
+ let count = 0;
482
+ let current = start;
483
+ const nestedWeeks: Date[][] = [];
484
+ let lastDay = null as null | number;
485
+ while (isBefore(current, end)) {
486
+ const weekNumber = Math.floor(count / 7);
487
+ nestedWeeks[weekNumber] ??= [];
488
+ const day = dateFnsGetDay(current);
489
+ if (lastDay !== day) {
490
+ lastDay = day;
491
+ nestedWeeks[weekNumber].push(current);
492
+ count += 1;
493
+ }
494
+ current = addDays(current, 1);
495
+ }
496
+ return nestedWeeks;
497
+ }
498
+
499
+ export function getYearRange(start: Date, end: Date) {
500
+ const startDate = startOfYear(start);
501
+ const endDate = endOfYear(end);
502
+ const years: Date[] = [];
503
+
504
+ let current = startDate;
505
+ while (isBefore(current, endDate)) {
506
+ years.push(current);
507
+ current = addYears(current, 1);
508
+ }
509
+ return years;
510
+ }
511
+
512
+
513
+ `}export{t as dateFnsModule};