@powerlines/plugin-date 0.12.299 → 0.12.301

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