UNPKG

@storm-stack/date-time

Version:

This package includes a DateTime class, various utility functions for working with dates and times, and a number of formatting options.

16 lines (15 loc) 614 B
import { EMPTY_STRING } from "@storm-stack/types"; export const formatDateTimeISO = (dateTime, options) => { const smallestUnit = options?.smallestUnit || "millisecond"; const roundingMode = options?.roundingMode || "ceil"; const calendarName = options?.calendarName || "never"; const timeZoneName = options?.timeZoneName || "never"; const offset = options?.offset || "never"; return dateTime ? `${dateTime.instant.toZonedDateTimeISO(dateTime.timeZoneId ?? process.env.TZ ?? "UTC").toString({ smallestUnit, roundingMode, calendarName, timeZoneName, offset })}` : EMPTY_STRING; };