@iyulab/components 2.20.0 → 2.20.1

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/CHANGELOG.md CHANGED
@@ -1,5 +1,15 @@
1
1
  # Changelog
2
2
 
3
+ ## [2.20.1] - 2026-10-12
4
+
5
+ ### Fixed
6
+
7
+ - `u-date-picker` and `u-date-range-picker` in `mode="datetime"` read a value written with another offset as the
8
+ instant it names. A value such as `2026-09-06T22:22:34Z` showed `22:22` on a `+09:00` machine, and editing it wrote
9
+ that wall clock back with the local offset, moving the stored instant by nine hours. The picker now shows the local
10
+ time of that instant, writes edits in the local offset for the same moment, and keeps the given string (no `change`)
11
+ when a pick leaves the instant as it was. `start` and `end` on the range picker still return the halves as written.
12
+
3
13
  ## [2.20.0] - 2026-10-10
4
14
 
5
15
  ### Changed
@@ -1,3 +1,4 @@
1
+ import { sameDateTime } from "./datetime.js";
1
2
  //#region src/components/calendar/date-text-controller.ts
2
3
  /**
3
4
  * The typed-date text box shared by `u-date-picker` and `u-date-range-picker`: what is being typed
@@ -52,8 +53,8 @@ var DateTextController = class {
52
53
  const next = this.options.toValue(text);
53
54
  this.badText = next === null;
54
55
  const value = next ?? void 0;
55
- const changed = value !== this.host.value;
56
- this.host.value = value;
56
+ const changed = !sameDateTime(value, this.host.value);
57
+ if (changed) this.host.value = value;
57
58
  this.draft = this.badText ? text : null;
58
59
  this.host.requestUpdate();
59
60
  if (changed) this.options.onChange();
@@ -3,8 +3,19 @@
3
3
  export declare function localOffset(date: Date): string;
4
4
  /** ISO day + `HH:mm` or `HH:mm:ss` → `YYYY-MM-DDTHH:mm:ss±HH:mm` (the offset of that local day and time). */
5
5
  export declare function toDateTimeOffset(day: string, time: string): string;
