compote-ui 0.52.4 → 0.52.5

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.
@@ -16,12 +16,18 @@
16
16
  defaultValue,
17
17
  label,
18
18
  name,
19
+ timeZone = getLocalTimeZone(),
20
+ hideTimeZone,
19
21
  onValueChange,
20
22
  ...restProps
21
23
  }: DateInputProps = $props();
22
24
 
23
25
  const absoluteDateTimeRe = /(?:Z|[+-]\d{2}:\d{2})$/;
24
26
 
27
+ function isAbsoluteDateTime(v: NativeDateInput): boolean {
28
+ return typeof v === 'string' && v.includes('T') && absoluteDateTimeRe.test(v);
29
+ }
30
+
25
31
  function toDateValue(v: NativeDateInput): DateValue | null {
26
32
  if (v == null) return null;
27
33
  if (typeof v === 'string') {
@@ -29,7 +35,7 @@
29
35
  if (v.includes('T')) {
30
36
  // ZonedDateTime.toString() format: "2024-01-15T10:30:00+02:00[Europe/Belgrade]"
31
37
  if (v.includes('[')) return parseZonedDateTime(v);
32
- if (absoluteDateTimeRe.test(v)) return parseAbsolute(v, 'UTC');
38
+ if (absoluteDateTimeRe.test(v)) return parseAbsolute(v, timeZone);
33
39
  return parseDateTime(v);
34
40
  }
35
41
  return parseDate(v);
@@ -41,7 +47,7 @@
41
47
  function fromDateValue(dv: DateValue | null, source: NativeDateInput): NativeDateInput {
42
48
  if (dv == null) return null;
43
49
  if (typeof source === 'string') {
44
- if (absoluteDateTimeRe.test(source)) return dv.toDate('UTC').toISOString();
50
+ if (absoluteDateTimeRe.test(source)) return dv.toDate(timeZone).toISOString();
45
51
  return dv.toString();
46
52
  }
47
53
  if (source instanceof Date) return dv.toDate(getLocalTimeZone());
@@ -50,10 +56,13 @@
50
56
 
51
57
  const arkValue = $derived(toDateValue(value));
52
58
  const arkDefault = $derived(toDateValue(defaultValue));
59
+ const shouldHideTimeZone = $derived(hideTimeZone ?? isAbsoluteDateTime(value));
53
60
  </script>
54
61
 
55
62
  <DateInput.Root
56
63
  {...restProps}
64
+ {timeZone}
65
+ hideTimeZone={shouldHideTimeZone}
57
66
  value={arkValue ? [arkValue] : []}
58
67
  defaultValue={arkDefault ? [arkDefault] : undefined}
59
68
  onValueChange={(details) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "compote-ui",
3
- "version": "0.52.4",
3
+ "version": "0.52.5",
4
4
  "license": "MIT",
5
5
  "scripts": {
6
6
  "dev": "vite dev --open",