@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) • 672 B
JavaScript
import { plainDateTimeOf } from "../../internal/inputChecks.js";
// src/plain/chop/chopDate.ts
/**
* Return the PlainTime portion extracted from an ISO PlainDateTime string.
*
* - Extracts time components from a PlainDateTime.
* - Returns "" for invalid input.
*
* @param value ISO PlainDateTime string
* @returns ISO PlainTime string or "" on invalid input
*
* @example chopDate("2024-02-29T12:34:56") // "12:34:56"
* @example chopDate("invalid") // ""
*/
function chopDate(value) {
const valueParsed = plainDateTimeOf(value);
if (valueParsed === null) return "";
try {
return valueParsed.toPlainTime().toString();
} catch {
return "";
}
}
export { chopDate };