6
+ /** A date-time value as this browser's wall clock — `YYYY-MM-DDTHH:mm:ss±HH:mm` in the local offset.
7
+ * A value with an offset is an instant: `2026-09-06T22:22:34Z` reads `2026-09-07T07:22:34+09:00` in
8
+ * Seoul, the same moment. A value without one is already wall clock and comes back as it is, and so
9
+ * does anything that is not a date-time. Every read of a picker value goes through here, so what
10
+ * the picker shows and what it writes back describe the same instant. */
11
+ export declare function toLocalDateTime(value: string): string;
12
+ /** Whether two picker values are the same — a day, a date-time, or a `start/end` interval of either,
13
+ * compared half by half as instants when they carry offsets. A value written back in the local
14
+ * offset is then not a change from the `…Z` it came from, and the picker keeps the string it was given. */
15
+ export declare function sameDateTime(a: string | undefined, b: string | undefined): boolean;
6
16
  /** Splits a value into its ISO day and its time — `HH:mm`, or `HH:mm:ss` with `seconds`
7
- * (`00:00` when there is no time part). */
17
+ * (`00:00` when there is no time part). A value with an offset is read as this browser's wall clock
18
+ * ({@link toLocalDateTime}). */
8
19
  export declare function splitDateTime(value: string, seconds?: boolean): {
9
20
  day: string;
10
21
  time: string;
@@ -15,10 +15,34 @@ function toDateTimeOffset(day, time) {
15
15
  local.setHours(h, m, s);
16
16
  return `${day}T${normalizeTime(time, true)}${localOffset(local)}`;
17
17
  }
18
+ /** A date-time with a UTC designator or offset after its time (`…Z`, `…+09:00`, `…-0530`). */
19
+ var WITH_OFFSET = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}(?::\d{2}(?:\.\d+)?)?(?:Z|[+-]\d{2}:?\d{2})$/i;
20
+ /** A date-time value as this browser's wall clock — `YYYY-MM-DDTHH:mm:ss±HH:mm` in the local offset.
21
+ * A value with an offset is an instant: `2026-09-06T22:22:34Z` reads `2026-09-07T07:22:34+09:00` in
22
+ * Seoul, the same moment. A value without one is already wall clock and comes back as it is, and so
23
+ * does anything that is not a date-time. Every read of a picker value goes through here, so what
24
+ * the picker shows and what it writes back describe the same instant. */
25
+ function toLocalDateTime(value) {
26
+ if (!WITH_OFFSET.test(value)) return value;
27
+ const instant = new Date(value);
28
+ if (Number.isNaN(instant.getTime())) return value;
29
+ const pad = (n) => String(n).padStart(2, "0");
30
+ return toDateTimeOffset(`${instant.getFullYear()}-${pad(instant.getMonth() + 1)}-${pad(instant.getDate())}`, `${pad(instant.getHours())}:${pad(instant.getMinutes())}:${pad(instant.getSeconds())}`);
31
+ }
32
+ /** Whether two picker values are the same — a day, a date-time, or a `start/end` interval of either,
33
+ * compared half by half as instants when they carry offsets. A value written back in the local
34
+ * offset is then not a change from the `…Z` it came from, and the picker keeps the string it was given. */
35
+ function sameDateTime(a, b) {
36
+ if (a === b) return true;
37
+ if (!a || !b) return false;
38
+ const local = (v) => v.split("/").map(toLocalDateTime).join("/");
39
+ return local(a) === local(b);
40
+ }
18
41
  /** Splits a value into its ISO day and its time — `HH:mm`, or `HH:mm:ss` with `seconds`
19
- * (`00:00` when there is no time part). */
42
+ * (`00:00` when there is no time part). A value with an offset is read as this browser's wall clock
43
+ * ({@link toLocalDateTime}). */
20
44
  function splitDateTime(value, seconds = false) {
21
- const [day, rest] = value.split("T");
45
+ const [day, rest] = toLocalDateTime(value).split("T");
22
46
  const match = rest?.match(/^\d{2}:\d{2}(?::\d{2})?/);
23
47
  return {
24
48
  day,
@@ -32,4 +56,4 @@ function normalizeTime(time, seconds) {
32
56
  return seconds ? `${hm}:${time.slice(6, 8) || "00"}` : hm;
33
57
  }
34
58
  //#endregion
35
- export { localOffset, normalizeTime, splitDateTime, toDateTimeOffset };
59
+ export { localOffset, normalizeTime, sameDateTime, splitDateTime, toDateTimeOffset, toLocalDateTime };
@@ -10,8 +10,8 @@ import { UCalendar } from "../calendar/UCalendar.js";
10
10
  import "../field/UField.js";
11
11
  import { UPopover } from "../popover/UPopover.js";
12
12
  import { CharsWidthController } from "../../utilities/chars.js";
13
+ import { normalizeTime, sameDateTime, splitDateTime, toDateTimeOffset } from "../calendar/datetime.js";
13
14
  import { DateTextController } from "../calendar/date-text-controller.js";
14
- import { normalizeTime, splitDateTime, toDateTimeOffset } from "../calendar/datetime.js";
15
15
  import { styles } from "../calendar/picker.styles.js";
16
16
  import { styles as styles$1 } from "./UDatePicker.styles.js";
17
17
  import { html } from "lit";
@@ -81,9 +81,9 @@ var UDatePicker = class UDatePicker extends UFormControlElement {
81
81
  }
82
82
  if (!this.value) return;
83
83
  const iso = buildValue(splitValue(this.value).date, this.mode, time);
84
- const changed = iso !== this.value;
84
+ const changed = !sameDateTime(iso, this.value);
85
85
  this.textEntry.clear();
86
- this.value = iso;
86
+ if (changed) this.value = iso;
87
87
  if (changed) this.emitChange();
88
88
  };
89
89
  this.handleDaySelect = (e) => {
@@ -124,9 +124,9 @@ var UDatePicker = class UDatePicker extends UFormControlElement {
124
124
  };
125
125
  this.handleApplyClick = () => {
126
126
  const next = this.staged;
127
- const changed = next !== this.value;
127
+ const changed = !sameDateTime(next, this.value);
128
128
  this.textEntry.clear();
129
- this.value = next;
129
+ if (changed) this.value = next;
130
130
  if (changed) this.emitChange();
131
131
  this.popoverEl?.hide();
132
132
  (this.textInputEl ?? this.containerEl)?.focus();
@@ -313,9 +313,9 @@ var UDatePicker = class UDatePicker extends UFormControlElement {
313
313
  this.staged = iso;
314
314
  return;
315
315
  }
316
- const changed = iso !== this.value;
316
+ const changed = !sameDateTime(iso, this.value);
317
317
  this.textEntry.clear();
318
- this.value = iso;
318
+ if (changed) this.value = iso;
319
319
  if (changed) this.emitChange();
320
320
  this.popoverEl?.hide();
321
321
  (this.textInputEl ?? this.containerEl)?.focus();
@@ -11,8 +11,8 @@ import { UCalendar } from "../calendar/UCalendar.js";
11
11
  import "../field/UField.js";
12
12
  import { UPopover } from "../popover/UPopover.js";
13
13
  import { CharsWidthController } from "../../utilities/chars.js";
14
+ import { normalizeTime, sameDateTime, splitDateTime, toDateTimeOffset, toLocalDateTime } from "../calendar/datetime.js";
14
15
  import { DateTextController } from "../calendar/date-text-controller.js";
15
- import { normalizeTime, splitDateTime, toDateTimeOffset } from "../calendar/datetime.js";
16
16
  import { styles } from "../calendar/picker.styles.js";
17
17
  import { resolvePresets } from "./presets.js";
18
18
  import { styles as styles$1 } from "./UDateRangePicker.styles.js";
@@ -22,14 +22,18 @@ import { ifDefined } from "lit/directives/if-defined.js";
22
22
  //#region src/components/date-range-picker/UDateRangePicker.ts
23
23
  var ISO_DATE = /^\d{4}-\d{2}-\d{2}$/;
24
24
  var ISO_DATE_TIME = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}/;
25
- /** Splits `"start/end"` into its two halves — ISO dates, or in `mode="datetime"` ISO date-times;
26
- * `undefined` unless both halves have that shape. */
27
- function parseInterval(value, mode) {
25
+ /** Splits `"start/end"` into its two halves — ISO dates, or in `mode="datetime"` ISO date-times read
26
+ * as this browser's wall clock (a half with an offset is an instant — `toLocalDateTime`), or as
27
+ * written with `local` off; `undefined` unless both halves have that shape. */
28
+ function parseInterval(value, mode, local = true) {
28
29
  if (!value) return void 0;
29
30
  const [start, end, ...rest] = value.split("/");
30
31
  const shape = mode === "datetime" ? ISO_DATE_TIME : ISO_DATE;
31
32
  if (rest.length || !shape.test(start ?? "") || !shape.test(end ?? "")) return void 0;
32
- return {
33
+ return mode === "datetime" && local ? {
34
+ start: toLocalDateTime(start),
35
+ end: toLocalDateTime(end)
36
+ } : {
33
37
  start,
34
38
  end
35
39
  };
@@ -38,8 +42,8 @@ function parseInterval(value, mode) {
38
42
  function reversed(start, end, mode) {
39
43
  return mode === "datetime" ? new Date(start).getTime() > new Date(end).getTime() : start > end;
40
44
  }
41
- /** The ISO day of a half (`YYYY-MM-DD` either way). */
42
- var dayPart = (half) => half.slice(0, 10);
45
+ /** The ISO day of a half (`YYYY-MM-DD` either way) — a half with an offset on this browser's wall clock. */
46
+ var dayPart = (half) => splitDateTime(half).day;
43
47
  var UDateRangePicker = class UDateRangePicker extends UFormControlElement {
44
48
  constructor(..._args) {
45
49
  super(..._args);
@@ -139,12 +143,12 @@ var UDateRangePicker = class UDateRangePicker extends UFormControlElement {
139
143
  /** Start of the range — the ISO day, or in `mode="datetime"` the ISO date-time; `undefined` when
140
144
  * there is no complete range. */
141
145
  get start() {
142
- return parseInterval(this.value, this.mode)?.start;
146
+ return parseInterval(this.value, this.mode, false)?.start;
143
147
  }
144
148
  /** End of the range — the ISO day, or in `mode="datetime"` the ISO date-time; `undefined` when
145
149
  * there is no complete range. */
146
150
  get end() {
147
- return parseInterval(this.value, this.mode)?.end;
151
+ return parseInterval(this.value, this.mode, false)?.end;
148
152
  }
149
153
  /** Times a whole-day range takes in `mode="datetime"` — a preset or a first calendar pick: from
150
154
  * the first minute (or second, with `seconds`) to the last. */
@@ -360,9 +364,9 @@ var UDateRangePicker = class UDateRangePicker extends UFormControlElement {
360
364
  this.staged = next;
361
365
  return;
362
366
  }
363
- const changed = next !== this.value;
367
+ const changed = !sameDateTime(next, this.value);
364
368
  this.textEntry.clear();
365
- this.value = next;
369
+ if (changed) this.value = next;
366
370
  if (changed) this.emitChange();
367
371
  }
368
372
  renderPresets(presets) {
@@ -370,7 +374,7 @@ var UDateRangePicker = class UDateRangePicker extends UFormControlElement {
370
374
  <div class="presets" part="presets" role="group" aria-label=${Locale.getValue("quickRanges")}>
371
375
  ${presets.map((p) => html`
372
376
  <button type="button" class="preset" part="preset"
373
- aria-pressed=${this.build(p.start, p.end, this.wholeDay) === this.working}
377
+ aria-pressed=${sameDateTime(this.build(p.start, p.end, this.wholeDay), this.working)}
374
378
  ?disabled=${this.unavailable(p)}
375
379
  @click=${() => this.commitRange(p.start, p.end, this.wholeDay)}
376
380
  >${p.label}</button>
@@ -401,9 +405,9 @@ var UDateRangePicker = class UDateRangePicker extends UFormControlElement {
401
405
  /** Commits `next` as the value (firing `change` when it differs), closes the calendar and
402
406
  * returns focus to the text box. */
403
407
  commitValue(next) {
404
- const changed = next !== this.value;
408
+ const changed = !sameDateTime(next, this.value);
405
409
  this.textEntry.clear();
406
- this.value = next;
410
+ if (changed) this.value = next;
407
411
  if (changed) this.emitChange();
408
412
  this.popoverEl?.hide();
409
413
  this.textInputEl?.focus();
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@iyulab/components",
3
3
  "description": "web-components library based on lit-element made by iyulab",
4
- "version": "2.20.0",
4
+ "version": "2.20.1",
5
5
  "keywords": [
6
6
  "iyulab",
7
7
  "components",
@@ -10,7 +10,11 @@ Single-date(-time) selection with a popover calendar. `mode="date"` (default) fo
10
10
  convention as the native `input[type=date]`: an ISO `YYYY-MM-DD` string. `mode="datetime"` adds
11
11
  a time-of-day input and the value becomes a complete ISO-8601 `DateTimeOffset` string
12
12
  (`YYYY-MM-DDTHH:mm:ss±HH:mm`, seconds and the browser's local UTC offset always filled in — the
13
- value is unconditionally valid regardless of how coarse the time input was). Form-associated.
13
+ value is unconditionally valid regardless of how coarse the time input was). A value set with any
14
+ other offset — a server's UTC `…Z` — is read as the instant it names and shown in the browser's local
15
+ time, so `2026-09-06T22:22:34Z` shows `2026-09-07 07:22` in Seoul and picking the next day writes the
16
+ same moment one day later. The value keeps the string it was given until the person changes it.
17
+ Form-associated.
14
18
 
15
19
  > The calendar week always starts on Sunday, regardless of locale.
16
20
 
@@ -45,7 +45,9 @@ exported as `parseDateRange` and `formatDateRangeText`.
45
45
 
46
46
  `mode="datetime"` adds a start time and an end time under the calendar (labelled inputs). Each half of
47
47
  the value is then a complete ISO-8601 `DateTimeOffset` — seconds and the browser's local offset are
48
- always filled in — and `start`/`end` return those halves:
48
+ always filled in — and `start`/`end` return those halves. A half written with another offset (a
49
+ server's UTC `…Z`) is read as an instant and shown in the browser's local time, the same as
50
+ `u-date-picker`:
49
51
 
50
52
  ```html
51
53
  <u-date-range-picker name="shift" label="Shift" mode="datetime"