startOfUtc
Signature
Section titled “Signature”startOfUtc(value: string, unit: any, options?: { weekStartsOn?: "monday" | "sunday"; fractionalSecondDigits?: FractionalDigit; }): stringimport { startOfUtc } from "@northguild/gmt/utc/calculate";Return the start of the specified date-time unit for a given UTC datetime string.
- Converts to ZonedDateTime, sets to start of unit, converts back to Instant.
- Supports: “year”, “month”, “week”, “day”, “hour”, “minute”, “second”, “millisecond”, “microsecond”, “nanosecond”.
- Returns “” for invalid input.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
value |
string |
ISO UTC datetime string |
unit |
any |
Temporal.DateUnit | Temporal.TimeUnit to specify the start |
Options
Section titled “Options”options
| Option | Type | Default |
|---|---|---|
weekStartsOn? |
"monday" | "sunday" |
— |
fractionalSecondDigits? |
FractionalDigit |
— |
Returns
Section titled “Returns”UTC Instant string representing the start of the unit, or “” on invalid input
Related types
Section titled “Related types”Examples
Section titled “Examples”startOfUtc("2024-03-15T14:30:45Z", "year") // "2024-01-01T00:00:00Z"startOfUtc("2024-03-15T14:30:45Z", "month") // "2024-03-01T00:00:00Z"startOfUtc("invalid", "year") // ""