clamp
Restricts a date to a specified range based on the underlying universal timestamp.
clamp()
Restricts a date to a specified range based on the underlying universal timestamp.
Signature
static clamp(value: ChronosInput, min: ChronosInput, max: ChronosInput): ChronosParameters
value: The date to clampmin: The lower bound of the allowed rangemax: The upper bound of the allowed range
Return Type
Chronos - Clamped moment (new instance)
Example
playground.ts
Notes
- All inputs are normalized to
Chronosinstances before comparison. - Comparison is always performed using each instance's UTC timestamp, ensuring a consistent and timezone-agnostic result.
- If
valuerepresents a moment earlier thanmin, the result will be equal tomin. - If
valuerepresents a moment later thanmax, the result will be equal tomax. - If
valuefalls within the range, it is returned as a newChronosinstance. - Internally equivalent to:
Chronos.min(Chronos.max(value, min), max). - The returned value is not one of the input values. A new immutable
Chronosinstance is always created. Its internal timezone, offset, name, and tracking information are cloned from the winning input instance.
See Also
Last updated: Tue, Jun 23, 2026 07:34:42PM (UTC)
