roundDate
Signature
Section titled “Signature”roundDate(value: string, options: { smallestUnit: DateUnit; roundingIncrement?: number; roundingMode?: Temporal.RoundingMode; }): stringimport { roundDate } from "@northguild/gmt/plain/calculate";Round an ISO 8601 date string to the specified date unit.
- Returns “” for invalid inputs.
- Accepts date units: “year”, “month”, “week”, “day”.
- Time units (“hour”, “minute”, etc.) are rejected and return “”.
- All date units 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 date string |
Options
Section titled “Options”options
| Option | Type | Default |
|---|---|---|
smallestUnit |
DateUnit |
— |
roundingIncrement? |
number |
— |
roundingMode? |
Temporal.RoundingMode |
— |
Returns
Section titled “Returns”Rounded ISO 8601 date string, or “” on invalid input
Related types
Section titled “Related types”Examples
Section titled “Examples”roundDate("2024-06-15", { smallestUnit: "year" }) // "2024-01-01"roundDate("2024-06-15", { smallestUnit: "month" }) // "2024-07-01"roundDate("2024-06-15", { smallestUnit: "week" }) // "2024-06-16"roundDate("2024-06-15", { smallestUnit: "day" }) // "2024-06-15"roundDate("invalid", { smallestUnit: "year" }) // ""