roundDateTime
Signature
Section titled “Signature”roundDateTime(value: string, options: { smallestUnit: DateTimeUnit; roundingIncrement?: number; roundingMode?: Temporal.RoundingMode; }): stringimport { roundDateTime } from "@northguild/gmt/plain/calculate";Round an ISO 8601 datetime string to the specified date-time unit.
- Returns “” for invalid inputs.
- Accepts all date and time units: “year”, “month”, “week”, “day”, “hour”, “minute”, “second”, “millisecond”, “microsecond”, “nanosecond”.
- Time units use Temporal.PlainDateTime.round() directly.
- Date units (year, month, week) use manual start-of-unit rounding.
- Wraps all Temporal calls in try-catch; returns “” on any error.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
value |
string |
ISO 8601 datetime string |
Options
Section titled “Options”options
| Option | Type | Default |
|---|---|---|
smallestUnit |
DateTimeUnit |
— |
roundingIncrement? |
number |
— |
roundingMode? |
Temporal.RoundingMode |
— |
Returns
Section titled “Returns”Rounded ISO 8601 datetime string, or “” on invalid input
Related types
Section titled “Related types”Examples
Section titled “Examples”roundDateTime("2024-06-15T12:34:56", { smallestUnit: "year" }) // "2024-01-01T00:00:00"roundDateTime("2024-06-15T12:34:56", { smallestUnit: "month" }) // "2024-07-01T00:00:00"roundDateTime("2024-06-15T12:34:56", { smallestUnit: "day" }) // "2024-06-16T00:00:00"roundDateTime("2024-06-15T12:34:56", { smallestUnit: "hour" }) // "2024-06-15T13:00:00"roundDateTime("invalid", { smallestUnit: "year" }) // ""