parseDateInput (tasks/parse-date.ts)

kaneo · packages/cli/src/tasks/parse-date.ts · typescript · MIT
ui, tag:knn-classified

Parses date strings into ISO strings or null, supporting relative and absolute formats.

// Source: https://github.com/usekaneo/kaneo | License: MIT | Copyright 2024 Andrej Acevski
// Provided via justclaw.it.com; keep this notice with the code.
import { Result } from "effect";
import { InvalidArgument } from "../errors/errors.js";

const ISO_DAY = /^(\d{4})-(\d{2})-(\d{2})$/u;
const RELATIVE_DAYS = /^\+(\d{1,4})d$/u;

function localNoon(year: number, monthIndex: number, day: number): Date {
  return new Date(year, monthIndex, day, 12, 0, 0, 0);
}

function invalid(
  input: string,
  flag: string,
  allowNone: boolean,
): InvalidArgument {
  return new InvalidArgument({
    message: `${flag} "${input}" is not a date.`,
    hint: allowNone
      ? "Use YYYY-MM-DD, today, tomorrow, +3d, or none to clear it."
      : "Use YYYY-MM-DD, today, tomorrow, or +3d.",
  });
}

function 

... (truncated -- full source via MCP)

See the full source, get the GitHub permalink, and search for more like it.

Get a free API key