Skip to the content

Capsid menu

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

The functions of datetime-local.ts
FunctionLinesComplexityCoveredCRAPMutation
toLocalInput4 to 82No data: no coverage report in this mapNo data: no coverage report in this mapNo data: no mutants in this code
toIso11 to 153No data: no coverage report in this mapNo data: no coverage report in this mapNo data: no mutants in this code
anHourFromNowLocal18 to 211No data: no coverage report in this mapNo data: no coverage report in this mapNo 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);
}