refactor(webui): use Core date-time formatting
This commit is contained in:
@@ -18,6 +18,7 @@ import {
|
||||
DataGridEmptyAction,
|
||||
DataGridRowActions,
|
||||
DateTimeField,
|
||||
formatDateTime,
|
||||
ModuleSubnav,
|
||||
SelectionList,
|
||||
SelectionListItem,
|
||||
@@ -31,6 +32,7 @@ import {
|
||||
type AuthInfo,
|
||||
type CalendarPickerUiCapability,
|
||||
type DataGridColumn,
|
||||
type FormatDateTimeOptions,
|
||||
type ModuleSubnavGroup
|
||||
} from "@govoplan/core-webui";
|
||||
import {
|
||||
@@ -1064,8 +1066,8 @@ function CandidateSlotsGrid({
|
||||
</span>
|
||||
)
|
||||
},
|
||||
{ id: "start", header: I18N.start, minWidth: 160, resizable: true, value: (slot) => slot.start_at, render: (slot) => formatDateTime(slot.start_at) },
|
||||
{ id: "end", header: I18N.end, minWidth: 160, resizable: true, value: (slot) => slot.end_at, render: (slot) => formatDateTime(slot.end_at) },
|
||||
{ id: "start", header: I18N.start, minWidth: 160, resizable: true, value: (slot) => slot.start_at, render: (slot) => formatDateTime(slot.start_at, SHORT_DATE_TIME_OPTIONS) },
|
||||
{ id: "end", header: I18N.end, minWidth: 160, resizable: true, value: (slot) => slot.end_at, render: (slot) => formatDateTime(slot.end_at, SHORT_DATE_TIME_OPTIONS) },
|
||||
{
|
||||
id: "available",
|
||||
header: I18N.available,
|
||||
@@ -1235,17 +1237,24 @@ function isoFromLocal(value: string): string {
|
||||
return new Date(value).toISOString();
|
||||
}
|
||||
|
||||
function formatDateTime(value: string): string {
|
||||
return new Intl.DateTimeFormat(undefined, { dateStyle: "short", timeStyle: "short" }).format(new Date(value));
|
||||
}
|
||||
const SHORT_DATE_TIME_OPTIONS: FormatDateTimeOptions = {
|
||||
year: undefined,
|
||||
month: undefined,
|
||||
day: undefined,
|
||||
hour: undefined,
|
||||
minute: undefined,
|
||||
timeZoneName: undefined,
|
||||
dateStyle: "short",
|
||||
timeStyle: "short"
|
||||
};
|
||||
|
||||
function formatRange(start: string, end: string): string {
|
||||
return `${formatDateTime(start)} – ${formatDateTime(end)}`;
|
||||
return `${formatDateTime(start, SHORT_DATE_TIME_OPTIONS)} – ${formatDateTime(end, SHORT_DATE_TIME_OPTIONS)}`;
|
||||
}
|
||||
|
||||
function formatRelevantDate(request: SchedulingRequest): string {
|
||||
const timestamp = schedulingRelevantTimestamp(request);
|
||||
return Number.isFinite(timestamp) ? formatDateTime(new Date(timestamp).toISOString()) : "";
|
||||
return Number.isFinite(timestamp) ? formatDateTime(new Date(timestamp).toISOString(), SHORT_DATE_TIME_OPTIONS) : "";
|
||||
}
|
||||
|
||||
function errorMessage(error: unknown, fallback: string): string {
|
||||
|
||||
Reference in New Issue
Block a user