UNPKG

@northguild/gmt

Version:

Date and time library for JavaScript and TypeScript, built on TC39 Temporal: time zones, DST, business days, ISO 8601 strings in and out. Never throws.

26 lines (24 loc) • 842 B
import { zonedDateTimeFrom } from "../../internal/zonedWallClock.js"; import { isValidZonedDateTime } from "../validate/isValidZonedDateTime.js"; // src/zoned/chop/chopZonedSeconds.ts /** * Returns the zoned datetime string truncated to minute precision. * * - Removes seconds and milliseconds. * - Returns "" for invalid input. * * @param value ISO 8601 zoned datetime string * @returns Zoned datetime string at minute precision or "" for invalid * * @example chopZonedSeconds("2024-02-29T14:30:45.123+11:00[Australia/Sydney]") // "2024-02-29T14:30+11:00[Australia/Sydney]" * @example chopZonedSeconds("invalid") // "" */ function chopZonedSeconds(value) { if (!isValidZonedDateTime(value)) return ""; try { return zonedDateTimeFrom(value).toString({ smallestUnit: "minute" }); } catch { return ""; } } export { chopZonedSeconds };