app/lib/editor/datetime-local.ts
18 lines and 3 functions in DrDustinEdwards/dustinedwards-info, at commit 1590ba4 on 2026-10-24. This file on GitHub.
Functions
| Function | Lines | Complexity | Covered | CRAP | Mutation |
|---|---|---|---|---|---|
| toLocalInput | 4 to 8 | 2 | No data: no coverage report in this map | No data: no coverage report in this map | No data: no mutants in this code |
| toIso | 11 to 15 | 3 | No data: no coverage report in this map | No data: no coverage report in this map | No data: no mutants in this code |
| anHourFromNowLocal | 18 to 21 | 1 | No data: no coverage report in this map | No data: no coverage report in this map | No data: no mutants in this code |
Imports
It imports no other module of this repo. Imported by app/components/admin/publish-actions.tsx, app/components/admin/settings-drawer.tsx.
Source
// A `datetime-local` input speaks `YYYY-MM-DDTHH:mm` in the reader's LOCAL time; the post stores UTC ISO.
/** An ISO instant as a `datetime-local` value, or "" when it does not parse. */
export function toLocalInput(iso: string) {
const at = Date.parse(iso);
if (Number.isNaN(at)) return "";
return new Date(at - new Date(at).getTimezoneOffset() * 60000).toISOString().slice(0, 16);
}
/** A `datetime-local` value as an ISO instant, or "" when it is empty or does not parse. */
export function toIso(local: string) {
if (!local) return "";
const at = Date.parse(local);
return Number.isNaN(at) ? "" : new Date(at).toISOString();
}
/** An hour from now, as a `datetime-local` value: the default a new schedule starts from. */
export function anHourFromNowLocal() {
const soon = new Date(Date.now() + 60 * 60 * 1000);
return new Date(soon.getTime() - soon.getTimezoneOffset() * 60000).toISOString().slice(0, 16);
}