parseUnitFromUnix
Signature
Section titled “Signature”parseUnitFromUnix(value: string | number, unit: PlainNowUnit, options?: { epochUnit?: UnixUnit; timeZone?: string; weekStartsOn?: "monday" | "sunday"; }): stringimport { parseUnitFromUnix } from "@northguild/gmt/unix/parse";Extract a unit from a unix epoch value.
- Valid units: “year”, “month”, “week”, “day”, “dayOfWeek”, “hour”, “minute”, “second”, “millisecond”, “microsecond”, “nanosecond”.
- Converts to ZonedDateTime then extracts the unit.
- Returns “” for invalid input.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
value |
string | number |
unix epoch in milliseconds or seconds (number or string) |
unit |
PlainNowUnit |
unit to extract (e.g. “year”, “month”, “hour”) |
Options
Section titled “Options”options
| Option | Type | Default |
|---|---|---|
epochUnit? |
UnixUnit |
— |
timeZone? |
string |
— |
weekStartsOn? |
"monday" | "sunday" |
— |
Returns
Section titled “Returns”extracted unit value as string, or “” on invalid input
Related types
Section titled “Related types”Examples
Section titled “Examples”parseUnitFromUnix(1700000000000, "year") // "2023"parseUnitFromUnix(1700000000, "hour", { epochUnit: "seconds" }) // "12"parseUnitFromUnix(1704067200000, "week") // "1"parseUnitFromUnix(1704067200000, "week", { weekStartsOn: "sunday" }) // "1"parseUnitFromUnix(-86400, { epochUnit: "seconds" }, "year") // "1969"