@ciwergrp/nuxid 1.14.0 → 1.15.0

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/README.md CHANGED
@@ -31,7 +31,7 @@ export default defineNuxtConfig({
31
31
  - `alias` (`Array<[from, to]>`)
32
32
  - **Validator helpers** (enabled by default): Element Plus friendly `createValidationRules` plus `ValidationRule` and `ValidationOptions` types. Auto-imported when enabled.
33
33
  - **Form composable** (enabled by default): `useHttp` wraps `$fetch`, handles `processing`, `errors`, `response`, and builds `FormData` automatically (or always when `alwaysFormData: true`). Auto-imported when enabled.
34
- - **Helper utilities** (enabled by default): array/object/number/string helpers with configurable factory (`number().abbreviate()`) or prefixed (`NumberAbbreviate()`) styles, locale lookups, and currency defaults.
34
+ - **Helper utilities** (enabled by default): array/object/number/string/date helpers with configurable factory (`number().abbreviate()`) or prefixed (`NumberAbbreviate()`) styles, locale lookups, currency defaults, and timezone source configuration (`query`/`cookie`/`localStorage`/`static`).
35
35
  - **Cursor fetch composable** (enabled by default): `useCursorFetch` wraps `$fetch`, supports cursor pagination, polling, reactive params, custom fetchers, and configurable cursor/meta keys. Auto-imported when enabled.
36
36
  - **Pinia integration** (enabled by default): injects Pinia, auto-imports core helpers (`defineStore`, `storeToRefs`, etc.), and auto-imports stores from `stores` by default.
37
37
  - **Icon defaults** (disabled by default): installs `@nuxt/icon` with default component name `KIcon`, size `1.25em`, base class `align-middle inline-block text-current`, mode `svg`. Configure via `nuxid.icon.config`.
@@ -145,6 +145,12 @@ export default defineNuxtConfig({
145
145
  localeKey: 'lang',
146
146
  localeFallback: 'en',
147
147
  defaultCurrency: 'USD',
148
+ timezone: {
149
+ source: 'cookie',
150
+ key: 'tz',
151
+ static: 'UTC',
152
+ fallback: 'UTC',
153
+ },
148
154
  },
149
155
  },
150
156
  pinia: {
package/dist/module.d.mts CHANGED
@@ -1,4 +1,5 @@
1
1
  import * as _nuxt_schema from '@nuxt/schema';
2
+ import { TimezoneId } from '../dist/runtime/helper/date/timezones.js';
2
3
  export * from '../dist/runtime/form.js';
3
4
  export { default as useHttp } from '../dist/runtime/form.js';
4
5
  export { useBreadcrumbs, useTitle } from '../dist/runtime/page/index.js';
@@ -129,6 +130,29 @@ interface ElementPlusOptions {
129
130
  }
130
131
  type ElementPlusFeatureInput = boolean | Partial<ElementPlusOptions> | Record<string, any> | undefined;
131
132
 
133
+ type HelperTimezoneSource = 'query' | 'cookie' | 'localStorage' | 'static';
134
+ interface HelperTimezoneOptions {
135
+ /**
136
+ * Where timezone value should be read from
137
+ * @default 'cookie'
138
+ */
139
+ source?: HelperTimezoneSource;
140
+ /**
141
+ * Query/cookie/localStorage key name for timezone value
142
+ * @default 'tz'
143
+ */
144
+ key?: string;
145
+ /**
146
+ * Fixed timezone value when source is static
147
+ * @default 'UTC'
148
+ */
149
+ static?: TimezoneId;
150
+ /**
151
+ * Fallback timezone when source value is missing/invalid
152
+ * @default 'UTC'
153
+ */
154
+ fallback?: TimezoneId;
155
+ }
132
156
  interface HelperOptions {
133
157
  /**
134
158
  * @default true
@@ -163,6 +187,26 @@ interface HelperOptions {
163
187
  * @default 'USD'
164
188
  */
165
189
  defaultCurrency?: string;
190
+ /**
191
+ * Timezone configuration for date helpers
192
+ */
193
+ timezone?: HelperTimezoneOptions;
194
+ /**
195
+ * @deprecated Use config.timezone.source
196
+ */
197
+ timezoneSource?: HelperTimezoneSource;
198
+ /**
199
+ * @deprecated Use config.timezone.key
200
+ */
201
+ timezoneKey?: string;
202
+ /**
203
+ * @deprecated Use config.timezone.static
204
+ */
205
+ timezoneStatic?: TimezoneId;
206
+ /**
207
+ * @deprecated Use config.timezone.fallback
208
+ */
209
+ timezoneFallback?: TimezoneId;
166
210
  };
167
211
  }
168
212
  type HelperFeatureInput = boolean | Partial<HelperOptions> | undefined;
package/dist/module.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@ciwergrp/nuxid",
3
3
  "configKey": "nuxid",
4
- "version": "1.14.0",
4
+ "version": "1.15.0",
5
5
  "builder": {
6
6
  "@nuxt/module-builder": "1.0.2",
7
7
  "unbuild": "3.6.1"
package/dist/module.mjs CHANGED
@@ -182,7 +182,13 @@ const helperDefaults = {
182
182
  localeSource: "cookie",
183
183
  localeKey: "lang",
184
184
  localeFallback: "en",
185
- defaultCurrency: "USD"
185
+ defaultCurrency: "USD",
186
+ timezone: {
187
+ source: "cookie",
188
+ key: "tz",
189
+ static: "UTC",
190
+ fallback: "UTC"
191
+ }
186
192
  }
187
193
  };
188
194
  function resolveHelperOptions(input) {
@@ -191,6 +197,11 @@ function resolveHelperOptions(input) {
191
197
  }
192
198
  const overrides = typeof input === "boolean" || input === void 0 ? {} : input;
193
199
  const config = overrides.config ?? {};
200
+ const timezoneConfig = config.timezone ?? {};
201
+ const timezoneSource = timezoneConfig.source ?? config.timezoneSource ?? helperDefaults.config.timezone.source;
202
+ const timezoneKey = timezoneConfig.key ?? config.timezoneKey ?? helperDefaults.config.timezone.key;
203
+ const timezoneStatic = timezoneConfig.static ?? config.timezoneStatic ?? helperDefaults.config.timezone.static;
204
+ const timezoneFallback = timezoneConfig.fallback ?? config.timezoneFallback ?? helperDefaults.config.timezone.fallback;
194
205
  return {
195
206
  enabled: overrides?.enabled ?? true,
196
207
  config: {
@@ -198,14 +209,21 @@ function resolveHelperOptions(input) {
198
209
  localeSource: config.localeSource ?? helperDefaults.config.localeSource,
199
210
  localeKey: config.localeKey ?? helperDefaults.config.localeKey,
200
211
  localeFallback: config.localeFallback ?? helperDefaults.config.localeFallback,
201
- defaultCurrency: config.defaultCurrency ?? helperDefaults.config.defaultCurrency
212
+ defaultCurrency: config.defaultCurrency ?? helperDefaults.config.defaultCurrency,
213
+ timezone: {
214
+ source: timezoneSource,
215
+ key: timezoneKey,
216
+ static: timezoneStatic,
217
+ fallback: timezoneFallback
218
+ }
202
219
  }
203
220
  };
204
221
  }
205
- function registerHelperFeature(options, { from }) {
222
+ function registerHelperFeature(options, { from, plugin }) {
206
223
  if (!options.enabled) {
207
224
  return;
208
225
  }
226
+ addPlugin(plugin);
209
227
  const style = options.config.style;
210
228
  if (style === "factory") {
211
229
  addImports({ name: "array", as: "array", from });
@@ -339,6 +357,8 @@ function registerHelperFeature(options, { from }) {
339
357
  "toRfc3339String",
340
358
  "toRfc7231String",
341
359
  "localDateToUTCISO",
360
+ "availableTimezones",
361
+ "currentTimezone",
342
362
  "dateParse",
343
363
  "parseISO",
344
364
  "addSecond",
@@ -648,8 +668,16 @@ const module$1 = defineNuxtModule({
648
668
  });
649
669
  }
650
670
  if (helperOptions.enabled) {
671
+ nuxt.options.runtimeConfig.public = nuxt.options.runtimeConfig.public || {};
672
+ nuxt.options.runtimeConfig.public.nuxid = {
673
+ ...nuxt.options.runtimeConfig.public.nuxid || {},
674
+ helper: {
675
+ config: helperOptions.config
676
+ }
677
+ };
651
678
  registerHelperFeature(helperOptions, {
652
- from: resolver.resolve("./runtime/helper")
679
+ from: resolver.resolve("./runtime/helper"),
680
+ plugin: resolver.resolve("./runtime/helper/plugin")
653
681
  });
654
682
  }
655
683
  if (fetcherOptions.enabled) {
@@ -16,52 +16,52 @@ import {
16
16
  startOfWeek as startOfWeekBase,
17
17
  startOfYear as startOfYearBase
18
18
  } from "date-fns";
19
- import { toDate } from "./input.js";
19
+ import { toCurrentTimezoneDate, toNativeDate } from "./context.js";
20
20
  export function startOfSecond(date) {
21
- return startOfSecondBase(toDate(date));
21
+ return toNativeDate(startOfSecondBase(toCurrentTimezoneDate(date)));
22
22
  }
23
23
  export function endOfSecond(date) {
24
- return endOfSecondBase(toDate(date));
24
+ return toNativeDate(endOfSecondBase(toCurrentTimezoneDate(date)));
25
25
  }
26
26
  export function startOfMinute(date) {
27
- return startOfMinuteBase(toDate(date));
27
+ return toNativeDate(startOfMinuteBase(toCurrentTimezoneDate(date)));
28
28
  }
29
29
  export function endOfMinute(date) {
30
- return endOfMinuteBase(toDate(date));
30
+ return toNativeDate(endOfMinuteBase(toCurrentTimezoneDate(date)));
31
31
  }
32
32
  export function startOfHour(date) {
33
- return startOfHourBase(toDate(date));
33
+ return toNativeDate(startOfHourBase(toCurrentTimezoneDate(date)));
34
34
  }
35
35
  export function endOfHour(date) {
36
- return endOfHourBase(toDate(date));
36
+ return toNativeDate(endOfHourBase(toCurrentTimezoneDate(date)));
37
37
  }
38
38
  export function startOfDay(date) {
39
- return startOfDayBase(toDate(date));
39
+ return toNativeDate(startOfDayBase(toCurrentTimezoneDate(date)));
40
40
  }
41
41
  export function endOfDay(date) {
42
- return endOfDayBase(toDate(date));
42
+ return toNativeDate(endOfDayBase(toCurrentTimezoneDate(date)));
43
43
  }
44
44
  export function startOfWeek(date) {
45
- return startOfWeekBase(toDate(date));
45
+ return toNativeDate(startOfWeekBase(toCurrentTimezoneDate(date)));
46
46
  }
47
47
  export function endOfWeek(date) {
48
- return endOfWeekBase(toDate(date));
48
+ return toNativeDate(endOfWeekBase(toCurrentTimezoneDate(date)));
49
49
  }
50
50
  export function startOfMonth(date) {
51
- return startOfMonthBase(toDate(date));
51
+ return toNativeDate(startOfMonthBase(toCurrentTimezoneDate(date)));
52
52
  }
53
53
  export function endOfMonth(date) {
54
- return endOfMonthBase(toDate(date));
54
+ return toNativeDate(endOfMonthBase(toCurrentTimezoneDate(date)));
55
55
  }
56
56
  export function startOfQuarter(date) {
57
- return startOfQuarterBase(toDate(date));
57
+ return toNativeDate(startOfQuarterBase(toCurrentTimezoneDate(date)));
58
58
  }
59
59
  export function endOfQuarter(date) {
60
- return endOfQuarterBase(toDate(date));
60
+ return toNativeDate(endOfQuarterBase(toCurrentTimezoneDate(date)));
61
61
  }
62
62
  export function startOfYear(date) {
63
- return startOfYearBase(toDate(date));
63
+ return toNativeDate(startOfYearBase(toCurrentTimezoneDate(date)));
64
64
  }
65
65
  export function endOfYear(date) {
66
- return endOfYearBase(toDate(date));
66
+ return toNativeDate(endOfYearBase(toCurrentTimezoneDate(date)));
67
67
  }
@@ -20,6 +20,7 @@ import {
20
20
  isWeekend as isWeekendBase,
21
21
  isYesterday as isYesterdayBase
22
22
  } from "date-fns";
23
+ import { toCurrentTimezoneDate } from "./context.js";
23
24
  import { toDate } from "./input.js";
24
25
  export function isBefore(date, dateToCompare) {
25
26
  return isBeforeBase(toDate(date), toDate(dateToCompare));
@@ -31,37 +32,37 @@ export function isEqual(date, dateToCompare) {
31
32
  return isEqualBase(toDate(date), toDate(dateToCompare));
32
33
  }
33
34
  export function isSameSecond(date, dateToCompare) {
34
- return isSameSecondBase(toDate(date), toDate(dateToCompare));
35
+ return isSameSecondBase(toCurrentTimezoneDate(date), toCurrentTimezoneDate(dateToCompare));
35
36
  }
36
37
  export function isSameMinute(date, dateToCompare) {
37
- return isSameMinuteBase(toDate(date), toDate(dateToCompare));
38
+ return isSameMinuteBase(toCurrentTimezoneDate(date), toCurrentTimezoneDate(dateToCompare));
38
39
  }
39
40
  export function isSameHour(date, dateToCompare) {
40
- return isSameHourBase(toDate(date), toDate(dateToCompare));
41
+ return isSameHourBase(toCurrentTimezoneDate(date), toCurrentTimezoneDate(dateToCompare));
41
42
  }
42
43
  export function isSameDay(date, dateToCompare) {
43
- return isSameDayBase(toDate(date), toDate(dateToCompare));
44
+ return isSameDayBase(toCurrentTimezoneDate(date), toCurrentTimezoneDate(dateToCompare));
44
45
  }
45
46
  export function isSameWeek(date, dateToCompare) {
46
- return isSameWeekBase(toDate(date), toDate(dateToCompare));
47
+ return isSameWeekBase(toCurrentTimezoneDate(date), toCurrentTimezoneDate(dateToCompare));
47
48
  }
48
49
  export function isSameMonth(date, dateToCompare) {
49
- return isSameMonthBase(toDate(date), toDate(dateToCompare));
50
+ return isSameMonthBase(toCurrentTimezoneDate(date), toCurrentTimezoneDate(dateToCompare));
50
51
  }
51
52
  export function isSameYear(date, dateToCompare) {
52
- return isSameYearBase(toDate(date), toDate(dateToCompare));
53
+ return isSameYearBase(toCurrentTimezoneDate(date), toCurrentTimezoneDate(dateToCompare));
53
54
  }
54
55
  export function isToday(date) {
55
- return isTodayBase(toDate(date));
56
+ return isTodayBase(toCurrentTimezoneDate(date));
56
57
  }
57
58
  export function isTomorrow(date) {
58
- return isTomorrowBase(toDate(date));
59
+ return isTomorrowBase(toCurrentTimezoneDate(date));
59
60
  }
60
61
  export function isYesterday(date) {
61
- return isYesterdayBase(toDate(date));
62
+ return isYesterdayBase(toCurrentTimezoneDate(date));
62
63
  }
63
64
  export function isWeekend(date) {
64
- return isWeekendBase(toDate(date));
65
+ return isWeekendBase(toCurrentTimezoneDate(date));
65
66
  }
66
67
  export function isPast(date) {
67
68
  return isPastBase(toDate(date));
@@ -70,13 +71,13 @@ export function isFuture(date) {
70
71
  return isFutureBase(toDate(date));
71
72
  }
72
73
  export function isThisWeek(date) {
73
- return isThisWeekBase(toDate(date));
74
+ return isThisWeekBase(toCurrentTimezoneDate(date));
74
75
  }
75
76
  export function isThisMonth(date) {
76
- return isThisMonthBase(toDate(date));
77
+ return isThisMonthBase(toCurrentTimezoneDate(date));
77
78
  }
78
79
  export function isThisYear(date) {
79
- return isThisYearBase(toDate(date));
80
+ return isThisYearBase(toCurrentTimezoneDate(date));
80
81
  }
81
82
  export function isValid(date) {
82
83
  return isValidBase(toDate(date));
@@ -0,0 +1,5 @@
1
+ import type { DateInput } from './input.js';
2
+ import type { TimezoneId } from './timezones.js';
3
+ export declare function toTimezoneDate(value: DateInput | Date, timezone: TimezoneId): import("@date-fns/tz").TZDate;
4
+ export declare function toCurrentTimezoneDate(value: DateInput | Date): import("@date-fns/tz").TZDate;
5
+ export declare function toNativeDate(value: Date): Date;
@@ -0,0 +1,13 @@
1
+ import { TZDateMini } from "@date-fns/tz";
2
+ import { toDate } from "./input.js";
3
+ import { currentTimezone } from "./timezone.js";
4
+ export function toTimezoneDate(value, timezone) {
5
+ const resolvedDate = toDate(value);
6
+ return new TZDateMini(resolvedDate.getTime(), timezone);
7
+ }
8
+ export function toCurrentTimezoneDate(value) {
9
+ return toTimezoneDate(value, currentTimezone().value);
10
+ }
11
+ export function toNativeDate(value) {
12
+ return new Date(value.getTime());
13
+ }
@@ -6,41 +6,41 @@ import {
6
6
  formatRFC3339 as formatRFC3339Date,
7
7
  formatRFC7231 as formatRFC7231Date
8
8
  } from "date-fns";
9
- import { toDate } from "./input.js";
9
+ import { toCurrentTimezoneDate } from "./context.js";
10
10
  export function format(date, formatString, options) {
11
- return formatDate(toDate(date), formatString, options);
11
+ return formatDate(toCurrentTimezoneDate(date), formatString, options);
12
12
  }
13
13
  export function formatISO(date, options) {
14
- return formatISODate(toDate(date), options);
14
+ return formatISODate(toCurrentTimezoneDate(date), options);
15
15
  }
16
16
  export function formatRFC3339(date, options) {
17
- return formatRFC3339Date(toDate(date), options);
17
+ return formatRFC3339Date(toCurrentTimezoneDate(date), options);
18
18
  }
19
19
  export function formatRFC7231(date) {
20
- return formatRFC7231Date(toDate(date));
20
+ return formatRFC7231Date(toCurrentTimezoneDate(date));
21
21
  }
22
22
  export function fromNow(date, options = {}) {
23
- return formatDistanceToNow(toDate(date), { addSuffix: true, ...options });
23
+ return formatDistanceToNow(toCurrentTimezoneDate(date), { addSuffix: true, ...options });
24
24
  }
25
25
  export function diffForHumans(date, baseDate, options = {}) {
26
- const resolvedBase = baseDate ? toDate(baseDate) : /* @__PURE__ */ new Date();
27
- return formatDistance(toDate(date), resolvedBase, { addSuffix: true, ...options });
26
+ const resolvedBase = baseDate ? toCurrentTimezoneDate(baseDate) : toCurrentTimezoneDate(/* @__PURE__ */ new Date());
27
+ return formatDistance(toCurrentTimezoneDate(date), resolvedBase, { addSuffix: true, ...options });
28
28
  }
29
29
  export function toDateString(date) {
30
- return formatDate(toDate(date), "yyyy-MM-dd");
30
+ return formatDate(toCurrentTimezoneDate(date), "yyyy-MM-dd");
31
31
  }
32
32
  export function toTimeString(date) {
33
- return formatDate(toDate(date), "HH:mm:ss");
33
+ return formatDate(toCurrentTimezoneDate(date), "HH:mm:ss");
34
34
  }
35
35
  export function toDateTimeString(date) {
36
- return formatDate(toDate(date), "yyyy-MM-dd HH:mm:ss");
36
+ return formatDate(toCurrentTimezoneDate(date), "yyyy-MM-dd HH:mm:ss");
37
37
  }
38
38
  export function toIsoString(date) {
39
- return formatISODate(toDate(date));
39
+ return formatISODate(toCurrentTimezoneDate(date));
40
40
  }
41
41
  export function toRfc3339String(date) {
42
- return formatRFC3339Date(toDate(date));
42
+ return formatRFC3339Date(toCurrentTimezoneDate(date));
43
43
  }
44
44
  export function toRfc7231String(date) {
45
- return formatRFC7231Date(toDate(date));
45
+ return formatRFC7231Date(toCurrentTimezoneDate(date));
46
46
  }
@@ -6,15 +6,18 @@ import { addDay, addDays, addHour, addHours, addMinute, addMinutes, addMonth, ad
6
6
  import { endOfDay, endOfHour, endOfMinute, endOfMonth, endOfQuarter, endOfSecond, endOfWeek, endOfYear, startOfDay, startOfHour, startOfMinute, startOfMonth, startOfQuarter, startOfSecond, startOfWeek, startOfYear } from './bounds.js';
7
7
  import { diffInDays, diffInHours, diffInMinutes, diffInMonths, diffInSeconds, diffInWeeks, diffInYears } from './diff.js';
8
8
  import { isAfter, isBefore, isEqual, isFuture, isPast, isSameDay, isSameHour, isSameMinute, isSameMonth, isSameSecond, isSameWeek, isSameYear, isThisMonth, isThisWeek, isThisYear, isToday, isTomorrow, isValid, isWeekend, isYesterday } from './compare.js';
9
- import { localDateToUTCISO, type LocalDateToUTCISOOptions } from './utc.js';
9
+ import { availableTimezones, currentTimezone } from './timezone.js';
10
+ import type { TimezoneId } from './timezones.js';
11
+ import { localDateToUTCISO } from './utc.js';
12
+ import type { LocalDateToUTCISOOptions } from './utc.js';
10
13
  export type { DateFormatPreset } from './format.js';
11
- export type { LocalDateToUTCISOOptions };
12
- export interface DateHelper {
14
+ export type { LocalDateToUTCISOOptions, TimezoneId };
15
+ declare function createDateHelper(): {
13
16
  toDate: typeof toDate;
14
17
  toUnix: typeof toUnix;
15
18
  toMillis: typeof toMillis;
16
19
  fromUnix: typeof fromUnix;
17
- fromTimestamp: typeof fromTimestamp;
20
+ fromTimestamp: typeof fromUnix;
18
21
  now: typeof now;
19
22
  today: typeof today;
20
23
  tomorrow: typeof tomorrow;
@@ -32,6 +35,8 @@ export interface DateHelper {
32
35
  toRfc3339String: typeof toRfc3339String;
33
36
  toRfc7231String: typeof toRfc7231String;
34
37
  localDateToUTCISO: typeof localDateToUTCISO;
38
+ availableTimezones: typeof availableTimezones;
39
+ currentTimezone: typeof currentTimezone;
35
40
  parse: typeof parse;
36
41
  parseISO: typeof parseISO;
37
42
  addSecond: typeof addSecond;
@@ -105,6 +110,7 @@ export interface DateHelper {
105
110
  isThisMonth: typeof isThisMonth;
106
111
  isThisYear: typeof isThisYear;
107
112
  isValid: typeof isValid;
108
- }
113
+ };
114
+ export type DateHelper = ReturnType<typeof createDateHelper>;
109
115
  export declare function dt(): DateHelper;
110
- export { type DateInput, toDate, toUnix, toMillis, fromUnix, fromTimestamp, now, today, tomorrow, yesterday, format as dateFormat, formatISO, formatRFC3339, formatRFC7231, fromNow, diffForHumans, toDateString, toTimeString, toDateTimeString, toIsoString, toRfc3339String, toRfc7231String, localDateToUTCISO, parse as dateParse, parseISO, addSecond, addSeconds, addMinute, addMinutes, addHour, addHours, addDay, addDays, addWeek, addWeeks, addMonth, addMonths, addYear, addYears, subSecond, subSeconds, subMinute, subMinutes, subHour, subHours, subDay, subDays, subWeek, subWeeks, subMonth, subMonths, subYear, subYears, startOfSecond, endOfSecond, startOfMinute, endOfMinute, startOfHour, endOfHour, startOfDay, endOfDay, startOfWeek, endOfWeek, startOfMonth, endOfMonth, startOfQuarter, endOfQuarter, startOfYear, endOfYear, diffInSeconds, diffInMinutes, diffInHours, diffInDays, diffInWeeks, diffInMonths, diffInYears, isBefore, isAfter, isEqual, isSameSecond, isSameMinute, isSameHour, isSameDay, isSameWeek, isSameMonth, isSameYear, isToday, isTomorrow, isYesterday, isWeekend, isPast, isFuture, isThisWeek, isThisMonth, isThisYear, isValid, };
116
+ export { type DateInput, toDate, toUnix, toMillis, fromUnix, fromTimestamp, now, today, tomorrow, yesterday, format as dateFormat, formatISO, formatRFC3339, formatRFC7231, fromNow, diffForHumans, toDateString, toTimeString, toDateTimeString, toIsoString, toRfc3339String, toRfc7231String, localDateToUTCISO, availableTimezones, currentTimezone, parse as dateParse, parseISO, addSecond, addSeconds, addMinute, addMinutes, addHour, addHours, addDay, addDays, addWeek, addWeeks, addMonth, addMonths, addYear, addYears, subSecond, subSeconds, subMinute, subMinutes, subHour, subHours, subDay, subDays, subWeek, subWeeks, subMonth, subMonths, subYear, subYears, startOfSecond, endOfSecond, startOfMinute, endOfMinute, startOfHour, endOfHour, startOfDay, endOfDay, startOfWeek, endOfWeek, startOfMonth, endOfMonth, startOfQuarter, endOfQuarter, startOfYear, endOfYear, diffInSeconds, diffInMinutes, diffInHours, diffInDays, diffInWeeks, diffInMonths, diffInYears, isBefore, isAfter, isEqual, isSameSecond, isSameMinute, isSameHour, isSameDay, isSameWeek, isSameMonth, isSameYear, isToday, isTomorrow, isYesterday, isWeekend, isPast, isFuture, isThisWeek, isThisMonth, isThisYear, isValid, };
@@ -94,8 +94,9 @@ import {
94
94
  isWeekend,
95
95
  isYesterday
96
96
  } from "./compare.js";
97
+ import { availableTimezones, currentTimezone } from "./timezone.js";
97
98
  import { localDateToUTCISO } from "./utc.js";
98
- export function dt() {
99
+ function createDateHelper() {
99
100
  return {
100
101
  toDate,
101
102
  toUnix,
@@ -119,6 +120,8 @@ export function dt() {
119
120
  toRfc3339String,
120
121
  toRfc7231String,
121
122
  localDateToUTCISO,
123
+ availableTimezones,
124
+ currentTimezone,
122
125
  parse,
123
126
  parseISO,
124
127
  addSecond,
@@ -194,6 +197,9 @@ export function dt() {
194
197
  isValid
195
198
  };
196
199
  }
200
+ export function dt() {
201
+ return createDateHelper();
202
+ }
197
203
  export {
198
204
  toDate,
199
205
  toUnix,
@@ -217,6 +223,8 @@ export {
217
223
  toRfc3339String,
218
224
  toRfc7231String,
219
225
  localDateToUTCISO,
226
+ availableTimezones,
227
+ currentTimezone,
220
228
  parse as dateParse,
221
229
  parseISO,
222
230
  addSecond,
@@ -1,5 +1,7 @@
1
1
  import { parseISO } from "date-fns";
2
2
  const numericPattern = /^-?\d+$/;
3
+ const dateOnlyPattern = /^\d{4}-\d{2}-\d{2}$/;
4
+ const dateTimeNoZonePattern = /^\d{4}-\d{2}-\d{2}[ T]\d{2}:\d{2}(?::\d{2}(?:\.\d{1,3})?)?$/;
3
5
  export function toDate(value) {
4
6
  if (value instanceof Date) {
5
7
  return new Date(value.getTime());
@@ -19,6 +21,12 @@ export function toDate(value) {
19
21
  const isMilliseconds = trimmed.length >= 13;
20
22
  return new Date(isMilliseconds ? numeric : numeric * 1e3);
21
23
  }
24
+ if (dateOnlyPattern.test(trimmed)) {
25
+ return /* @__PURE__ */ new Date(`${trimmed}T00:00:00.000Z`);
26
+ }
27
+ if (dateTimeNoZonePattern.test(trimmed)) {
28
+ return /* @__PURE__ */ new Date(trimmed.replace(" ", "T") + "Z");
29
+ }
22
30
  const isoDate = parseISO(trimmed);
23
31
  if (!Number.isNaN(isoDate.getTime())) {
24
32
  return isoDate;
@@ -1,13 +1,14 @@
1
- import { startOfToday, startOfTomorrow, startOfYesterday } from "date-fns";
1
+ import { addDays, startOfDay, subDays } from "date-fns";
2
+ import { toCurrentTimezoneDate, toNativeDate } from "./context.js";
2
3
  export function now() {
3
4
  return /* @__PURE__ */ new Date();
4
5
  }
5
6
  export function today() {
6
- return startOfToday();
7
+ return toNativeDate(startOfDay(toCurrentTimezoneDate(/* @__PURE__ */ new Date())));
7
8
  }
8
9
  export function tomorrow() {
9
- return startOfTomorrow();
10
+ return toNativeDate(startOfDay(addDays(toCurrentTimezoneDate(/* @__PURE__ */ new Date()), 1)));
10
11
  }
11
12
  export function yesterday() {
12
- return startOfYesterday();
13
+ return toNativeDate(startOfDay(subDays(toCurrentTimezoneDate(/* @__PURE__ */ new Date()), 1)));
13
14
  }
@@ -1,8 +1,14 @@
1
1
  import { parse as parseDate, parseISO as parseISODate } from "date-fns";
2
2
  import { toDate } from "./input.js";
3
+ import { toNativeDate, toTimezoneDate } from "./context.js";
3
4
  export function parse(value, formatString, baseDate = /* @__PURE__ */ new Date(), options) {
4
- return parseDate(value, formatString, toDate(baseDate), options);
5
+ const parsedDate = parseDate(value, formatString, toTimezoneDate(baseDate, "UTC"), options);
6
+ return toNativeDate(parsedDate);
5
7
  }
6
8
  export function parseISO(value) {
7
- return parseISODate(value);
9
+ const parsedDate = parseISODate(value);
10
+ if (!Number.isNaN(parsedDate.getTime())) {
11
+ return toDate(value);
12
+ }
13
+ return parsedDate;
8
14
  }
@@ -14,87 +14,87 @@ import {
14
14
  subWeeks as subWeeksBase,
15
15
  subYears as subYearsBase
16
16
  } from "date-fns";
17
- import { toDate } from "./input.js";
17
+ import { toCurrentTimezoneDate, toNativeDate } from "./context.js";
18
18
  export function addSeconds(date, amount) {
19
- return addSecondsBase(toDate(date), amount);
19
+ return toNativeDate(addSecondsBase(toCurrentTimezoneDate(date), amount));
20
20
  }
21
21
  export function addSecond(date) {
22
22
  return addSeconds(date, 1);
23
23
  }
24
24
  export function addMinutes(date, amount) {
25
- return addMinutesBase(toDate(date), amount);
25
+ return toNativeDate(addMinutesBase(toCurrentTimezoneDate(date), amount));
26
26
  }
27
27
  export function addMinute(date) {
28
28
  return addMinutes(date, 1);
29
29
  }
30
30
  export function addHours(date, amount) {
31
- return addHoursBase(toDate(date), amount);
31
+ return toNativeDate(addHoursBase(toCurrentTimezoneDate(date), amount));
32
32
  }
33
33
  export function addHour(date) {
34
34
  return addHours(date, 1);
35
35
  }
36
36
  export function addDays(date, amount) {
37
- return addDaysBase(toDate(date), amount);
37
+ return toNativeDate(addDaysBase(toCurrentTimezoneDate(date), amount));
38
38
  }
39
39
  export function addDay(date) {
40
40
  return addDays(date, 1);
41
41
  }
42
42
  export function addWeeks(date, amount) {
43
- return addWeeksBase(toDate(date), amount);
43
+ return toNativeDate(addWeeksBase(toCurrentTimezoneDate(date), amount));
44
44
  }
45
45
  export function addWeek(date) {
46
46
  return addWeeks(date, 1);
47
47
  }
48
48
  export function addMonths(date, amount) {
49
- return addMonthsBase(toDate(date), amount);
49
+ return toNativeDate(addMonthsBase(toCurrentTimezoneDate(date), amount));
50
50
  }
51
51
  export function addMonth(date) {
52
52
  return addMonths(date, 1);
53
53
  }
54
54
  export function addYears(date, amount) {
55
- return addYearsBase(toDate(date), amount);
55
+ return toNativeDate(addYearsBase(toCurrentTimezoneDate(date), amount));
56
56
  }
57
57
  export function addYear(date) {
58
58
  return addYears(date, 1);
59
59
  }
60
60
  export function subSeconds(date, amount) {
61
- return subSecondsBase(toDate(date), amount);
61
+ return toNativeDate(subSecondsBase(toCurrentTimezoneDate(date), amount));
62
62
  }
63
63
  export function subSecond(date) {
64
64
  return subSeconds(date, 1);
65
65
  }
66
66
  export function subMinutes(date, amount) {
67
- return subMinutesBase(toDate(date), amount);
67
+ return toNativeDate(subMinutesBase(toCurrentTimezoneDate(date), amount));
68
68
  }
69
69
  export function subMinute(date) {
70
70
  return subMinutes(date, 1);
71
71
  }
72
72
  export function subHours(date, amount) {
73
- return subHoursBase(toDate(date), amount);
73
+ return toNativeDate(subHoursBase(toCurrentTimezoneDate(date), amount));
74
74
  }
75
75
  export function subHour(date) {
76
76
  return subHours(date, 1);
77
77
  }
78
78
  export function subDays(date, amount) {
79
- return subDaysBase(toDate(date), amount);
79
+ return toNativeDate(subDaysBase(toCurrentTimezoneDate(date), amount));
80
80
  }
81
81
  export function subDay(date) {
82
82
  return subDays(date, 1);
83
83
  }
84
84
  export function subWeeks(date, amount) {
85
- return subWeeksBase(toDate(date), amount);
85
+ return toNativeDate(subWeeksBase(toCurrentTimezoneDate(date), amount));
86
86
  }
87
87
  export function subWeek(date) {
88
88
  return subWeeks(date, 1);
89
89
  }
90
90
  export function subMonths(date, amount) {
91
- return subMonthsBase(toDate(date), amount);
91
+ return toNativeDate(subMonthsBase(toCurrentTimezoneDate(date), amount));
92
92
  }
93
93
  export function subMonth(date) {
94
94
  return subMonths(date, 1);
95
95
  }
96
96
  export function subYears(date, amount) {
97
- return subYearsBase(toDate(date), amount);
97
+ return toNativeDate(subYearsBase(toCurrentTimezoneDate(date), amount));
98
98
  }
99
99
  export function subYear(date) {
100
100
  return subYears(date, 1);
@@ -0,0 +1,7 @@
1
+ import type { Ref } from 'vue';
2
+ import { type TimezoneId } from './timezones.js';
3
+ export declare function availableTimezones(): TimezoneId[];
4
+ export declare function currentTimezone(): Readonly<Ref<TimezoneId>>;
5
+ export declare function isTimezoneId(value: string): value is TimezoneId;
6
+ export declare function normalizeTimezone(rawValue?: string | null): TimezoneId | undefined;
7
+ export declare function setCurrentTimezone(value: string | undefined, fallback?: TimezoneId): TimezoneId;