@iyulab/components 2.20.3 → 2.21.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/CHANGELOG.md +17 -0
- package/dist/components/calendar/datetime.d.ts +2 -3
- package/dist/components/calendar/datetime.js +3 -15
- package/dist/index.d.ts +1 -0
- package/dist/index.js +2 -1
- package/dist/utilities/dateValue.d.ts +36 -0
- package/dist/utilities/dateValue.js +79 -0
- package/dist/utilities/format.js +8 -17
- package/package.json +1 -1
- package/skills/iyulab-components/references/utilities/format.md +29 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,22 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [2.21.0] - 2026-10-12
|
|
4
|
+
|
|
5
|
+
### Added
|
|
6
|
+
|
|
7
|
+
- **Date values** — `readDateValue(value)` reads the three kinds of date text an app receives and says which
|
|
8
|
+
one it is: `instant` (a date-time with `Z` or an offset — that moment), `plainDateTime` (no offset — local wall
|
|
9
|
+
clock) and `plainDate` (`YYYY-MM-DD` — local midnight, not UTC midnight). It returns `null` for a day or time that
|
|
10
|
+
does not exist (`2026-02-30`) instead of a rolled-over date. `writeInstant`, `writePlainDateTime`,
|
|
11
|
+
`writePlainDate` and `localOffset` write a date back in the kind it was read. The date pickers and `formatDate`
|
|
12
|
+
read through it.
|
|
13
|
+
|
|
14
|
+
### Changed
|
|
15
|
+
|
|
16
|
+
- `formatDate` shows ISO-shaped text that names no real day (`2026-02-30`) as the text itself, as it does for
|
|
17
|
+
other invalid input — it used to format the rolled-over date (March 2). Text that is not ISO-shaped still goes
|
|
18
|
+
to the platform parser.
|
|
19
|
+
|
|
3
20
|
## [2.20.3] - 2026-10-12
|
|
4
21
|
|
|
5
22
|
### Fixed
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
export declare function localOffset(date: Date): string;
|
|
1
|
+
import { localOffset } from '../../utilities/dateValue.js';
|
|
2
|
+
export { localOffset };
|
|
4
3
|
/** ISO day + `HH:mm` or `HH:mm:ss` → `YYYY-MM-DDTHH:mm:ss±HH:mm` (the offset of that local day and time). */
|
|
5
4
|
export declare function toDateTimeOffset(day: string, time: string): string;
|
|
6
5
|
/** A date-time value as this browser's wall clock — `YYYY-MM-DDTHH:mm:ss±HH:mm` in the local offset.
|
|
@@ -1,13 +1,6 @@
|
|
|
1
|
+
import { localOffset, readDateValue, writeInstant } from "../../utilities/dateValue.js";
|
|
1
2
|
import { parseISODate } from "./dates.js";
|
|
2
3
|
//#region src/components/calendar/datetime.ts
|
|
3
|
-
/** `±HH:mm` for the browser's local timezone at `date` (DST-aware — recomputed per date,
|
|
4
|
-
* not cached — `getTimezoneOffset()`'s sign is the inverse of the ISO-8601 offset sign). */
|
|
5
|
-
function localOffset(date) {
|
|
6
|
-
const minutes = -date.getTimezoneOffset();
|
|
7
|
-
const sign = minutes >= 0 ? "+" : "-";
|
|
8
|
-
const abs = Math.abs(minutes);
|
|
9
|
-
return `${sign}${String(Math.floor(abs / 60)).padStart(2, "0")}:${String(abs % 60).padStart(2, "0")}`;
|
|
10
|
-
}
|
|
11
4
|
/** ISO day + `HH:mm` or `HH:mm:ss` → `YYYY-MM-DDTHH:mm:ss±HH:mm` (the offset of that local day and time). */
|
|
12
5
|
function toDateTimeOffset(day, time) {
|
|
13
6
|
const [h, m, s = 0] = time.split(":").map(Number);
|
|
@@ -15,19 +8,14 @@ function toDateTimeOffset(day, time) {
|
|
|
15
8
|
local.setHours(h, m, s);
|
|
16
9
|
return `${day}T${normalizeTime(time, true)}${localOffset(local)}`;
|
|
17
10
|
}
|
|
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
11
|
/** A date-time value as this browser's wall clock — `YYYY-MM-DDTHH:mm:ss±HH:mm` in the local offset.
|
|
21
12
|
* A value with an offset is an instant: `2026-09-06T22:22:34Z` reads `2026-09-07T07:22:34+09:00` in
|
|
22
13
|
* Seoul, the same moment. A value without one is already wall clock and comes back as it is, and so
|
|
23
14
|
* does anything that is not a date-time. Every read of a picker value goes through here, so what
|
|
24
15
|
* the picker shows and what it writes back describe the same instant. */
|
|
25
16
|
function toLocalDateTime(value) {
|
|
26
|
-
|
|
27
|
-
|
|
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())}`);
|
|
17
|
+
const read = readDateValue(value);
|
|
18
|
+
return read?.kind === "instant" ? writeInstant(read.date) : value;
|
|
31
19
|
}
|
|
32
20
|
/** Whether two picker values are the same — a day, a date-time, or a `start/end` interval of either,
|
|
33
21
|
* compared half by half as instants when they carry offsets. A value written back in the local
|
package/dist/index.d.ts
CHANGED
|
@@ -63,6 +63,7 @@ export * from './events/ShowEvent';
|
|
|
63
63
|
export * from './utilities/BrowserStorage.js';
|
|
64
64
|
export * from './utilities/clipboard.js';
|
|
65
65
|
export * from './utilities/converters.js';
|
|
66
|
+
export * from './utilities/dateValue.js';
|
|
66
67
|
export * from './utilities/devWarning.js';
|
|
67
68
|
export * from './utilities/Dialog.js';
|
|
68
69
|
export * from './utilities/elements.js';
|
package/dist/index.js
CHANGED
|
@@ -26,6 +26,7 @@ import { UCheckbox } from "./components/checkbox/UCheckbox.js";
|
|
|
26
26
|
import { UTag } from "./components/tag/UTag.js";
|
|
27
27
|
import { UChip } from "./components/chip/UChip.js";
|
|
28
28
|
import { UCopyButton } from "./components/copy-button/UCopyButton.js";
|
|
29
|
+
import { localOffset, readDateValue, writeInstant, writePlainDate, writePlainDateTime } from "./utilities/dateValue.js";
|
|
29
30
|
import { dateTextPattern, formatCurrency, formatDate, formatDateRange, formatDateRangeText, formatDateText, formatDateTimeRangeText, formatDateTimeText, formatNumber, parseDate, parseDateRange, parseDateTime, parseDateTimeRange, parseNumber } from "./utilities/format.js";
|
|
30
31
|
import { UField } from "./components/field/UField.js";
|
|
31
32
|
import { UPopover } from "./components/popover/UPopover.js";
|
|
@@ -65,4 +66,4 @@ import { Dialog } from "./utilities/Dialog.js";
|
|
|
65
66
|
import { Theme } from "./utilities/Theme.js";
|
|
66
67
|
import { Toast } from "./utilities/Toast.js";
|
|
67
68
|
import { decodeDelimited, decodeTsv, encodeTsv } from "./utilities/tsv.js";
|
|
68
|
-
export { ALERT_STATUSES, BrowserStorage, Dialog, IconCache, IconRegistry, Locale, OverlayManager, Theme, Toast, UAlert, UAvatar, UBadge, UBreadcrumb, UBreadcrumbItem, UButton, UButtonGroup, UCard, UCarousel, UCheckbox, UChip, UCopyButton, UDatePicker, UDateRangePicker, UDialog, UDivider, UDrawer, UElement, UExpander, UField, UFileInput, UFloatingElement, UForm, UFormControlElement, UIcon, UIconButton, UInput, UMenu, UMenuItem, UOption, UOverlayElement, UPagination, UPanel, UPopover, UProgressBar, UProgressRing, URadio, URating, USelect, USkeleton, USlider, USpinner, USplitPanel, USteps, USwitch, UTab, UTabPanel, UTag, UText, UTextarea, UTooltip, UTree, UTreeItem, arrayAttrConverter, booleanAttrConverter, copyFromKey, createDevWarner, dateAttrConverter, dateTextPattern, decodeDelimited, decodeTsv, devWarnOnce, encodeTsv, formatCurrency, formatDate, formatDateRange, formatDateRangeText, formatDateText, formatDateTimeRangeText, formatDateTimeText, formatNumber, getDefaultBaseUrl, getParentElement, isCoarsePointer, isFocusCandidate, isFromControl, isImeComposing, isTextEntry, jsonAttrConverter, parseDate, parseDateRange, parseDateTime, parseDateTimeRange, parseNumber, pasteFromKey, querySelectorAllWithin, querySelectorDeep, querySelectorWithin, resetDevWarnings, setDefaultBaseUrl, urlAttrConverter };
|
|
69
|
+
export { ALERT_STATUSES, BrowserStorage, Dialog, IconCache, IconRegistry, Locale, OverlayManager, Theme, Toast, UAlert, UAvatar, UBadge, UBreadcrumb, UBreadcrumbItem, UButton, UButtonGroup, UCard, UCarousel, UCheckbox, UChip, UCopyButton, UDatePicker, UDateRangePicker, UDialog, UDivider, UDrawer, UElement, UExpander, UField, UFileInput, UFloatingElement, UForm, UFormControlElement, UIcon, UIconButton, UInput, UMenu, UMenuItem, UOption, UOverlayElement, UPagination, UPanel, UPopover, UProgressBar, UProgressRing, URadio, URating, USelect, USkeleton, USlider, USpinner, USplitPanel, USteps, USwitch, UTab, UTabPanel, UTag, UText, UTextarea, UTooltip, UTree, UTreeItem, arrayAttrConverter, booleanAttrConverter, copyFromKey, createDevWarner, dateAttrConverter, dateTextPattern, decodeDelimited, decodeTsv, devWarnOnce, encodeTsv, formatCurrency, formatDate, formatDateRange, formatDateRangeText, formatDateText, formatDateTimeRangeText, formatDateTimeText, formatNumber, getDefaultBaseUrl, getParentElement, isCoarsePointer, isFocusCandidate, isFromControl, isImeComposing, isTextEntry, jsonAttrConverter, localOffset, parseDate, parseDateRange, parseDateTime, parseDateTimeRange, parseNumber, pasteFromKey, querySelectorAllWithin, querySelectorDeep, querySelectorWithin, readDateValue, resetDevWarnings, setDefaultBaseUrl, urlAttrConverter, writeInstant, writePlainDate, writePlainDateTime };
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The three kinds of date value an app receives as text, read and written in one place.
|
|
3
|
+
* The names come from Temporal:
|
|
4
|
+
*
|
|
5
|
+
* - **`instant`** — a date-time with an offset or `Z` (`2026-09-06T22:22:34Z`, `…+09:00`). It names one
|
|
6
|
+
* moment everywhere; shown here, it is this browser's wall clock at that moment.
|
|
7
|
+
* - **`plainDateTime`** — a date-time without an offset (`2026-09-06T22:22`, `2026-09-06 22:22:34`). It is a
|
|
8
|
+
* wall clock already and is read as local time, never shifted.
|
|
9
|
+
* - **`plainDate`** — a calendar day (`2026-09-06`). It is local midnight of that day. `new Date('2026-09-06')`
|
|
10
|
+
* is UTC midnight instead, which is the previous day west of Greenwich.
|
|
11
|
+
*
|
|
12
|
+
* A `Date` is an instant. Text that is none of the three, or names a day that does not exist
|
|
13
|
+
* (`2026-02-30`), reads as `null` — never a rolled-over or guessed date.
|
|
14
|
+
*/
|
|
15
|
+
export type DateValueKind = 'instant' | 'plainDateTime' | 'plainDate';
|
|
16
|
+
/** A date value with the kind its text named. `date` is the moment it means here. */
|
|
17
|
+
export interface DateValue {
|
|
18
|
+
kind: DateValueKind;
|
|
19
|
+
date: Date;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Reads a date value and tells which kind it is. `null` for text that is not one of the three
|
|
23
|
+
* kinds, for a day or time that does not exist, and for an invalid `Date`.
|
|
24
|
+
*/
|
|
25
|
+
export declare function readDateValue(value: Date | string): DateValue | null;
|
|
26
|
+
/** `±HH:mm` for this browser's time zone at `date` — recomputed per date, so a DST change is honoured
|
|
27
|
+
* (`getTimezoneOffset()`'s sign is the inverse of the ISO-8601 sign). */
|
|
28
|
+
export declare function localOffset(date: Date): string;
|
|
29
|
+
/** The local calendar day of `date` — `YYYY-MM-DD`. */
|
|
30
|
+
export declare function writePlainDate(date: Date): string;
|
|
31
|
+
/** The local wall clock of `date` without an offset — `YYYY-MM-DDTHH:mm:ss`, or `YYYY-MM-DDTHH:mm`
|
|
32
|
+
* when `seconds` is `false`. */
|
|
33
|
+
export declare function writePlainDateTime(date: Date, seconds?: boolean): string;
|
|
34
|
+
/** The moment `date` names, written as this browser's wall clock with its offset —
|
|
35
|
+
* `YYYY-MM-DDTHH:mm:ss±HH:mm`. `2026-09-06T22:22:34Z` read in Seoul writes `2026-09-07T07:22:34+09:00`. */
|
|
36
|
+
export declare function writeInstant(date: Date): string;
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
//#region src/utilities/dateValue.ts
|
|
2
|
+
var PLAIN_DATE = /^(\d{4})-(\d{2})-(\d{2})$/;
|
|
3
|
+
var DATE_TIME = /^(\d{4})-(\d{2})-(\d{2})[T ](\d{2}):(\d{2})(?::(\d{2})(?:\.(\d{1,9}))?)?(Z|[+-]\d{2}:?\d{2})?$/i;
|
|
4
|
+
/** Whether the fields name a real calendar day and clock time — `Date` rolls `2026-02-30` into March and
|
|
5
|
+
* `24:00` into the next day; the check runs in UTC so no time zone moves a field. */
|
|
6
|
+
function realFields(y, m, d, h = 0, min = 0, s = 0) {
|
|
7
|
+
const u = new Date(Date.UTC(y, m - 1, d, h, min, s));
|
|
8
|
+
return u.getUTCFullYear() === y && u.getUTCMonth() === m - 1 && u.getUTCDate() === d && u.getUTCHours() === h && u.getUTCMinutes() === min && u.getUTCSeconds() === s;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Reads a date value and tells which kind it is. `null` for text that is not one of the three
|
|
12
|
+
* kinds, for a day or time that does not exist, and for an invalid `Date`.
|
|
13
|
+
*/
|
|
14
|
+
function readDateValue(value) {
|
|
15
|
+
if (value instanceof Date) return Number.isNaN(value.getTime()) ? null : {
|
|
16
|
+
kind: "instant",
|
|
17
|
+
date: value
|
|
18
|
+
};
|
|
19
|
+
const text = value.trim();
|
|
20
|
+
const day = PLAIN_DATE.exec(text);
|
|
21
|
+
if (day) {
|
|
22
|
+
const [y, m, d] = [
|
|
23
|
+
Number(day[1]),
|
|
24
|
+
Number(day[2]),
|
|
25
|
+
Number(day[3])
|
|
26
|
+
];
|
|
27
|
+
return realFields(y, m, d) ? {
|
|
28
|
+
kind: "plainDate",
|
|
29
|
+
date: new Date(y, m - 1, d)
|
|
30
|
+
} : null;
|
|
31
|
+
}
|
|
32
|
+
const dt = DATE_TIME.exec(text);
|
|
33
|
+
if (!dt) return null;
|
|
34
|
+
const [y, m, d, h, min, s] = [
|
|
35
|
+
1,
|
|
36
|
+
2,
|
|
37
|
+
3,
|
|
38
|
+
4,
|
|
39
|
+
5,
|
|
40
|
+
6
|
|
41
|
+
].map((i) => Number(dt[i] ?? 0));
|
|
42
|
+
const ms = dt[7] ? Number(dt[7].slice(0, 3).padEnd(3, "0")) : 0;
|
|
43
|
+
if (!realFields(y, m, d, h, min, s)) return null;
|
|
44
|
+
const zone = dt[8];
|
|
45
|
+
if (!zone) return {
|
|
46
|
+
kind: "plainDateTime",
|
|
47
|
+
date: new Date(y, m - 1, d, h, min, s, ms)
|
|
48
|
+
};
|
|
49
|
+
const offset = zone.toUpperCase() === "Z" ? 0 : (zone[0] === "-" ? -1 : 1) * (Number(zone.slice(1, 3)) * 60 + Number(zone.slice(-2)));
|
|
50
|
+
return {
|
|
51
|
+
kind: "instant",
|
|
52
|
+
date: /* @__PURE__ */ new Date(Date.UTC(y, m - 1, d, h, min, s, ms) - offset * 6e4)
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
var pad = (n, width = 2) => String(n).padStart(width, "0");
|
|
56
|
+
/** `±HH:mm` for this browser's time zone at `date` — recomputed per date, so a DST change is honoured
|
|
57
|
+
* (`getTimezoneOffset()`'s sign is the inverse of the ISO-8601 sign). */
|
|
58
|
+
function localOffset(date) {
|
|
59
|
+
const minutes = -date.getTimezoneOffset();
|
|
60
|
+
const abs = Math.abs(minutes);
|
|
61
|
+
return `${minutes >= 0 ? "+" : "-"}${pad(Math.floor(abs / 60))}:${pad(abs % 60)}`;
|
|
62
|
+
}
|
|
63
|
+
/** The local calendar day of `date` — `YYYY-MM-DD`. */
|
|
64
|
+
function writePlainDate(date) {
|
|
65
|
+
return `${pad(date.getFullYear(), 4)}-${pad(date.getMonth() + 1)}-${pad(date.getDate())}`;
|
|
66
|
+
}
|
|
67
|
+
/** The local wall clock of `date` without an offset — `YYYY-MM-DDTHH:mm:ss`, or `YYYY-MM-DDTHH:mm`
|
|
68
|
+
* when `seconds` is `false`. */
|
|
69
|
+
function writePlainDateTime(date, seconds = true) {
|
|
70
|
+
const time = `${pad(date.getHours())}:${pad(date.getMinutes())}${seconds ? `:${pad(date.getSeconds())}` : ""}`;
|
|
71
|
+
return `${writePlainDate(date)}T${time}`;
|
|
72
|
+
}
|
|
73
|
+
/** The moment `date` names, written as this browser's wall clock with its offset —
|
|
74
|
+
* `YYYY-MM-DDTHH:mm:ss±HH:mm`. `2026-09-06T22:22:34Z` read in Seoul writes `2026-09-07T07:22:34+09:00`. */
|
|
75
|
+
function writeInstant(date) {
|
|
76
|
+
return `${writePlainDateTime(date)}${localOffset(date)}`;
|
|
77
|
+
}
|
|
78
|
+
//#endregion
|
|
79
|
+
export { localOffset, readDateValue, writeInstant, writePlainDate, writePlainDateTime };
|
package/dist/utilities/format.js
CHANGED
|
@@ -1,25 +1,16 @@
|
|
|
1
1
|
import { Locale } from "./Locale.js";
|
|
2
|
+
import { readDateValue } from "./dateValue.js";
|
|
2
3
|
//#region src/utilities/format.ts
|
|
3
4
|
/**
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
* `
|
|
8
|
-
*
|
|
9
|
-
* A full ISO datetime (e.g. `2026-02-24T09:00:00Z`) is unambiguous — it carries
|
|
10
|
-
* its own timezone — so the local-time-safe split isn't needed there; when the
|
|
11
|
-
* split doesn't yield three numbers, fall back to native parsing instead of
|
|
12
|
-
* producing an Invalid Date.
|
|
13
|
-
*/
|
|
14
|
-
function parseISODate(iso) {
|
|
15
|
-
const [y, m, d] = iso.split("-").map(Number);
|
|
16
|
-
return Number.isNaN(y) || Number.isNaN(m) || Number.isNaN(d) ? new Date(iso) : new Date(y, m - 1, d);
|
|
17
|
-
}
|
|
18
|
-
/**
|
|
19
|
-
* Resolves a Date or ISO date string to a Date object.
|
|
5
|
+
* Resolves a Date or date string to a Date — through {@link readDateValue}, so a `YYYY-MM-DD` day is local
|
|
6
|
+
* midnight (not UTC midnight, which is the previous day west of Greenwich), a date-time without an offset is
|
|
7
|
+
* local wall clock, and one with an offset is that instant. ISO-shaped text that names no real day
|
|
8
|
+
* (`2026-02-30`) is an invalid `Date` — not March 2. Other text goes to the platform parser, as it always did.
|
|
20
9
|
*/
|
|
21
10
|
function resolve(value) {
|
|
22
|
-
|
|
11
|
+
const read = readDateValue(value);
|
|
12
|
+
if (read) return read.date;
|
|
13
|
+
return typeof value === "string" && !/^\d{4}-\d{2}-\d{2}/.test(value.trim()) ? new Date(value) : /* @__PURE__ */ new Date(NaN);
|
|
23
14
|
}
|
|
24
15
|
/**
|
|
25
16
|
* Wraps `Intl.NumberFormat` with the active locale (`Locale.get()` if omitted).
|
package/package.json
CHANGED
|
@@ -52,9 +52,11 @@ formatDate('2026-03-14', { dateStyle: 'long' });
|
|
|
52
52
|
formatDate(order.createdAt, { dateStyle: 'short', timeStyle: 'short' });
|
|
53
53
|
```
|
|
54
54
|
|
|
55
|
-
Accepts a `Date` or
|
|
56
|
-
not UTC** — `'2026-03-14'` is midnight where the user is, so a date
|
|
57
|
-
across time zones the way `new Date('2026-03-14')` does
|
|
55
|
+
Accepts a `Date` or a date string, read by [`readDateValue`](#date-values--readdatevalue-and-writers): a
|
|
56
|
+
`YYYY-MM-DD` day is **local midnight, not UTC** — `'2026-03-14'` is midnight where the user is, so a date
|
|
57
|
+
never shifts a day across time zones the way `new Date('2026-03-14')` does; a date-time without an offset is
|
|
58
|
+
local wall clock; one with an offset (`…Z`, `…+09:00`) is that instant. ISO-shaped text that names no real
|
|
59
|
+
day (`2026-02-30`) is treated as invalid rather than rolled into March; other text goes to the platform parser.
|
|
58
60
|
|
|
59
61
|
A value that cannot be resolved to a real date — a malformed string, or an already-invalid
|
|
60
62
|
`Date` — returns `String(value)` instead of throwing. `Intl.DateTimeFormat.format()` throws
|
|
@@ -65,6 +67,30 @@ That degrade is **deliberately not symmetric** with `formatCurrency`: a date arr
|
|
|
65
67
|
data (an API, a user, a stale cache), so a bad one is an expected runtime state; a currency
|
|
66
68
|
code is written at the call site, so a bad one is a bug worth surfacing.
|
|
67
69
|
|
|
70
|
+
## Date values — `readDateValue` and writers
|
|
71
|
+
|
|
72
|
+
```ts
|
|
73
|
+
import { readDateValue, writeInstant, writePlainDate, writePlainDateTime } from '@iyulab/components';
|
|
74
|
+
|
|
75
|
+
const read = readDateValue('2026-09-06T22:22:34Z');
|
|
76
|
+
// { kind: 'instant', date } — in Seoul, writeInstant(read.date) is '2026-09-07T07:22:34+09:00'
|
|
77
|
+
if (read?.kind === 'plainDate') console.log(writePlainDate(read.date));
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
An app receives dates as text of three kinds, named after Temporal:
|
|
81
|
+
|
|
82
|
+
| kind | text | means here |
|
|
83
|
+
|---|---|---|
|
|
84
|
+
| `instant` | a date-time with `Z` or an offset (`…+09:00`, `…-0500`) | that moment; shown as this browser's wall clock |
|
|
85
|
+
| `plainDateTime` | a date-time without an offset (`2026-09-06T22:22`, `2026-09-06 22:22:34`) | that wall clock, local |
|
|
86
|
+
| `plainDate` | a day (`2026-09-06`) | local midnight of that day |
|
|
87
|
+
|
|
88
|
+
`readDateValue(value)` returns `{ kind, date }`, or `null` for text that is none of the three or names a day or
|
|
89
|
+
time that does not exist. A `Date` reads as an `instant`. Write back in the kind you read so the value keeps its
|
|
90
|
+
meaning: `writeInstant(date)` (local offset, same moment), `writePlainDateTime(date, seconds?)`,
|
|
91
|
+
`writePlainDate(date)`. `localOffset(date)` gives the `±HH:mm` of that date (daylight saving is per date).
|
|
92
|
+
`formatDate` and the date pickers read through the same function.
|
|
93
|
+
|
|
68
94
|
## Locale
|
|
69
95
|
|
|
70
96
|
All three read `Locale.get()` when `locale` is omitted, so they follow whatever
|