startOfTime
Signature
Section titled “Signature”startOfTime(value: string, unit: StartOfTimeUnit, optionsArg?: { fractionalSecondDigits?: FractionalDigit; }): stringReturn the start of the specified time unit for a given ISO 8601 time string.
- The start keeps every field larger than
unitand zeroes every smaller one, down to the nanosecond:"millisecond"keeps the milliseconds,"day"is midnight. unitaccepts the singular or plural name ("hour"or"hours"), as Temporal does.- Returns "" for invalid inputs.
- Compatibility: before 1.16.0 the sub-second units zeroed their own field (
"millisecond"on12:34:56.999gave12:34:56.000), and"day"/"hour"/"minute"kept the fraction.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
value | string | ISO 8601 time string |
unit | StartOfTimeUnit | StartOfTimeUnit to specify the unit for the start |
Options
Section titled “Options”optionsArg
How the result is written
| Option | Type | Default | Description |
|---|---|---|---|
fractionalSecondDigits? | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | "auto" | 8 | 9 (FractionalDigit) | The digits unit names: 3 for "millisecond", 6 for "microsecond", 9 for "nanosecond" and 0 for any coarser unit. | The number of fractional-second digits the result is written with, 0 to 9, or "auto" to drop trailing zeros. Fewer digits than unit names truncate, as Temporal’s toString does. |
Returns
Section titled “Returns”ISO 8601 string representing the start of the specified unit, or "" on invalid input
StartOfTimeUnit
Section titled “StartOfTimeUnit”Units startOfTime accepts: a Temporal time unit, or "day" for midnight, each singular or plural.
import type { StartOfTimeUnit } from "@northguild/gmt";"day" | TimeUnit | PluralUnit<"day" | TimeUnit>Related types
Section titled “Related types”Examples
Section titled “Examples”import { startOfTime } from "@northguild/gmt/plain/calculate";
startOfTime("12:34:56", "hour") // "12:00:00"