Skip to content

getZonedNowUnit

getZonedNowUnit(ianaTimezone: string, unit: ZonedNowUnit): string

Return the requested current unit value for the specified IANA timeZone.

  • Uses Temporal.Now.zonedDateTimeISO to get the current time.
  • week is the ISO 8601 week number, from parseWeekFromDate.
  • Validation is performed on timezone and unit.
  • unit accepts the singular or plural name of a Temporal unit ("hour" or "hours"), as Temporal does; "dayOfWeek" has no plural.
  • The "year" unit is written as Temporal writes a year: four digits ("2024", "0005"), or a sign and six digits outside 0000–9999 ("+010000", "-000005").
ParameterTypeDescription
ianaTimezonestringIANA name or UTC offset: a time zone identifier (+05:30, +0530, -08) or a stored offset (±HH:MM[:SS], what getTimeZoneOffset returns)
unitZonedNowUnitunit to extract from current zoned time

string representation of the requested unit or "" on invalid input

Units extractable from the current time in a specific IANA timeZone, as consumed by getZonedNowUnit.

import type { ZonedNowUnit } from "@northguild/gmt";
"dayOfWeek" | SmallestUnit<"year" | "month" | "week" | "day" | "hour" | "minute" | "second" | "millisecond" | "microsecond" | "nanosecond">
import { getZonedNowUnit } from "@northguild/gmt/zoned/get";
getZonedNowUnit("America/New_York", "hour") // "07"
output 

zoned/get/getZonedNowUnit.ts