-
-
Notifications
You must be signed in to change notification settings - Fork 4
Open
Description
This is mostly just informative rather than a feature request at the moment, could be interesting to consider how to offer representing dateTime with the proposed Temporal.Instant instead of Date
.
I had started using a Temporal polyfill mainly for working with Durations, and found it useful to represent the dates as an Instant
.
So, I tried this quick-and-dirty mapping to substitute the ldkit handling for xsd.dateTime
:
import { registerDataHandler } from 'ldkit';
import { xsd } from 'ldkit/namespaces';
import { Temporal } from '@js-temporal/polyfill';
declare module 'ldkit' {
interface CustomDataTypes {
[xsd.dateTime]: Temporal.Instant;
}
}
registerDataHandler(
xsd.dateTime,
(literalValue: string) => {
const m = literalValue.match(/^"([^"]+)"\^\^/);
if (m) return Temporal.Instant.from(m[1]);
return Temporal.Instant.from(literalValue);
},
(value: Temporal.Instant) => {
return `"${value.toString()}"^^${xsd.dateTime}`;
}
);
I saw ldkit has some helpers internally for converting the value^^type
format, but they didn't seem to be available through the exported APIs. Do you have a suggestion for a better way to handle the string encoding & decoding?
Metadata
Metadata
Assignees
Labels
No labels