@lmzhen/dsh-evolution-client-kit 0.37.0 → 0.37.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/lib/index.js +39 -9
- package/lib/types/format.d.ts +14 -0
- package/lib/types/format.js +41 -11
- package/lib/types/index.d.ts +1 -1
- package/lib/types/index.js +1 -1
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -438,6 +438,20 @@ var AsyncResource = class {
|
|
|
438
438
|
};
|
|
439
439
|
//#endregion
|
|
440
440
|
//#region lib/types/format.js
|
|
441
|
+
/** Parse an ISO string, epoch ms, or null into a valid Date; null when absent/invalid. */
|
|
442
|
+
function toLocalDate(value) {
|
|
443
|
+
if (value === null || value === void 0) return null;
|
|
444
|
+
const ms = typeof value === "number" ? value : Date.parse(value);
|
|
445
|
+
if (!Number.isFinite(ms)) return null;
|
|
446
|
+
const date = new Date(ms);
|
|
447
|
+
return Number.isNaN(date.getTime()) ? null : date;
|
|
448
|
+
}
|
|
449
|
+
const pad = (part) => String(part).padStart(2, "0");
|
|
450
|
+
/** The local clock part, HH:MM[:SS]. */
|
|
451
|
+
function clockOf(date, options) {
|
|
452
|
+
const head = pad(date.getHours()) + ":" + pad(date.getMinutes());
|
|
453
|
+
return options.seconds === false ? head : head + ":" + pad(date.getSeconds());
|
|
454
|
+
}
|
|
441
455
|
/**
|
|
442
456
|
* Format an ISO string, epoch milliseconds, or null as local wall time.
|
|
443
457
|
* Invalid values return null; callers decide how to say "unknown".
|
|
@@ -446,14 +460,30 @@ var AsyncResource = class {
|
|
|
446
460
|
* @returns the formatted local time, or null when the value is absent/invalid.
|
|
447
461
|
*/
|
|
448
462
|
function formatLocalDateTime(value, options = {}) {
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
463
|
+
const date = toLocalDate(value);
|
|
464
|
+
if (date === null) return null;
|
|
465
|
+
return String(date.getFullYear()) + "-" + pad(date.getMonth() + 1) + "-" + pad(date.getDate()) + " " + clockOf(date, options);
|
|
466
|
+
}
|
|
467
|
+
/**
|
|
468
|
+
* Format only the local clock part, HH:MM[:SS]; null when the value is absent/invalid.
|
|
469
|
+
* @param value - ISO string, epoch ms, or null.
|
|
470
|
+
* @param options - seconds on/off; defaults to on.
|
|
471
|
+
* @returns the local clock text, or null.
|
|
472
|
+
*/
|
|
473
|
+
function formatLocalClock(value, options = {}) {
|
|
474
|
+
const date = toLocalDate(value);
|
|
475
|
+
return date === null ? null : clockOf(date, options);
|
|
476
|
+
}
|
|
477
|
+
/**
|
|
478
|
+
* True when the value falls on the same local calendar day as now.
|
|
479
|
+
* @param value - ISO string, epoch ms, or null.
|
|
480
|
+
* @param now - the reference instant; defaults to the current time.
|
|
481
|
+
* @returns whether both are the same local day; false for invalid input.
|
|
482
|
+
*/
|
|
483
|
+
function isSameLocalDay(value, now = /* @__PURE__ */ new Date()) {
|
|
484
|
+
const date = toLocalDate(value);
|
|
485
|
+
if (date === null) return false;
|
|
486
|
+
return date.getFullYear() === now.getFullYear() && date.getMonth() === now.getMonth() && date.getDate() === now.getDate();
|
|
457
487
|
}
|
|
458
488
|
//#endregion
|
|
459
489
|
//#region lib/types/notice.js
|
|
@@ -801,4 +831,4 @@ function createSettingsGatewayCache(binder, api) {
|
|
|
801
831
|
};
|
|
802
832
|
}
|
|
803
833
|
//#endregion
|
|
804
|
-
export { ActionMenu, AsyncResource, Block, CommandCopyButton, DecisionFrame, DisclosureGroup, EmptyState, FALLBACKS, FailureBlock, FilterChip, PAGE_SURFACE_CLASS, PAGE_SURFACE_CSS, PLATFORM_MENU, ROUTES, StateNotice, StatusChip, TOKENS, TOKEN_CSS, TaskBanner, TimeText, copyAction, createSettingsGatewayCache, createSettingsSeat, failureText, formatLocalDateTime, loadStateOf, menuPrimitivesFrom, panelWorkspaceId, registerSidebarPanel, registerWorkbenchView, renderPlatformMenu, saveSettings, tokenVars };
|
|
834
|
+
export { ActionMenu, AsyncResource, Block, CommandCopyButton, DecisionFrame, DisclosureGroup, EmptyState, FALLBACKS, FailureBlock, FilterChip, PAGE_SURFACE_CLASS, PAGE_SURFACE_CSS, PLATFORM_MENU, ROUTES, StateNotice, StatusChip, TOKENS, TOKEN_CSS, TaskBanner, TimeText, copyAction, createSettingsGatewayCache, createSettingsSeat, failureText, formatLocalClock, formatLocalDateTime, isSameLocalDay, loadStateOf, menuPrimitivesFrom, panelWorkspaceId, registerSidebarPanel, registerWorkbenchView, renderPlatformMenu, saveSettings, tokenVars };
|
package/lib/types/format.d.ts
CHANGED
|
@@ -11,4 +11,18 @@ export interface LocalDateTimeOptions {
|
|
|
11
11
|
* @returns the formatted local time, or null when the value is absent/invalid.
|
|
12
12
|
*/
|
|
13
13
|
export declare function formatLocalDateTime(value: string | number | null | undefined, options?: LocalDateTimeOptions): string | null;
|
|
14
|
+
/**
|
|
15
|
+
* Format only the local clock part, HH:MM[:SS]; null when the value is absent/invalid.
|
|
16
|
+
* @param value - ISO string, epoch ms, or null.
|
|
17
|
+
* @param options - seconds on/off; defaults to on.
|
|
18
|
+
* @returns the local clock text, or null.
|
|
19
|
+
*/
|
|
20
|
+
export declare function formatLocalClock(value: string | number | null | undefined, options?: LocalDateTimeOptions): string | null;
|
|
21
|
+
/**
|
|
22
|
+
* True when the value falls on the same local calendar day as now.
|
|
23
|
+
* @param value - ISO string, epoch ms, or null.
|
|
24
|
+
* @param now - the reference instant; defaults to the current time.
|
|
25
|
+
* @returns whether both are the same local day; false for invalid input.
|
|
26
|
+
*/
|
|
27
|
+
export declare function isSameLocalDay(value: string | number | null | undefined, now?: Date): boolean;
|
|
14
28
|
//# sourceMappingURL=format.d.ts.map
|
package/lib/types/format.js
CHANGED
|
@@ -1,3 +1,19 @@
|
|
|
1
|
+
/** Parse an ISO string, epoch ms, or null into a valid Date; null when absent/invalid. */
|
|
2
|
+
function toLocalDate(value) {
|
|
3
|
+
if (value === null || value === undefined)
|
|
4
|
+
return null;
|
|
5
|
+
const ms = typeof value === 'number' ? value : Date.parse(value);
|
|
6
|
+
if (!Number.isFinite(ms))
|
|
7
|
+
return null;
|
|
8
|
+
const date = new Date(ms);
|
|
9
|
+
return Number.isNaN(date.getTime()) ? null : date;
|
|
10
|
+
}
|
|
11
|
+
const pad = (part) => String(part).padStart(2, '0');
|
|
12
|
+
/** The local clock part, HH:MM[:SS]. */
|
|
13
|
+
function clockOf(date, options) {
|
|
14
|
+
const head = pad(date.getHours()) + ':' + pad(date.getMinutes());
|
|
15
|
+
return options.seconds === false ? head : head + ':' + pad(date.getSeconds());
|
|
16
|
+
}
|
|
1
17
|
/**
|
|
2
18
|
* Format an ISO string, epoch milliseconds, or null as local wall time.
|
|
3
19
|
* Invalid values return null; callers decide how to say "unknown".
|
|
@@ -6,17 +22,31 @@
|
|
|
6
22
|
* @returns the formatted local time, or null when the value is absent/invalid.
|
|
7
23
|
*/
|
|
8
24
|
export function formatLocalDateTime(value, options = {}) {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
const ms = typeof value === 'number' ? value : Date.parse(value);
|
|
12
|
-
if (!Number.isFinite(ms))
|
|
25
|
+
const date = toLocalDate(value);
|
|
26
|
+
if (date === null)
|
|
13
27
|
return null;
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
28
|
+
return String(date.getFullYear()) + '-' + pad(date.getMonth() + 1) + '-' + pad(date.getDate()) + ' ' + clockOf(date, options);
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Format only the local clock part, HH:MM[:SS]; null when the value is absent/invalid.
|
|
32
|
+
* @param value - ISO string, epoch ms, or null.
|
|
33
|
+
* @param options - seconds on/off; defaults to on.
|
|
34
|
+
* @returns the local clock text, or null.
|
|
35
|
+
*/
|
|
36
|
+
export function formatLocalClock(value, options = {}) {
|
|
37
|
+
const date = toLocalDate(value);
|
|
38
|
+
return date === null ? null : clockOf(date, options);
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* True when the value falls on the same local calendar day as now.
|
|
42
|
+
* @param value - ISO string, epoch ms, or null.
|
|
43
|
+
* @param now - the reference instant; defaults to the current time.
|
|
44
|
+
* @returns whether both are the same local day; false for invalid input.
|
|
45
|
+
*/
|
|
46
|
+
export function isSameLocalDay(value, now = new Date()) {
|
|
47
|
+
const date = toLocalDate(value);
|
|
48
|
+
if (date === null)
|
|
49
|
+
return false;
|
|
50
|
+
return date.getFullYear() === now.getFullYear() && date.getMonth() === now.getMonth() && date.getDate() === now.getDate();
|
|
21
51
|
}
|
|
22
52
|
//# sourceMappingURL=format.js.map
|
package/lib/types/index.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ export { createSettingsSeat } from './settings-seat.ts';
|
|
|
6
6
|
export type { WorkbenchViewSpec } from './workbench-view.ts';
|
|
7
7
|
export { panelWorkspaceId } from './workspace.ts';
|
|
8
8
|
export { AsyncResource } from './async-resource.ts';
|
|
9
|
-
export { formatLocalDateTime, type LocalDateTimeOptions } from './format.ts';
|
|
9
|
+
export { formatLocalClock, formatLocalDateTime, isSameLocalDay, type LocalDateTimeOptions } from './format.ts';
|
|
10
10
|
export { StateNotice, type StateNoticeProps, type StateNoticeTone } from './notice.ts';
|
|
11
11
|
export { DecisionFrame, type DecisionFrameProps } from './presentation/decision-frame.ts';
|
|
12
12
|
export { TaskBanner, type TaskBannerProps } from './presentation/task-banner.ts';
|
package/lib/types/index.js
CHANGED
|
@@ -3,7 +3,7 @@ export { registerWorkbenchView } from "./workbench-view.js";
|
|
|
3
3
|
export { createSettingsSeat } from "./settings-seat.js";
|
|
4
4
|
export { panelWorkspaceId } from "./workspace.js";
|
|
5
5
|
export { AsyncResource } from "./async-resource.js";
|
|
6
|
-
export { formatLocalDateTime } from "./format.js";
|
|
6
|
+
export { formatLocalClock, formatLocalDateTime, isSameLocalDay } from "./format.js";
|
|
7
7
|
export { StateNotice } from "./notice.js";
|
|
8
8
|
export { DecisionFrame } from "./presentation/decision-frame.js";
|
|
9
9
|
export { TaskBanner } from "./presentation/task-banner.js";
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lmzhen/dsh-evolution-client-kit",
|
|
3
3
|
"description": "Shared browser seams and lifecycle for the evolution family sidebar panels (community build)",
|
|
4
|
-
"version": "0.37.
|
|
4
|
+
"version": "0.37.1",
|
|
5
5
|
"private": false,
|
|
6
6
|
"publishConfig": {
|
|
7
7
|
"access": "public"
|