@burglekitt/gmt
Version:
Temporal-based date and time utilities with timezone support and polyfill integration
21 lines (20 loc) • 1.39 kB
TypeScript
/**
* Restrict `value` to the range [`min`, `max`] in zoned datetime space.
*
* - Returns `value` if it falls within the bounds (inclusive on both ends).
* - Returns `min` if `value` is before `min`.
* - Returns `max` if `value` is after `max`.
* - Returns `""` if any input is invalid or `min > max`.
*
* @param value ISO ZonedDateTime string to clamp
* @param min ISO ZonedDateTime string for the lower bound (inclusive)
* @param max ISO ZonedDateTime string for the upper bound (inclusive)
* @returns The clamped zoned datetime string, or "" on invalid input
*
* @example clampZoned("2024-03-15T12:00:00+00:00[UTC]", "2024-03-01T00:00:00+00:00[UTC]", "2024-03-31T23:59:59+00:00[UTC]") // "2024-03-15T12:00:00+00:00[UTC]"
* @example clampZoned("2024-02-01T12:00:00+00:00[UTC]", "2024-03-01T00:00:00+00:00[UTC]", "2024-03-31T23:59:59+00:00[UTC]") // "2024-03-01T00:00:00+00:00[UTC]"
* @example clampZoned("2024-05-01T12:00:00+00:00[UTC]", "2024-03-01T00:00:00+00:00[UTC]", "2024-03-31T23:59:59+00:00[UTC]") // "2024-03-31T23:59:59+00:00[UTC]"
* @example clampZoned("2024-03-15T12:00:00+00:00[UTC]", "2024-03-31T00:00:00+00:00[UTC]", "2024-03-01T00:00:00+00:00[UTC]") // ""
* @example clampZoned("invalid", "2024-03-01T00:00:00+00:00[UTC]", "2024-03-31T23:59:59+00:00[UTC]") // ""
*/
export declare function clampZoned(value: string, min: string, max: string): string;