@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) • 853 B
JavaScript
import { zonedDateTimeFrom } from "../../internal/zonedWallClock.js";
import { isValidZonedDateTime } from "../validate/isValidZonedDateTime.js";
// src/zoned/chop/chopZonedTimezone.ts
/**
* Returns the local plain datetime (date + time) extracted from a zoned datetime string.
*
* - Extracts both date and time components from a ZonedDateTime.
* - Returns "" for invalid input.
*
* @param value ISO 8601 zoned datetime string
* @returns Local plain datetime string or "" for invalid
*
* @example chopZonedTimezone("2024-02-29T14:30:45.123+05:30[Asia/Kolkata]") // "2024-02-29T14:30:45.123"
* @example chopZonedTimezone("invalid") // ""
*/
function chopZonedTimezone(value) {
if (!isValidZonedDateTime(value)) return "";
try {
return zonedDateTimeFrom(value).toPlainDateTime().toString();
} catch {
return "";
}
}
export { chopZonedTimezone };