Skip to content

clampZoned

clampZoned(value: string, min: string, max: string): string
import { clampZoned } from "@northguild/gmt/zoned/calculate";

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.
Parameter Type Description
value string ISO ZonedDateTime string to clamp
min string ISO ZonedDateTime string for the lower bound (inclusive)
max string ISO ZonedDateTime string for the upper bound (inclusive)

The clamped zoned datetime string, or “” on invalid input

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]"
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]"
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]"
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]") // ""
clampZoned("invalid", "2024-03-01T00:00:00+00:00[UTC]", "2024-03-31T23:59:59+00:00[UTC]") // ""

zoned/calculate/clampZoned.ts