Skip to content

roundTime

roundTime(value: string, options: { smallestUnit: Temporal.SmallestUnit<"hour">; roundingIncrement?: number; roundingMode?: Temporal.RoundingMode; }): string
import { 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.
Parameter Type Description
value string ISO 8601 time string

options

Option Type Default
smallestUnit Temporal.SmallestUnit&lt;"hour"&gt;
roundingIncrement? number
roundingMode? Temporal.RoundingMode

Rounded ISO 8601 time string, or “” on invalid input

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" }) // ""

plain/calculate/roundTime.ts