@aquera/nile-elements 2.0.20 → 2.0.22
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 +7 -0
- package/dist/floating-ui.dom-9df9f37b.cjs.js +2 -0
- package/dist/floating-ui.dom-9df9f37b.cjs.js.map +1 -0
- package/dist/floating-ui.dom-c4ea6a32.esm.js +1 -0
- package/dist/index.cjs.js +1 -1
- package/dist/index.esm.js +1 -1
- package/dist/index.js +598 -488
- package/dist/nile-auto-complete/index.cjs.js +1 -1
- package/dist/nile-auto-complete/index.esm.js +1 -1
- package/dist/nile-auto-complete/nile-auto-complete.cjs.js +1 -1
- package/dist/nile-auto-complete/nile-auto-complete.esm.js +1 -1
- package/dist/nile-auto-complete/portal-manager.cjs.js +1 -1
- package/dist/nile-auto-complete/portal-manager.esm.js +1 -1
- package/dist/nile-button/nile-button.cjs.js +1 -1
- package/dist/nile-button/nile-button.cjs.js.map +1 -1
- package/dist/nile-button/nile-button.css.cjs.js +1 -1
- package/dist/nile-button/nile-button.css.cjs.js.map +1 -1
- package/dist/nile-button/nile-button.css.esm.js +46 -9
- package/dist/nile-button/nile-button.esm.js +6 -6
- package/dist/nile-color-picker/index.cjs.js +1 -1
- package/dist/nile-color-picker/index.esm.js +1 -1
- package/dist/nile-color-picker/nile-color-picker.cjs.js +1 -1
- package/dist/nile-color-picker/nile-color-picker.esm.js +1 -1
- package/dist/nile-combobox/index.cjs.js +1 -1
- package/dist/nile-combobox/index.esm.js +1 -1
- package/dist/nile-combobox/nile-combobox.cjs.js +1 -1
- package/dist/nile-combobox/nile-combobox.esm.js +1 -1
- package/dist/nile-combobox/portal-manager.cjs.js +1 -1
- package/dist/nile-combobox/portal-manager.esm.js +1 -1
- package/dist/nile-dropdown/index.cjs.js +1 -1
- package/dist/nile-dropdown/index.esm.js +1 -1
- package/dist/nile-dropdown/nile-dropdown.cjs.js +1 -1
- package/dist/nile-dropdown/nile-dropdown.esm.js +1 -1
- package/dist/nile-dropdown/portal-manager.cjs.js +1 -1
- package/dist/nile-dropdown/portal-manager.esm.js +1 -1
- package/dist/nile-empty-state/nile-empty-state.cjs.js +1 -1
- package/dist/nile-empty-state/nile-empty-state.cjs.js.map +1 -1
- package/dist/nile-empty-state/nile-empty-state.esm.js +4 -4
- package/dist/nile-markdown-editor/index.cjs.js +1 -1
- package/dist/nile-markdown-editor/index.esm.js +1 -1
- package/dist/nile-markdown-editor/nile-markdown-editor.cjs.js +1 -1
- package/dist/nile-markdown-editor/nile-markdown-editor.esm.js +1 -1
- package/dist/nile-popover/index.cjs.js +1 -1
- package/dist/nile-popover/index.esm.js +1 -1
- package/dist/nile-popover/nile-popover.cjs.js +1 -1
- package/dist/nile-popover/nile-popover.esm.js +1 -1
- package/dist/nile-popover/portal-manager.cjs.js +1 -1
- package/dist/nile-popover/portal-manager.esm.js +1 -1
- package/dist/nile-popup/index.cjs.js +1 -1
- package/dist/nile-popup/index.esm.js +1 -1
- package/dist/nile-popup/nile-popup.cjs.js +1 -1
- package/dist/nile-popup/nile-popup.esm.js +1 -1
- package/dist/nile-select/index.cjs.js +1 -1
- package/dist/nile-select/index.esm.js +1 -1
- package/dist/nile-select/nile-select.cjs.js +1 -1
- package/dist/nile-select/nile-select.esm.js +1 -1
- package/dist/nile-select/portal-manager.cjs.js +1 -1
- package/dist/nile-select/portal-manager.esm.js +1 -1
- package/dist/nile-side-bar-action/index.cjs.js +1 -1
- package/dist/nile-side-bar-action/index.esm.js +1 -1
- package/dist/nile-side-bar-action/nile-side-bar-action.cjs.js +1 -1
- package/dist/nile-side-bar-action/nile-side-bar-action.esm.js +1 -1
- package/dist/nile-side-bar-action/portal-manager.cjs.js +1 -1
- package/dist/nile-side-bar-action/portal-manager.esm.js +1 -1
- package/dist/nile-tooltip/index.cjs.js +1 -1
- package/dist/nile-tooltip/index.esm.js +1 -1
- package/dist/nile-tooltip/nile-tooltip.cjs.js +1 -1
- package/dist/nile-tooltip/nile-tooltip.esm.js +1 -1
- package/dist/nile-virtual-select/index.cjs.js +1 -1
- package/dist/nile-virtual-select/index.esm.js +1 -1
- package/dist/nile-virtual-select/nile-virtual-select.cjs.js +1 -1
- package/dist/nile-virtual-select/nile-virtual-select.esm.js +1 -1
- package/dist/nile-virtual-select/portal-manager.cjs.js +1 -1
- package/dist/nile-virtual-select/portal-manager.esm.js +1 -1
- package/dist/nile-wysiwyg-editor/index.cjs.js +1 -1
- package/dist/nile-wysiwyg-editor/index.esm.js +1 -1
- package/dist/nile-wysiwyg-editor/nile-wysiwyg-editor.cjs.js +1 -1
- package/dist/nile-wysiwyg-editor/nile-wysiwyg-editor.cjs.js.map +1 -1
- package/dist/nile-wysiwyg-editor/nile-wysiwyg-editor.css.cjs.js +1 -1
- package/dist/nile-wysiwyg-editor/nile-wysiwyg-editor.css.cjs.js.map +1 -1
- package/dist/nile-wysiwyg-editor/nile-wysiwyg-editor.css.esm.js +73 -1
- package/dist/nile-wysiwyg-editor/nile-wysiwyg-editor.esm.js +3 -2
- package/dist/nile-wysiwyg-editor/nile-wysiwyg-toolbar/index.cjs.js +1 -1
- package/dist/nile-wysiwyg-editor/nile-wysiwyg-toolbar/index.esm.js +1 -1
- package/dist/nile-wysiwyg-editor/nile-wysiwyg-toolbar/nile-wysiwyg-toolbar.cjs.js +1 -1
- package/dist/nile-wysiwyg-editor/nile-wysiwyg-toolbar/nile-wysiwyg-toolbar.esm.js +1 -1
- package/dist/nile-wysiwyg-editor/types.cjs.js +1 -1
- package/dist/nile-wysiwyg-editor/types.cjs.js.map +1 -1
- package/dist/nile-wysiwyg-editor/types.esm.js +1 -1
- package/dist/src/nile-button/nile-button.css.js +46 -9
- package/dist/src/nile-button/nile-button.css.js.map +1 -1
- package/dist/src/nile-button/nile-button.d.ts +2 -2
- package/dist/src/nile-button/nile-button.js +13 -5
- package/dist/src/nile-button/nile-button.js.map +1 -1
- package/dist/src/nile-button/nile-button.test.js +140 -2
- package/dist/src/nile-button/nile-button.test.js.map +1 -1
- package/dist/src/nile-date-time-picker/nile-date-time-picker.phases-1.test.d.ts +47 -0
- package/dist/src/nile-date-time-picker/nile-date-time-picker.phases-1.test.js +578 -0
- package/dist/src/nile-date-time-picker/nile-date-time-picker.phases-1.test.js.map +1 -0
- package/dist/src/nile-date-time-picker/nile-date-time-picker.phases-2.test.d.ts +3 -0
- package/dist/src/nile-date-time-picker/nile-date-time-picker.phases-2.test.js +109 -0
- package/dist/src/nile-date-time-picker/nile-date-time-picker.phases-2.test.js.map +1 -0
- package/dist/src/nile-date-time-picker/nile-date-time-picker.phases-3.test.d.ts +3 -0
- package/dist/src/nile-date-time-picker/nile-date-time-picker.phases-3.test.js +356 -0
- package/dist/src/nile-date-time-picker/nile-date-time-picker.phases-3.test.js.map +1 -0
- package/dist/src/nile-date-time-picker/nile-date-time-picker.phases-4.test.d.ts +4 -0
- package/dist/src/nile-date-time-picker/nile-date-time-picker.phases-4.test.js +339 -0
- package/dist/src/nile-date-time-picker/nile-date-time-picker.phases-4.test.js.map +1 -0
- package/dist/src/nile-date-time-picker/nile-date-time-picker.regressions.test.d.ts +3 -0
- package/dist/src/nile-date-time-picker/nile-date-time-picker.regressions.test.js +1472 -0
- package/dist/src/nile-date-time-picker/nile-date-time-picker.regressions.test.js.map +1 -0
- package/dist/src/nile-date-time-picker/nile-date-time-picker.test-helpers.d.ts +103 -0
- package/dist/src/nile-date-time-picker/nile-date-time-picker.test-helpers.js +331 -0
- package/dist/src/nile-date-time-picker/nile-date-time-picker.test-helpers.js.map +1 -0
- package/dist/src/nile-date-time-picker/nile-date-time-picker.test.d.ts +0 -140
- package/dist/src/nile-date-time-picker/nile-date-time-picker.test.js +1 -4495
- package/dist/src/nile-date-time-picker/nile-date-time-picker.test.js.map +1 -1
- package/dist/src/nile-date-time-picker/nile-date-time-picker.year-handling.test.d.ts +3 -0
- package/dist/src/nile-date-time-picker/nile-date-time-picker.year-handling.test.js +1440 -0
- package/dist/src/nile-date-time-picker/nile-date-time-picker.year-handling.test.js.map +1 -0
- package/dist/src/nile-empty-state/nile-empty-state.d.ts +5 -0
- package/dist/src/nile-empty-state/nile-empty-state.js +11 -2
- package/dist/src/nile-empty-state/nile-empty-state.js.map +1 -1
- package/dist/src/nile-empty-state/nile-empty-state.test.js +31 -0
- package/dist/src/nile-empty-state/nile-empty-state.test.js.map +1 -1
- package/dist/src/nile-wysiwyg-editor/index.d.ts +2 -1
- package/dist/src/nile-wysiwyg-editor/index.js +1 -1
- package/dist/src/nile-wysiwyg-editor/index.js.map +1 -1
- package/dist/src/nile-wysiwyg-editor/nile-wysiwyg-editor.css.js +75 -0
- package/dist/src/nile-wysiwyg-editor/nile-wysiwyg-editor.css.js.map +1 -1
- package/dist/src/nile-wysiwyg-editor/nile-wysiwyg-editor.d.ts +20 -0
- package/dist/src/nile-wysiwyg-editor/nile-wysiwyg-editor.js +37 -1
- package/dist/src/nile-wysiwyg-editor/nile-wysiwyg-editor.js.map +1 -1
- package/dist/src/nile-wysiwyg-editor/nile-wysiwyg-editor.test.js +108 -0
- package/dist/src/nile-wysiwyg-editor/nile-wysiwyg-editor.test.js.map +1 -1
- package/dist/src/nile-wysiwyg-editor/types.d.ts +8 -0
- package/dist/src/nile-wysiwyg-editor/types.js +50 -0
- package/dist/src/nile-wysiwyg-editor/types.js.map +1 -1
- package/dist/src/version.js +1 -1
- package/dist/src/version.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +2 -2
- package/rollup.config.js +1 -0
- package/scripts/component-metrics.mjs +145 -0
- package/scripts/merge-coverage.cjs +33 -0
- package/src/nile-button/nile-button.css.ts +46 -9
- package/src/nile-button/nile-button.test.ts +162 -2
- package/src/nile-button/nile-button.ts +13 -4
- package/src/nile-date-time-picker/nile-date-time-picker.phases-1.test.ts +607 -0
- package/src/nile-date-time-picker/nile-date-time-picker.phases-2.test.ts +112 -0
- package/src/nile-date-time-picker/nile-date-time-picker.phases-3.test.ts +389 -0
- package/src/nile-date-time-picker/nile-date-time-picker.phases-4.test.ts +329 -0
- package/src/nile-date-time-picker/nile-date-time-picker.regressions.test.ts +1618 -0
- package/src/nile-date-time-picker/nile-date-time-picker.test-helpers.ts +381 -0
- package/src/nile-date-time-picker/nile-date-time-picker.test.ts +1 -4771
- package/src/nile-date-time-picker/nile-date-time-picker.year-handling.test.ts +1499 -0
- package/src/nile-empty-state/nile-empty-state.test.ts +24 -0
- package/src/nile-empty-state/nile-empty-state.ts +12 -2
- package/src/nile-wysiwyg-editor/index.ts +2 -1
- package/src/nile-wysiwyg-editor/nile-wysiwyg-editor.css.ts +76 -0
- package/src/nile-wysiwyg-editor/nile-wysiwyg-editor.test.ts +132 -0
- package/src/nile-wysiwyg-editor/nile-wysiwyg-editor.ts +40 -1
- package/src/nile-wysiwyg-editor/types.ts +52 -0
- package/test-timings.json +41 -0
- package/vscode-html-custom-data.json +42 -3
- package/web-test-runner.config.mjs +72 -2
- package/dist/floating-ui.dom-007bbe96.cjs.js +0 -2
- package/dist/floating-ui.dom-007bbe96.cjs.js.map +0 -1
- package/dist/floating-ui.dom-cc9126da.esm.js +0 -1
|
@@ -0,0 +1,381 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Top-level helpers shared by more than one nile-date-time-picker.*.test.ts file
|
|
3
|
+
* (moved verbatim from the original single test file). Not a test file itself.
|
|
4
|
+
*/
|
|
5
|
+
import { fixture, html } from '@open-wc/testing';
|
|
6
|
+
import { utcFromFields, localDateFromFields } from '../nile-calendar/timezones';
|
|
7
|
+
|
|
8
|
+
/* PART 1 — INDEPENDENT ORACLE (shared subset; the rest stays in nile-date-time-picker.phases.test.ts) */
|
|
9
|
+
|
|
10
|
+
export type Wall = {
|
|
11
|
+
year: number; month: number; day: number; // month is 1-BASED
|
|
12
|
+
hours: number; minutes: number; seconds: number; ms: number;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
/* ── B. epoch -> true UTC offset in a zone ────────────────────────────────── */
|
|
16
|
+
|
|
17
|
+
const OFFSET_FMT_CACHE = new Map<string, Intl.DateTimeFormat>();
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* The zone's real offset at an instant, in ms, east-positive.
|
|
21
|
+
* Independent mechanism: reads Intl's own printed offset string rather than
|
|
22
|
+
* reconstructing it from formatted date parts.
|
|
23
|
+
*/
|
|
24
|
+
export function offsetAt(epochMs: number, zone: string): number {
|
|
25
|
+
let fmt = OFFSET_FMT_CACHE.get(zone);
|
|
26
|
+
if (!fmt) {
|
|
27
|
+
fmt = new Intl.DateTimeFormat('en-US', { timeZone: zone, timeZoneName: 'longOffset' });
|
|
28
|
+
OFFSET_FMT_CACHE.set(zone, fmt);
|
|
29
|
+
}
|
|
30
|
+
const part = fmt.formatToParts(new Date(epochMs)).find(p => p.type === 'timeZoneName');
|
|
31
|
+
if (!part) throw new Error(`no timeZoneName part for ${zone}`);
|
|
32
|
+
const t = part.value.trim();
|
|
33
|
+
// "GMT" (exactly) means +00:00; otherwise "GMT+05:30" / "GMT-03:30" / "GMT+14"
|
|
34
|
+
if (t === 'GMT' || t === 'UTC') return 0;
|
|
35
|
+
const m = /^(?:GMT|UTC)([+-])(\d{1,2})(?::(\d{2}))?(?::(\d{2}))?$/.exec(t);
|
|
36
|
+
if (!m) throw new Error(`unparsable offset "${t}" for ${zone}`);
|
|
37
|
+
const sign = m[1] === '-' ? -1 : 1;
|
|
38
|
+
const h = Number(m[2]);
|
|
39
|
+
const mi = Number(m[3] ?? 0);
|
|
40
|
+
const s = Number(m[4] ?? 0);
|
|
41
|
+
return sign * (h * 3600000 + mi * 60000 + s * 1000);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/* ── A. epoch -> wall clock in a zone ─────────────────────────────────────── */
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Derived from the offset by pure UTC arithmetic — NOT by formatting the date
|
|
48
|
+
* into y/m/d/h/m/s parts. Independent of the implementation's approach.
|
|
49
|
+
*/
|
|
50
|
+
export function wallAt(epochMs: number, zone: string): Wall {
|
|
51
|
+
const local = epochMs + offsetAt(epochMs, zone);
|
|
52
|
+
const d = new Date(local);
|
|
53
|
+
return {
|
|
54
|
+
year: d.getUTCFullYear(), month: d.getUTCMonth() + 1, day: d.getUTCDate(),
|
|
55
|
+
hours: d.getUTCHours(), minutes: d.getUTCMinutes(),
|
|
56
|
+
seconds: d.getUTCSeconds(), ms: d.getUTCMilliseconds(),
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export function wallEquals(a: Wall, b: Wall): boolean {
|
|
61
|
+
return a.year === b.year && a.month === b.month && a.day === b.day &&
|
|
62
|
+
a.hours === b.hours && a.minutes === b.minutes &&
|
|
63
|
+
a.seconds === b.seconds && a.ms === b.ms;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** Nile bracketed form -> its parts. Independent regex. */
|
|
67
|
+
export function parseBracketed(
|
|
68
|
+
raw: string
|
|
69
|
+
): { wall: Wall; offsetMs: number; zone: string } | null {
|
|
70
|
+
const m = /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})(?:\.(\d{1,3}))?\[GMT([+-])(\d{2}):(\d{2})\s+([^\]]+)\]$/
|
|
71
|
+
.exec(raw.trim());
|
|
72
|
+
if (!m) return null;
|
|
73
|
+
const [, y, mo, d, h, mi, s, frac, sign, oh, om, zone] = m;
|
|
74
|
+
return {
|
|
75
|
+
wall: {
|
|
76
|
+
year: Number(y), month: Number(mo), day: Number(d),
|
|
77
|
+
hours: Number(h), minutes: Number(mi), seconds: Number(s),
|
|
78
|
+
ms: frac === undefined ? 0 : Number(frac.padEnd(3, '0')),
|
|
79
|
+
},
|
|
80
|
+
offsetMs: (sign === '-' ? -1 : 1) * (Number(oh) * 3600000 + Number(om) * 60000),
|
|
81
|
+
zone: zone.trim(),
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export const fmtWall = (w: Wall): string =>
|
|
86
|
+
`${String(w.year).padStart(4, '0')}-${String(w.month).padStart(2, '0')}-${String(w.day).padStart(2, '0')}` +
|
|
87
|
+
`T${String(w.hours).padStart(2, '0')}:${String(w.minutes).padStart(2, '0')}:${String(w.seconds).padStart(2, '0')}` +
|
|
88
|
+
`.${String(w.ms).padStart(3, '0')}`;
|
|
89
|
+
|
|
90
|
+
/* PART 2 — DRIVER + INVARIANT CHECKER (shared subset) */
|
|
91
|
+
|
|
92
|
+
export type Payload = {
|
|
93
|
+
value: string | null;
|
|
94
|
+
localTimezoneValue: Date | null;
|
|
95
|
+
unixEpoch: number | null;
|
|
96
|
+
timezone: string;
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
export type Violation = { code: string; detail: string };
|
|
100
|
+
|
|
101
|
+
/* ── driving the real component ───────────────────────────────────────────── */
|
|
102
|
+
|
|
103
|
+
export async function makePicker(attrs: { value?: string | null; timezone?: string }): Promise<any> {
|
|
104
|
+
const el: any = attrs.value === undefined || attrs.value === null
|
|
105
|
+
? await fixture(html`<nile-date-time-picker .timezone=${attrs.timezone ?? 'UTC'}></nile-date-time-picker>`)
|
|
106
|
+
: await fixture(html`<nile-date-time-picker
|
|
107
|
+
value=${attrs.value} .timezone=${attrs.timezone ?? 'UTC'}></nile-date-time-picker>`);
|
|
108
|
+
await settle2(el);
|
|
109
|
+
return el;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
export async function settle(el: any): Promise<any> {
|
|
113
|
+
await el.updateComplete;
|
|
114
|
+
const cal = el.calendarElement;
|
|
115
|
+
if (cal) await cal.updateComplete;
|
|
116
|
+
return cal;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/** A preset value may adopt a zone, scheduling a second update. Settle twice. */
|
|
120
|
+
export async function settle2(el: any): Promise<any> {
|
|
121
|
+
await settle(el);
|
|
122
|
+
return settle(el);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
export let LAST_EMIT_COUNT = 0;
|
|
126
|
+
|
|
127
|
+
export const applyButton = (cal: any): HTMLElement =>
|
|
128
|
+
cal.shadowRoot.querySelector('.apply-button') as HTMLElement;
|
|
129
|
+
|
|
130
|
+
/** Click the real Apply button and capture the single committed payload. */
|
|
131
|
+
export async function apply(el: any): Promise<Payload | null> {
|
|
132
|
+
const cal = await settle(el);
|
|
133
|
+
let detail: Payload | null = null;
|
|
134
|
+
let count = 0;
|
|
135
|
+
const onChange = (e: Event) => { detail = (e as CustomEvent).detail; count += 1; };
|
|
136
|
+
el.addEventListener('nile-change', onChange);
|
|
137
|
+
applyButton(cal).click();
|
|
138
|
+
await settle(el);
|
|
139
|
+
el.removeEventListener('nile-change', onChange);
|
|
140
|
+
// Apply legitimately emits nothing when there is no selection — record the
|
|
141
|
+
// count without assuming a payload exists.
|
|
142
|
+
LAST_EMIT_COUNT = count;
|
|
143
|
+
if (detail) (detail as any).__emitCount = count;
|
|
144
|
+
return detail;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/* ── PHASE 16: the invariant checker ─────────────────────────────────────── */
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* Every assertion is made against the ORACLE, never against component helpers.
|
|
151
|
+
* Returns [] when the payload is internally consistent.
|
|
152
|
+
*/
|
|
153
|
+
export function checkPayload(p: Payload | null, intendedZone?: string): Violation[] {
|
|
154
|
+
const v: Violation[] = [];
|
|
155
|
+
if (!p) return [{ code: 'NO_PAYLOAD', detail: 'Apply emitted nothing' }];
|
|
156
|
+
|
|
157
|
+
if (p.unixEpoch === null) {
|
|
158
|
+
if (p.value !== null) v.push({ code: 'NULL_EPOCH_WITH_VALUE', detail: `value=${p.value}` });
|
|
159
|
+
return v;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
// A. localTimezoneValue mirrors the epoch
|
|
163
|
+
if (!p.localTimezoneValue || p.localTimezoneValue.getTime() !== p.unixEpoch) {
|
|
164
|
+
v.push({
|
|
165
|
+
code: 'A_LTV_NE_EPOCH',
|
|
166
|
+
detail: `localTimezoneValue=${p.localTimezoneValue && p.localTimezoneValue.getTime()} epoch=${p.unixEpoch}`,
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
// E. timezone is the intended one
|
|
171
|
+
if (intendedZone !== undefined && p.timezone !== intendedZone) {
|
|
172
|
+
v.push({ code: 'E_TZ_MISMATCH', detail: `payload tz=${p.timezone} intended=${intendedZone}` });
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
if (p.value === null) {
|
|
176
|
+
v.push({ code: 'EPOCH_WITHOUT_VALUE', detail: `epoch=${p.unixEpoch}` });
|
|
177
|
+
return v;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
const parsed = parseBracketed(p.value);
|
|
181
|
+
if (!parsed) {
|
|
182
|
+
v.push({ code: 'VALUE_UNPARSABLE', detail: `value=${p.value}` });
|
|
183
|
+
return v;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
// D. printed offset == zone's ACTUAL offset at the epoch
|
|
187
|
+
let trueOff: number | null = null;
|
|
188
|
+
try { trueOff = offsetAt(p.unixEpoch, p.timezone); } catch { /* unresolvable */ }
|
|
189
|
+
if (trueOff !== null && parsed.offsetMs !== trueOff) {
|
|
190
|
+
v.push({
|
|
191
|
+
code: 'D_OFFSET_WRONG',
|
|
192
|
+
detail: `printed=${parsed.offsetMs / 60000}min true=${trueOff / 60000}min at epoch=${p.unixEpoch} tz=${p.timezone}`,
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
// C. printed digits == the zone's reading of the epoch
|
|
197
|
+
if (trueOff !== null) {
|
|
198
|
+
const expected = wallAt(p.unixEpoch, p.timezone);
|
|
199
|
+
if (!wallEquals(parsed.wall, expected)) {
|
|
200
|
+
v.push({
|
|
201
|
+
code: 'C_DIGITS_WRONG',
|
|
202
|
+
detail: `printed=${fmtWall(parsed.wall)} expected=${fmtWall(expected)} tz=${p.timezone} epoch=${p.unixEpoch}`,
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
// B. the value, resolved independently, is the same instant as unixEpoch
|
|
208
|
+
// (digits - printed offset must equal the epoch)
|
|
209
|
+
const fromValue = utcFromFields(
|
|
210
|
+
parsed.wall.year, parsed.wall.month - 1, parsed.wall.day,
|
|
211
|
+
parsed.wall.hours, parsed.wall.minutes, parsed.wall.seconds, parsed.wall.ms
|
|
212
|
+
) - parsed.offsetMs;
|
|
213
|
+
if (fromValue !== p.unixEpoch) {
|
|
214
|
+
v.push({
|
|
215
|
+
code: 'B_VALUE_NE_EPOCH',
|
|
216
|
+
detail: `value resolves to ${fromValue} but unixEpoch=${p.unixEpoch} (delta ${fromValue - p.unixEpoch}ms) value=${p.value}`,
|
|
217
|
+
});
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
return v;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
/** F. emit -> reload -> Apply preserves the epoch exactly. */
|
|
224
|
+
export async function roundTrip(p: Payload): Promise<{ second: Payload | null; violations: Violation[] }> {
|
|
225
|
+
const el2 = await makePicker({ value: p.value, timezone: p.timezone });
|
|
226
|
+
const second = await apply(el2);
|
|
227
|
+
const violations = checkPayload(second, undefined);
|
|
228
|
+
if (second && second.unixEpoch !== p.unixEpoch) {
|
|
229
|
+
violations.push({
|
|
230
|
+
code: 'F_EPOCH_DRIFT',
|
|
231
|
+
detail: `first=${p.unixEpoch} second=${second.unixEpoch} delta=${(second.unixEpoch ?? 0) - (p.unixEpoch ?? 0)}ms value=${p.value}`,
|
|
232
|
+
});
|
|
233
|
+
}
|
|
234
|
+
return { second, violations };
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
/* ==========================================================================
|
|
238
|
+
Shared by more than one nile-date-time-picker.phases-*.test.ts file
|
|
239
|
+
(moved verbatim from the Section K PART 1 / PART 2 / PART 6 helpers;
|
|
240
|
+
only `export` was added where a helper had not been exported before)
|
|
241
|
+
========================================================================== */
|
|
242
|
+
|
|
243
|
+
/* ── C. wall clock + zone -> candidate instant(s) ─────────────────────────── */
|
|
244
|
+
|
|
245
|
+
/** Wall clock as a "UTC-pretending" epoch — the anchor both sides agree on. */
|
|
246
|
+
export function wallToUTCms(w: Wall): number {
|
|
247
|
+
return utcFromFields(w.year, w.month - 1, w.day, w.hours, w.minutes, w.seconds, w.ms);
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
/**
|
|
251
|
+
* EVERY instant the zone displays as exactly `w`.
|
|
252
|
+
* [] -> the wall clock does not exist (spring-forward gap)
|
|
253
|
+
* [t] -> unambiguous
|
|
254
|
+
* [t1, t2] -> ambiguous (fall-back overlap), ascending
|
|
255
|
+
*
|
|
256
|
+
* Method: the true offset is within ±26h of any guess, so probing the offsets
|
|
257
|
+
* reported at guess-26h .. guess+26h yields every candidate; each is then
|
|
258
|
+
* CONFIRMED by reading it back. No reliance on a correction-pass converging.
|
|
259
|
+
*/
|
|
260
|
+
export function instantsFor(w: Wall, zone: string): number[] {
|
|
261
|
+
const guess = wallToUTCms(w);
|
|
262
|
+
const probes = new Set<number>();
|
|
263
|
+
for (let h = -26; h <= 26; h++) probes.add(offsetAt(guess + h * 3600000, zone));
|
|
264
|
+
const out: number[] = [];
|
|
265
|
+
for (const off of probes) {
|
|
266
|
+
const cand = guess - off;
|
|
267
|
+
if (out.indexOf(cand) !== -1) continue;
|
|
268
|
+
if (wallEquals(wallAt(cand, zone), w)) out.push(cand);
|
|
269
|
+
}
|
|
270
|
+
return out.sort((a, b) => a - b);
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
/* ── DST transition discovery (PHASE 4) ──────────────────────────────────── */
|
|
274
|
+
|
|
275
|
+
/** Every offset change in [from, to), found by coarse scan + binary search. */
|
|
276
|
+
export function findTransitions(zone: string, from: number, to: number): number[] {
|
|
277
|
+
const STEP = 6 * 3600000;
|
|
278
|
+
const hits: number[] = [];
|
|
279
|
+
let prev = offsetAt(from, zone);
|
|
280
|
+
for (let t = from + STEP; t < to; t += STEP) {
|
|
281
|
+
const cur = offsetAt(t, zone);
|
|
282
|
+
if (cur !== prev) {
|
|
283
|
+
let lo = t - STEP, hi = t;
|
|
284
|
+
// 1ms precision: at 1s precision offsetAt(t-1) can already read the NEW
|
|
285
|
+
// offset, which silently classifies a forward transition as delta=0.
|
|
286
|
+
while (hi - lo > 1) {
|
|
287
|
+
const mid = lo + Math.floor((hi - lo) / 2);
|
|
288
|
+
if (offsetAt(mid, zone) === prev) lo = mid; else hi = mid;
|
|
289
|
+
}
|
|
290
|
+
hits.push(hi);
|
|
291
|
+
prev = cur;
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
return hits;
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
/** Zones the runtime itself offers — the same source the component's list uses. */
|
|
298
|
+
export function runtimeZones(): string[] {
|
|
299
|
+
const anyIntl = Intl as any;
|
|
300
|
+
return typeof anyIntl.supportedValuesOf === 'function'
|
|
301
|
+
? (anyIntl.supportedValuesOf('timeZone') as string[])
|
|
302
|
+
: [];
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
/** Inverse of wallToUTCms — read a "UTC-pretending" epoch back as wall digits. */
|
|
306
|
+
export function wallFromUTCms(ms: number): Wall {
|
|
307
|
+
const d = new Date(ms);
|
|
308
|
+
return {
|
|
309
|
+
year: d.getUTCFullYear(), month: d.getUTCMonth() + 1, day: d.getUTCDate(),
|
|
310
|
+
hours: d.getUTCHours(), minutes: d.getUTCMinutes(),
|
|
311
|
+
seconds: d.getUTCSeconds(), ms: d.getUTCMilliseconds(),
|
|
312
|
+
};
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
/** Classify a transition and give a wall clock strictly inside the gap/overlap. */
|
|
316
|
+
export function transitionShape(t: number, zone: string): {
|
|
317
|
+
kind: 'forward' | 'backward'; deltaMs: number; insideWall: Wall;
|
|
318
|
+
offBefore: number; offAfter: number;
|
|
319
|
+
} {
|
|
320
|
+
const offBefore = offsetAt(t - 1, zone);
|
|
321
|
+
const offAfter = offsetAt(t, zone);
|
|
322
|
+
const deltaMs = offAfter - offBefore;
|
|
323
|
+
// wall clocks in [t+offBefore, t+offAfter) are skipped (forward) or repeated
|
|
324
|
+
// (backward, with the interval reversed). Take the midpoint either way.
|
|
325
|
+
const lo = Math.min(t + offBefore, t + offAfter);
|
|
326
|
+
const hi = Math.max(t + offBefore, t + offAfter);
|
|
327
|
+
return {
|
|
328
|
+
kind: deltaMs > 0 ? 'forward' : 'backward',
|
|
329
|
+
deltaMs,
|
|
330
|
+
insideWall: wallFromUTCms(lo + Math.floor((hi - lo) / 2)),
|
|
331
|
+
offBefore, offAfter,
|
|
332
|
+
};
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
/** Seed a wall clock directly into the panel, then Apply. */
|
|
336
|
+
export async function selectAndApply(
|
|
337
|
+
el: any, w: Wall, zone: string
|
|
338
|
+
): Promise<Payload | null> {
|
|
339
|
+
const cal = await settle(el);
|
|
340
|
+
cal.timezone = zone;
|
|
341
|
+
await settle(el);
|
|
342
|
+
// the day is read field-wise from `value`; noon anchor keeps the DAY stable
|
|
343
|
+
cal.value = localDateFromFields(w.year, w.month - 1, w.day, 12, 0, 0, 0);
|
|
344
|
+
cal.currentMonth = w.month - 1;
|
|
345
|
+
cal.currentYear = w.year;
|
|
346
|
+
cal.tpHours = w.hours;
|
|
347
|
+
cal.tpMinutes = w.minutes;
|
|
348
|
+
cal.tpSeconds = w.seconds;
|
|
349
|
+
cal.tpMilliseconds = w.ms;
|
|
350
|
+
await settle(el);
|
|
351
|
+
return apply(el);
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
export const HOST_TZ = Intl.DateTimeFormat().resolvedOptions().timeZone;
|
|
355
|
+
|
|
356
|
+
/** Collects failures so a sweep reports ALL of them, not just the first. */
|
|
357
|
+
export class Failures {
|
|
358
|
+
rows: string[] = [];
|
|
359
|
+
add(ctx: string, vs: Violation[]) {
|
|
360
|
+
for (const x of vs) this.rows.push(`[${x.code}] ${ctx} :: ${x.detail}`);
|
|
361
|
+
}
|
|
362
|
+
get count() { return this.rows.length; }
|
|
363
|
+
report(limit = 25): string {
|
|
364
|
+
if (!this.rows.length) return '';
|
|
365
|
+
const head = this.rows.slice(0, limit).join('\n ');
|
|
366
|
+
return `\n ${head}${this.rows.length > limit ? `\n ...and ${this.rows.length - limit} more` : ''}`;
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
export const YEAR_FROM = Date.UTC(2026, 0, 1);
|
|
371
|
+
export const YEAR_TO = Date.UTC(2027, 0, 1);
|
|
372
|
+
|
|
373
|
+
export type Tr = { zone: string; t: number };
|
|
374
|
+
|
|
375
|
+
export function allTransitions(zones: string[]): Tr[] {
|
|
376
|
+
const out: Tr[] = [];
|
|
377
|
+
for (const z of zones) {
|
|
378
|
+
for (const t of findTransitions(z, YEAR_FROM, YEAR_TO)) out.push({ zone: z, t });
|
|
379
|
+
}
|
|
380
|
+
return out;
|
|
381
|
+
}
|