clampDate
Signature
Section titled “Signature”clampDate(value: string, min: string, max: string): stringimport { clampDate } from "@northguild/gmt/plain/calculate";Restrict value to the range [min, max].
- Returns
valueif it falls within the bounds (inclusive on both ends). - Returns
minifvalueis beforemin. - Returns
maxifvalueis aftermax. - Returns
""if any input is invalid ormin > max.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
value |
string |
ISO PlainDate string to clamp |
min |
string |
ISO PlainDate string for the lower bound (inclusive) |
max |
string |
ISO PlainDate string for the upper bound (inclusive) |
Returns
Section titled “Returns”The clamped date string, or “” on invalid input
Examples
Section titled “Examples”clampDate("2024-03-15", "2024-03-01", "2024-03-31") // "2024-03-15"clampDate("2024-02-01", "2024-03-01", "2024-03-31") // "2024-03-01"clampDate("2024-05-01", "2024-03-01", "2024-03-31") // "2024-03-31"clampDate("2024-03-15", "2024-03-31", "2024-03-01") // ""clampDate("invalid", "2024-03-01", "2024-03-31") // ""