@powerlines/plugin-date 0.12.66 → 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.
- package/dist/_virtual/rolldown_runtime.cjs +1 -0
- package/dist/{chunk-BGGBqwuQ.mjs → _virtual/rolldown_runtime.mjs} +1 -1
- package/dist/alloy/src/core/components/output.cjs +1 -0
- package/dist/alloy/src/core/components/output.mjs +1 -0
- package/dist/alloy/src/core/components/single-line-comment.cjs +1 -0
- package/dist/alloy/src/core/components/single-line-comment.mjs +1 -0
- package/dist/alloy/src/core/components/source-file.cjs +1 -0
- package/dist/alloy/src/core/components/source-file.mjs +1 -0
- package/dist/alloy/src/core/contexts/context.cjs +1 -0
- package/dist/alloy/src/core/contexts/context.mjs +1 -0
- package/dist/alloy/src/core/contexts/reflection.cjs +1 -0
- package/dist/alloy/src/core/contexts/reflection.mjs +1 -0
- package/dist/alloy/src/create-plugin.cjs +2 -0
- package/dist/alloy/src/create-plugin.mjs +2 -0
- package/dist/alloy/src/helpers/refkey.cjs +1 -0
- package/dist/alloy/src/helpers/refkey.mjs +1 -0
- package/dist/alloy/src/markdown/components/markdown-file.cjs +1 -0
- package/dist/alloy/src/markdown/components/markdown-file.mjs +1 -0
- package/dist/alloy/src/markdown/components/markdown-table.cjs +1 -0
- package/dist/alloy/src/markdown/components/markdown-table.mjs +1 -0
- package/dist/alloy/src/markdown/contexts/markdown-table.cjs +1 -0
- package/dist/alloy/src/markdown/contexts/markdown-table.mjs +1 -0
- package/dist/alloy/src/typescript/components/builtin-file.cjs +1 -0
- package/dist/alloy/src/typescript/components/builtin-file.mjs +1 -0
- package/dist/alloy/src/typescript/components/tsdoc-reflection.cjs +1 -0
- package/dist/alloy/src/typescript/components/tsdoc-reflection.mjs +1 -0
- package/dist/alloy/src/typescript/components/tsdoc.cjs +1 -0
- package/dist/alloy/src/typescript/components/tsdoc.mjs +1 -0
- package/dist/alloy/src/typescript/components/typescript-file.cjs +1 -0
- package/dist/alloy/src/typescript/components/typescript-file.mjs +1 -0
- package/dist/alloy/src/typescript/components/typescript-interface.cjs +1 -0
- package/dist/alloy/src/typescript/components/typescript-interface.mjs +1 -0
- package/dist/alloy/src/typescript/components/typescript-object.cjs +1 -0
- package/dist/alloy/src/typescript/components/typescript-object.mjs +1 -0
- package/dist/components/date-fns.cjs +513 -0
- package/dist/components/date-fns.d.cts +13 -0
- package/dist/components/date-fns.d.mts +13 -0
- package/dist/components/date-fns.mjs +513 -0
- package/dist/components/dayjs.cjs +458 -0
- package/dist/components/dayjs.d.cts +13 -0
- package/dist/components/dayjs.d.mts +13 -0
- package/dist/components/dayjs.mjs +458 -0
- package/dist/components/index.cjs +1 -0
- package/dist/components/index.d.mts +4 -0
- package/dist/components/index.mjs +1 -0
- package/dist/components/luxon.cjs +462 -0
- package/dist/components/luxon.d.cts +13 -0
- package/dist/components/luxon.d.mts +13 -0
- package/dist/components/luxon.mjs +462 -0
- package/dist/components/moment.cjs +448 -0
- package/dist/components/moment.d.cts +13 -0
- package/dist/components/moment.d.mts +13 -0
- package/dist/components/moment.mjs +448 -0
- package/dist/deepkit/schemas/reflection.cjs +1 -0
- package/dist/deepkit/schemas/reflection.d.cts +1560 -0
- package/dist/deepkit/schemas/reflection.d.mts +1560 -0
- package/dist/deepkit/schemas/reflection.mjs +1 -0
- package/dist/deepkit/schemas/reflection2.cjs +1 -0
- package/dist/deepkit/schemas/reflection2.mjs +1 -0
- package/dist/deepkit/src/capnp.cjs +1 -0
- package/dist/deepkit/src/capnp.mjs +1 -0
- package/dist/deepkit/src/reflect-type.cjs +1 -0
- package/dist/deepkit/src/reflect-type.mjs +1 -0
- package/dist/deepkit/src/resolve-reflections.cjs +1 -0
- package/dist/deepkit/src/resolve-reflections.mjs +1 -0
- package/dist/deepkit/src/types.d.cts +10 -0
- package/dist/deepkit/src/types.d.mts +10 -0
- package/dist/deepkit/src/utilities.cjs +1 -0
- package/dist/deepkit/src/utilities.mjs +1 -0
- package/dist/deepkit/src/vendor/type.cjs +1 -0
- package/dist/deepkit/src/vendor/type.d.cts +7 -0
- package/dist/deepkit/src/vendor/type.d.mts +7 -0
- package/dist/deepkit/src/vendor/type.mjs +1 -0
- package/dist/index.cjs +1 -1953
- package/dist/index.d.cts +7 -40
- package/dist/index.d.mts +9 -40
- package/dist/index.mjs +1 -1950
- package/dist/plugin-babel/src/helpers/ast-utils.cjs +1 -0
- package/dist/plugin-babel/src/helpers/ast-utils.mjs +1 -0
- package/dist/plugin-babel/src/helpers/create-plugin.cjs +1 -0
- package/dist/plugin-babel/src/helpers/create-plugin.mjs +1 -0
- package/dist/plugin-babel/src/helpers/filters.cjs +1 -0
- package/dist/plugin-babel/src/helpers/filters.mjs +1 -0
- package/dist/plugin-babel/src/helpers/index.cjs +1 -0
- package/dist/plugin-babel/src/helpers/index.mjs +1 -0
- package/dist/plugin-babel/src/helpers/module-helpers.cjs +1 -0
- package/dist/plugin-babel/src/helpers/module-helpers.mjs +1 -0
- package/dist/plugin-babel/src/helpers/options.cjs +1 -0
- package/dist/plugin-babel/src/helpers/options.mjs +1 -0
- package/dist/plugin-babel/src/index.cjs +1 -0
- package/dist/plugin-babel/src/index.mjs +1 -0
- package/dist/plugin-babel/src/types/index.d.mts +1 -0
- package/dist/plugin-babel/src/types/plugin.d.cts +15 -0
- package/dist/plugin-babel/src/types/plugin.d.mts +15 -0
- package/dist/plugin-env/src/babel/index.cjs +1 -0
- package/dist/plugin-env/src/babel/index.mjs +1 -0
- package/dist/plugin-env/src/babel/plugin.cjs +5 -0
- package/dist/plugin-env/src/babel/plugin.mjs +5 -0
- package/dist/plugin-env/src/components/docs.cjs +1 -0
- package/dist/plugin-env/src/components/docs.mjs +1 -0
- package/dist/plugin-env/src/components/env.cjs +34 -0
- package/dist/plugin-env/src/components/env.mjs +31 -0
- package/dist/plugin-env/src/components/index.cjs +1 -0
- package/dist/plugin-env/src/components/index.mjs +1 -0
- package/dist/plugin-env/src/helpers/create-reflection-resource.cjs +1 -0
- package/dist/plugin-env/src/helpers/create-reflection-resource.mjs +1 -0
- package/dist/plugin-env/src/helpers/index.cjs +1 -0
- package/dist/plugin-env/src/helpers/index.mjs +1 -0
- package/dist/plugin-env/src/helpers/load.cjs +1 -0
- package/dist/plugin-env/src/helpers/load.mjs +1 -0
- package/dist/plugin-env/src/helpers/persistence.cjs +1 -0
- package/dist/plugin-env/src/helpers/persistence.mjs +1 -0
- package/dist/plugin-env/src/helpers/reflect.cjs +1 -0
- package/dist/plugin-env/src/helpers/reflect.mjs +1 -0
- package/dist/plugin-env/src/helpers/source-file-env.cjs +1 -0
- package/dist/plugin-env/src/helpers/source-file-env.mjs +1 -0
- package/dist/plugin-env/src/helpers/template-helpers.cjs +1 -0
- package/dist/plugin-env/src/helpers/template-helpers.mjs +1 -0
- package/dist/plugin-env/src/index.cjs +16 -0
- package/dist/plugin-env/src/index.mjs +16 -0
- package/dist/plugin-env/src/types/plugin.d.cts +135 -0
- package/dist/plugin-env/src/types/plugin.d.mts +136 -0
- package/dist/plugin-env/src/types/runtime.d.cts +792 -0
- package/dist/plugin-env/src/types/runtime.d.mts +792 -0
- package/dist/powerlines/src/lib/build/esbuild.cjs +14 -0
- package/dist/powerlines/src/lib/build/esbuild.mjs +14 -0
- package/dist/powerlines/src/lib/entry.cjs +1 -0
- package/dist/powerlines/src/lib/entry.mjs +1 -0
- package/dist/powerlines/src/lib/logger.cjs +1 -0
- package/dist/powerlines/src/lib/logger.mjs +1 -0
- package/dist/powerlines/src/lib/utilities/bundle.cjs +1 -0
- package/dist/powerlines/src/lib/utilities/bundle.mjs +1 -0
- package/dist/powerlines/src/lib/utilities/file-header.cjs +10 -0
- package/dist/powerlines/src/lib/utilities/file-header.mjs +10 -0
- package/dist/powerlines/src/lib/utilities/resolve.cjs +1 -0
- package/dist/powerlines/src/lib/utilities/resolve.mjs +1 -0
- package/dist/powerlines/src/plugin-utils/helpers.cjs +1 -0
- package/dist/powerlines/src/plugin-utils/helpers.mjs +1 -0
- package/dist/powerlines/src/plugin-utils/paths.cjs +1 -0
- package/dist/powerlines/src/plugin-utils/paths.mjs +1 -0
- package/dist/powerlines/src/types/babel.d.cts +22 -0
- package/dist/powerlines/src/types/babel.d.mts +22 -0
- package/dist/powerlines/src/types/build.d.cts +139 -0
- package/dist/powerlines/src/types/build.d.mts +139 -0
- package/dist/powerlines/src/types/commands.d.cts +8 -0
- package/dist/powerlines/src/types/commands.d.mts +9 -0
- package/dist/powerlines/src/types/config.d.cts +356 -0
- package/dist/powerlines/src/types/config.d.mts +357 -0
- package/dist/powerlines/src/types/context.d.cts +358 -0
- package/dist/powerlines/src/types/context.d.mts +360 -0
- package/dist/powerlines/src/types/fs.d.cts +458 -0
- package/dist/powerlines/src/types/fs.d.mts +458 -0
- package/dist/powerlines/src/types/hooks.d.mts +2 -0
- package/dist/powerlines/src/types/plugin.d.cts +232 -0
- package/dist/powerlines/src/types/plugin.d.mts +232 -0
- package/dist/powerlines/src/types/resolved.d.cts +82 -0
- package/dist/powerlines/src/types/resolved.d.mts +82 -0
- package/dist/powerlines/src/types/tsconfig.d.cts +69 -0
- package/dist/powerlines/src/types/tsconfig.d.mts +69 -0
- package/dist/types/index.cjs +0 -1
- package/dist/types/index.d.cts +2 -3
- package/dist/types/index.d.mts +2 -3
- package/dist/types/index.mjs +1 -1
- package/dist/types/plugin.cjs +0 -1
- package/dist/types/plugin.d.cts +42 -1
- package/dist/types/plugin.d.mts +42 -1
- package/dist/types/plugin.mjs +1 -1
- package/dist/types/runtime.cjs +0 -1
- package/dist/types/runtime.d.cts +710 -1
- package/dist/types/runtime.d.mts +710 -1
- package/dist/types/runtime.mjs +1 -1
- package/package.json +7 -7
- package/dist/index-CmCelmEL.d.cts +0 -1
- package/dist/index-ColiPbLk.d.mts +0 -1
- package/dist/plugin-CU36jSR5.d.mts +0 -4211
- package/dist/plugin-DHXHjv16.cjs +0 -0
- package/dist/plugin-DxCv7BdD.d.cts +0 -4212
- package/dist/plugin-alze5tBm.mjs +0 -1
- package/dist/runtime-0ZpEtv0G.mjs +0 -1
- package/dist/runtime-B8LVkjWB.d.cts +0 -711
- package/dist/runtime-D4zTdSwv.cjs +0 -0
- package/dist/runtime-DPe0V01H.d.mts +0 -711
- package/dist/types-CBTc19th.cjs +0 -0
- package/dist/types-CZFQnkin.mjs +0 -1
|
@@ -0,0 +1,458 @@
|
|
|
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 defaultDayjs, { QUnitType } from "dayjs";
|
|
11
|
+
import customParseFormatPlugin from "dayjs/plugin/customParseFormat";
|
|
12
|
+
import localizedFormatPlugin from "dayjs/plugin/localizedFormat";
|
|
13
|
+
import isBetweenPlugin from "dayjs/plugin/isBetween";
|
|
14
|
+
import weekOfYear from "dayjs/plugin/weekOfYear";
|
|
15
|
+
import {
|
|
16
|
+
StormDateInterface,
|
|
17
|
+
DateFormats,
|
|
18
|
+
TimeUnit
|
|
19
|
+
} from "@powerlines/plugin-date/types/runtime";
|
|
20
|
+
|
|
21
|
+
defaultDayjs.extend(customParseFormatPlugin);
|
|
22
|
+
defaultDayjs.extend(localizedFormatPlugin);
|
|
23
|
+
defaultDayjs.extend(isBetweenPlugin);
|
|
24
|
+
defaultDayjs.extend(weekOfYear);
|
|
25
|
+
|
|
26
|
+
interface Opts {
|
|
27
|
+
locale?: string;
|
|
28
|
+
/** Make sure that your dayjs instance extends customParseFormat and advancedFormat */
|
|
29
|
+
instance?: typeof defaultDayjs;
|
|
30
|
+
formats?: Partial<DateFormats>;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
type Dayjs = defaultDayjs.Dayjs;
|
|
34
|
+
type Constructor<TDate extends Dayjs> = (
|
|
35
|
+
...args: Parameters<typeof defaultDayjs>
|
|
36
|
+
) => TDate;
|
|
37
|
+
const withLocale = <TDate extends Dayjs>(
|
|
38
|
+
dayjs: any,
|
|
39
|
+
locale?: string
|
|
40
|
+
): Constructor<TDate> => (!locale ? dayjs : (...args) => dayjs(...args).locale(locale));
|
|
41
|
+
|
|
42
|
+
export const formats: DateFormats = {
|
|
43
|
+
normalDateWithWeekday: "ddd, MMM D",
|
|
44
|
+
normalDate: "D MMMM",
|
|
45
|
+
shortDate: "MMM D",
|
|
46
|
+
monthAndDate: "MMMM D",
|
|
47
|
+
dayOfMonth: "D",
|
|
48
|
+
year: "YYYY",
|
|
49
|
+
month: "MMMM",
|
|
50
|
+
monthShort: "MMM",
|
|
51
|
+
monthAndYear: "MMMM YYYY",
|
|
52
|
+
weekday: "dddd",
|
|
53
|
+
weekdayShort: "ddd",
|
|
54
|
+
minutes: "mm",
|
|
55
|
+
hours12h: "hh",
|
|
56
|
+
hours24h: "HH",
|
|
57
|
+
seconds: "ss",
|
|
58
|
+
fullTime: "LT",
|
|
59
|
+
fullTime12h: "hh:mm A",
|
|
60
|
+
fullTime24h: "HH:mm",
|
|
61
|
+
fullDate: "ll",
|
|
62
|
+
fullDateWithWeekday: "dddd, LL",
|
|
63
|
+
fullDateTime: "lll",
|
|
64
|
+
fullDateTime12h: "ll hh:mm A",
|
|
65
|
+
fullDateTime24h: "ll HH:mm",
|
|
66
|
+
keyboardDate: "L",
|
|
67
|
+
keyboardDateTime: "L LT",
|
|
68
|
+
keyboardDateTime12h: "L hh:mm A",
|
|
69
|
+
keyboardDateTime24h: "L HH:mm",
|
|
70
|
+
systemDateTime: "L HH:mm:ss.SSS",
|
|
71
|
+
filePathDateTime: "L_HH-mm-ss-SSS"
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
export let locale = $storm.env.DEFAULT_LOCALE;
|
|
75
|
+
|
|
76
|
+
export const dayjs = withLocale(defaultDayjs, locale);
|
|
77
|
+
|
|
78
|
+
export const type = "dayjs";
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Creates a date object using the provided value.
|
|
82
|
+
*
|
|
83
|
+
* @remarks
|
|
84
|
+
* 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.
|
|
85
|
+
*
|
|
86
|
+
* @example
|
|
87
|
+
* \`\`\`ts
|
|
88
|
+
* import { createDate } from "storm:date";
|
|
89
|
+
*
|
|
90
|
+
* const date = createDate("2023-10-01");
|
|
91
|
+
* console.log(date.format("YYYY-MM-DD")); // Outputs: 2023-10-01
|
|
92
|
+
* \`\`\`
|
|
93
|
+
*
|
|
94
|
+
* @param value - The value to create the date object from.
|
|
95
|
+
* @returns A date object or \`null\` if the value is \`null\`.
|
|
96
|
+
*/
|
|
97
|
+
export function createDate<
|
|
98
|
+
TArg extends unknown = undefined,
|
|
99
|
+
TResultingDate extends unknown = TArg extends null
|
|
100
|
+
? null
|
|
101
|
+
: TArg extends undefined
|
|
102
|
+
? TDate
|
|
103
|
+
: TDate | null
|
|
104
|
+
>(value?: TArg): TResultingDate {
|
|
105
|
+
if (value === null) {
|
|
106
|
+
return null as TResultingDate;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
return dayjs(value as any) as unknown as TResultingDate;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
export function is12HourCycleInCurrentLocale() {
|
|
113
|
+
/* istanbul ignore next */
|
|
114
|
+
return /A|a/.test(dayjs.Ls[dayjs.locale() || $storm.env.DEFAULT_LOCALE]?.formats?.LT ?? "");
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
export function getCurrentLocaleCode() {
|
|
118
|
+
return dayjs.locale() || $storm.env.DEFAULT_LOCALE;
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
export function getFormatHelperText(format: string) {
|
|
122
|
+
// @see https://github.com/iamkun/dayjs/blob/dev/src/plugin/localizedFormat/index.js
|
|
123
|
+
const localFormattingTokens = /(\[[^\[]*\])|(\\)?(LTS|LT|LL?L?L?)|./g;
|
|
124
|
+
|
|
125
|
+
return (
|
|
126
|
+
format
|
|
127
|
+
.match(localFormattingTokens)
|
|
128
|
+
?.map((token) => {
|
|
129
|
+
const firstCharacter = token[0];
|
|
130
|
+
if (firstCharacter === "L") {
|
|
131
|
+
/* istanbul ignore next */
|
|
132
|
+
return (
|
|
133
|
+
dayjs.Ls[dayjs.locale() || $storm.env.DEFAULT_LOCALE]?.formats[
|
|
134
|
+
token as keyof ILocale["formats"]
|
|
135
|
+
] ?? token
|
|
136
|
+
);
|
|
137
|
+
}
|
|
138
|
+
return token;
|
|
139
|
+
})
|
|
140
|
+
.join("")
|
|
141
|
+
.replace(/a/gi, "(a|p)m")
|
|
142
|
+
.toLocaleLowerCase() ?? format
|
|
143
|
+
);
|
|
144
|
+
};
|
|
145
|
+
|
|
146
|
+
export function parseISO(isoString: string) {
|
|
147
|
+
return dayjs(isoString);
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
export function toISO(value: Dayjs) {
|
|
151
|
+
return value.toISOString();
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
export function parse(value: any, format: string) {
|
|
155
|
+
if (value === "") {
|
|
156
|
+
return null;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
return dayjs(value, format, dayjs.locale(), true);
|
|
160
|
+
};
|
|
161
|
+
|
|
162
|
+
export function toJsDate(value: Dayjs) {
|
|
163
|
+
return value.toDate();
|
|
164
|
+
};
|
|
165
|
+
|
|
166
|
+
export function isValid(value: any) {
|
|
167
|
+
return dayjs(value).isValid();
|
|
168
|
+
};
|
|
169
|
+
|
|
170
|
+
export function isNull(date: Dayjs | null) {
|
|
171
|
+
return date === null;
|
|
172
|
+
};
|
|
173
|
+
|
|
174
|
+
export function getDiff(date: Dayjs, comparing: Dayjs | string, units?: Unit) {
|
|
175
|
+
if (typeof comparing === "string") {
|
|
176
|
+
comparing = dayjs(comparing);
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
if (!comparing.isValid()) {
|
|
180
|
+
return 0;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
return date.diff(comparing, units as QUnitType);
|
|
184
|
+
};
|
|
185
|
+
|
|
186
|
+
export function isAfter(date: Dayjs, value: Dayjs) {
|
|
187
|
+
return date.isAfter(value);
|
|
188
|
+
};
|
|
189
|
+
|
|
190
|
+
export function isBefore(date: Dayjs, value: Dayjs) {
|
|
191
|
+
return date.isBefore(value);
|
|
192
|
+
};
|
|
193
|
+
|
|
194
|
+
export function isAfterDay(date: Dayjs, value: Dayjs) {
|
|
195
|
+
return date.isAfter(value, "day");
|
|
196
|
+
};
|
|
197
|
+
|
|
198
|
+
export function isBeforeDay(date: Dayjs, value: Dayjs) {
|
|
199
|
+
return date.isBefore(value, "day");
|
|
200
|
+
};
|
|
201
|
+
|
|
202
|
+
export function isAfterMonth(date: Dayjs, value: Dayjs) {
|
|
203
|
+
return date.isAfter(value, "month");
|
|
204
|
+
};
|
|
205
|
+
|
|
206
|
+
export function isBeforeMonth(date: Dayjs, value: Dayjs) {
|
|
207
|
+
return date.isBefore(value, "month");
|
|
208
|
+
};
|
|
209
|
+
|
|
210
|
+
export function isBeforeYear(date: Dayjs, value: Dayjs) {
|
|
211
|
+
return date.isBefore(value, "year");
|
|
212
|
+
};
|
|
213
|
+
|
|
214
|
+
export function isAfterYear(date: Dayjs, value: Dayjs) {
|
|
215
|
+
return date.isAfter(value, "year");
|
|
216
|
+
};
|
|
217
|
+
|
|
218
|
+
export function startOfDay(date: Dayjs) {
|
|
219
|
+
return date.startOf("day");
|
|
220
|
+
};
|
|
221
|
+
|
|
222
|
+
export function endOfDay(date: Dayjs) {
|
|
223
|
+
return date.endOf("day");
|
|
224
|
+
};
|
|
225
|
+
|
|
226
|
+
export function format(date: Dayjs, formatKey: keyof DateFormats) {
|
|
227
|
+
return formatByString(date, formats[formatKey]);
|
|
228
|
+
};
|
|
229
|
+
|
|
230
|
+
export function formatByString(date: Dayjs, formatString: string) {
|
|
231
|
+
return dayjs(date).format(formatString);
|
|
232
|
+
};
|
|
233
|
+
|
|
234
|
+
export function formatNumber(numberToFormat: string) {
|
|
235
|
+
return numberToFormat;
|
|
236
|
+
};
|
|
237
|
+
|
|
238
|
+
export function getHours(date: Dayjs) {
|
|
239
|
+
return date.hour();
|
|
240
|
+
};
|
|
241
|
+
|
|
242
|
+
export function addSeconds(date: Dayjs, count: number) {
|
|
243
|
+
return count < 0
|
|
244
|
+
? (date.subtract(Math.abs(count), "second") as Dayjs)
|
|
245
|
+
: (date.add(count, "second") as Dayjs);
|
|
246
|
+
};
|
|
247
|
+
|
|
248
|
+
export function addMinutes(date: Dayjs, count: number) {
|
|
249
|
+
return count < 0
|
|
250
|
+
? (date.subtract(Math.abs(count), "minute") as Dayjs)
|
|
251
|
+
: (date.add(count, "minute") as Dayjs);
|
|
252
|
+
};
|
|
253
|
+
|
|
254
|
+
export function addHours(date: Dayjs, count: number) {
|
|
255
|
+
return count < 0
|
|
256
|
+
? (date.subtract(Math.abs(count), "hour") as Dayjs)
|
|
257
|
+
: (date.add(count, "hour") as Dayjs);
|
|
258
|
+
};
|
|
259
|
+
|
|
260
|
+
export function addDays(date: Dayjs, count: number) {
|
|
261
|
+
return count < 0
|
|
262
|
+
? (date.subtract(Math.abs(count), "day") as Dayjs)
|
|
263
|
+
: (date.add(count, "day") as Dayjs);
|
|
264
|
+
};
|
|
265
|
+
|
|
266
|
+
export function addWeeks(date: Dayjs, count: number) {
|
|
267
|
+
return count < 0
|
|
268
|
+
? (date.subtract(Math.abs(count), "week") as Dayjs)
|
|
269
|
+
: (date.add(count, "week") as Dayjs);
|
|
270
|
+
};
|
|
271
|
+
|
|
272
|
+
export function addMonths(date: Dayjs, count: number) {
|
|
273
|
+
return count < 0
|
|
274
|
+
? (date.subtract(Math.abs(count), "month") as Dayjs)
|
|
275
|
+
: (date.add(count, "month") as Dayjs);
|
|
276
|
+
};
|
|
277
|
+
|
|
278
|
+
export function addYears(date: Dayjs, count: number) {
|
|
279
|
+
return count < 0
|
|
280
|
+
? (date.subtract(Math.abs(count), "year") as Dayjs)
|
|
281
|
+
: (date.add(count, "year") as Dayjs);
|
|
282
|
+
};
|
|
283
|
+
|
|
284
|
+
export function setMonth(date: Dayjs, count: number) {
|
|
285
|
+
return date.set("month", count) as Dayjs;
|
|
286
|
+
};
|
|
287
|
+
|
|
288
|
+
export function setHours(date: Dayjs, count: number) {
|
|
289
|
+
return date.set("hour", count) as Dayjs;
|
|
290
|
+
};
|
|
291
|
+
|
|
292
|
+
export function getMinutes(date: Dayjs) {
|
|
293
|
+
return date.minute();
|
|
294
|
+
};
|
|
295
|
+
|
|
296
|
+
export function setMinutes(date: Dayjs, count: number) {
|
|
297
|
+
return date.set("minute", count) as Dayjs;
|
|
298
|
+
};
|
|
299
|
+
|
|
300
|
+
export function getSeconds(date: Dayjs) {
|
|
301
|
+
return date.second();
|
|
302
|
+
};
|
|
303
|
+
|
|
304
|
+
export function setSeconds(date: Dayjs, count: number) {
|
|
305
|
+
return date.set("second", count) as Dayjs;
|
|
306
|
+
};
|
|
307
|
+
|
|
308
|
+
export function getWeek(date: Dayjs) {
|
|
309
|
+
return date.week();
|
|
310
|
+
};
|
|
311
|
+
|
|
312
|
+
export function getMonth(date: Dayjs) {
|
|
313
|
+
return date.month();
|
|
314
|
+
};
|
|
315
|
+
|
|
316
|
+
export function getDate(date: Dayjs) {
|
|
317
|
+
return date.date();
|
|
318
|
+
};
|
|
319
|
+
|
|
320
|
+
export function setDate(date: Dayjs, count: number) {
|
|
321
|
+
return date.set("date", count) as Dayjs;
|
|
322
|
+
};
|
|
323
|
+
|
|
324
|
+
export function getDaysInMonth(date: Dayjs) {
|
|
325
|
+
return date.daysInMonth();
|
|
326
|
+
};
|
|
327
|
+
|
|
328
|
+
export function isSameDay(date: Dayjs, comparing: Dayjs) {
|
|
329
|
+
return date.isSame(comparing, "day");
|
|
330
|
+
};
|
|
331
|
+
|
|
332
|
+
export function isSameMonth(date: Dayjs, comparing: Dayjs) {
|
|
333
|
+
return date.isSame(comparing, "month");
|
|
334
|
+
};
|
|
335
|
+
|
|
336
|
+
export function isSameYear(date: Dayjs, comparing: Dayjs) {
|
|
337
|
+
return date.isSame(comparing, "year");
|
|
338
|
+
};
|
|
339
|
+
|
|
340
|
+
export function isSameHour(date: Dayjs, comparing: Dayjs) {
|
|
341
|
+
return date.isSame(comparing, "hour");
|
|
342
|
+
};
|
|
343
|
+
|
|
344
|
+
export function getMeridiemText(meridiem: "am" | "pm") {
|
|
345
|
+
return meridiem === "am" ? "AM" : "PM";
|
|
346
|
+
};
|
|
347
|
+
|
|
348
|
+
export function startOfYear(date: Dayjs) {
|
|
349
|
+
return date.startOf("year") as Dayjs;
|
|
350
|
+
};
|
|
351
|
+
|
|
352
|
+
export function endOfYear(date: Dayjs) {
|
|
353
|
+
return date.endOf("year") as Dayjs;
|
|
354
|
+
};
|
|
355
|
+
|
|
356
|
+
export function startOfMonth(date: Dayjs) {
|
|
357
|
+
return date.startOf("month") as Dayjs;
|
|
358
|
+
};
|
|
359
|
+
|
|
360
|
+
export function endOfMonth(date: Dayjs) {
|
|
361
|
+
return date.endOf("month") as Dayjs;
|
|
362
|
+
};
|
|
363
|
+
|
|
364
|
+
export function startOfWeek(date: Dayjs) {
|
|
365
|
+
return date.startOf("week") as Dayjs;
|
|
366
|
+
};
|
|
367
|
+
|
|
368
|
+
export function endOfWeek(date: Dayjs) {
|
|
369
|
+
return date.endOf("week") as Dayjs;
|
|
370
|
+
};
|
|
371
|
+
|
|
372
|
+
export function getNextMonth(date: Dayjs) {
|
|
373
|
+
return date.add(1, "month") as Dayjs;
|
|
374
|
+
};
|
|
375
|
+
|
|
376
|
+
export function getPreviousMonth(date: Dayjs) {
|
|
377
|
+
return date.subtract(1, "month") as Dayjs;
|
|
378
|
+
};
|
|
379
|
+
|
|
380
|
+
export function getMonthArray(date: Dayjs) {
|
|
381
|
+
const firstMonth = date.startOf("year") as Dayjs;
|
|
382
|
+
const monthArray = [firstMonth];
|
|
383
|
+
|
|
384
|
+
while (monthArray.length < 12) {
|
|
385
|
+
const prevMonth = monthArray[monthArray.length - 1];
|
|
386
|
+
monthArray.push(getNextMonth(prevMonth));
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
return monthArray;
|
|
390
|
+
};
|
|
391
|
+
|
|
392
|
+
export function getYear(date: Dayjs) {
|
|
393
|
+
return date.year();
|
|
394
|
+
};
|
|
395
|
+
|
|
396
|
+
export function setYear(date: Dayjs, year: number) {
|
|
397
|
+
return date.set("year", year) as Dayjs;
|
|
398
|
+
};
|
|
399
|
+
|
|
400
|
+
export function mergeDateAndTime(date: Dayjs, time: Dayjs) {
|
|
401
|
+
return date.hour(time.hour()).minute(time.minute()).second(time.second()) as Dayjs;
|
|
402
|
+
};
|
|
403
|
+
|
|
404
|
+
export function getWeekdays() {
|
|
405
|
+
const start = dayjs().startOf("week");
|
|
406
|
+
return [0, 1, 2, 3, 4, 5, 6].map((diff) =>
|
|
407
|
+
formatByString(start.add(diff, "day"), "dd")
|
|
408
|
+
);
|
|
409
|
+
};
|
|
410
|
+
|
|
411
|
+
export function isEqual(value: any, comparing: any) {
|
|
412
|
+
if (value === null && comparing === null) {
|
|
413
|
+
return true;
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
return dayjs(value).isSame(comparing);
|
|
417
|
+
};
|
|
418
|
+
|
|
419
|
+
export function getWeekArray(date: Dayjs) {
|
|
420
|
+
const start = dayjs(date).startOf("month").startOf("week") as Dayjs;
|
|
421
|
+
const end = dayjs(date).endOf("month").endOf("week") as Dayjs;
|
|
422
|
+
|
|
423
|
+
let count = 0;
|
|
424
|
+
let current = start;
|
|
425
|
+
const nestedWeeks: Dayjs[][] = [];
|
|
426
|
+
|
|
427
|
+
while (current.isBefore(end)) {
|
|
428
|
+
const weekNumber = Math.floor(count / 7);
|
|
429
|
+
nestedWeeks[weekNumber] = nestedWeeks[weekNumber] || [];
|
|
430
|
+
nestedWeeks[weekNumber].push(current);
|
|
431
|
+
|
|
432
|
+
current = current.add(1, "day") as TDate;
|
|
433
|
+
count += 1;
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
return nestedWeeks;
|
|
437
|
+
};
|
|
438
|
+
|
|
439
|
+
export function getYearRange(start: Dayjs, end: Dayjs) {
|
|
440
|
+
const startDate = start.startOf("year");
|
|
441
|
+
const endDate = end.endOf("year");
|
|
442
|
+
const years: Dayjs[] = [];
|
|
443
|
+
|
|
444
|
+
let current = startDate;
|
|
445
|
+
while (current.isBefore(endDate)) {
|
|
446
|
+
years.push(current);
|
|
447
|
+
current = current.add(1, "year");
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
return years;
|
|
451
|
+
};
|
|
452
|
+
|
|
453
|
+
export function isWithinRange(date: Dayjs, [start, end]: [Dayjs, Dayjs]) {
|
|
454
|
+
return date.isBetween(start, end, null, "[]");
|
|
455
|
+
};
|
|
456
|
+
|
|
457
|
+
|
|
458
|
+
`}export{t as dayjsModule};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const e=require(`./date-fns.cjs`),t=require(`./dayjs.cjs`),n=require(`./luxon.cjs`),r=require(`./moment.cjs`);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{dateFnsModule as e}from"./date-fns.mjs";import{dayjsModule as t}from"./dayjs.mjs";import{luxonModule as n}from"./luxon.mjs";import{momentModule as r}from"./moment.mjs";export{};
|