roundTime
Signature
Section titled “Signature”roundTime(value: string, options: { smallestUnit: Temporal.SmallestUnit<"hour">; roundingIncrement?: number; roundingMode?: Temporal.RoundingMode; }): stringimport { roundTime } from "@northguild/gmt/plain/calculate";Round an ISO 8601 time string to the specified time unit.
- Returns “” for invalid inputs.
- Only time units are accepted: “hour”, “minute”, “second”, “millisecond”, “microsecond”, “nanosecond”.
- Wraps Temporal.PlainTime.round() which throws on invalid options.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
value |
string |
ISO 8601 time string |
Options
Section titled “Options”options
| Option | Type | Default |
|---|---|---|
smallestUnit |
Temporal.SmallestUnit<"hour"> |
— |
roundingIncrement? |
number |
— |
roundingMode? |
Temporal.RoundingMode |
— |
Returns
Section titled “Returns”Rounded ISO 8601 time string, or “” on invalid input
Examples
Section titled “Examples”roundTime("12:34:56", { smallestUnit: "hour" }) // "13:00:00"roundTime("12:34:56", { smallestUnit: "minute" }) // "12:35:00"roundTime("12:34:56", { smallestUnit: "second", roundingMode: "floor" }) // "12:34:56"roundTime("invalid", { smallestUnit: "hour" }) // ""