@northguild/gmt
Version:
Date and time library for JavaScript and TypeScript, built on TC39 Temporal: time zones, DST, business days, ISO 8601 strings in and out. Never throws.
39 lines • 2.9 kB
TypeScript
/**
* Return an array of plain ISO date strings covering the inclusive date range between two zoned datetimes.
*
* - Both datetimes must have the same time zone: identifiers of one zone count as the same
* (`UTC` and `Etc/UTC` on every host; an IANA link such as `Europe/Kiev` and `Europe/Kyiv` where
* the host resolves it, which Safari 27 without `Temporal` does not).
* - Returns [] for invalid inputs, mismatched timezones, start > end, or invalid step.
* - A range holding more dates than `options.maxPieces` returns `[]` without generating any.
* - An explicit `undefined` `stepDays` is the default step, so `(start, end, undefined, options)`
* reaches `options`. **Compatibility:** before 1.16.0 it returned `[]`.
* - **End-inclusive, where the `interval*` functions are half-open.** This enumerates the dates a
* range covers, so the end date is one of them; an interval bounds a span as `[start, end)`, so
* its `end` is not. The same pair therefore yields one more date here than `intervalCountZoned`
* counts.
*
* @param startZonedDateTime start zoned ISO 8601 datetime string
* @param endZonedDateTime end zoned ISO 8601 datetime string
* @param stepDays optional positive integer step in days
* @param options optional limit on the size of the output
* @returns array of ISO date strings or [] when invalid
*
* @example mapZonedDatesInRange("+275760-09-12T00:00:00+00:00[UTC]", "+275760-09-13T00:00:00+00:00[UTC]") // ["+275760-09-12", "+275760-09-13"] (a range ending on the maximum instant)
* @example mapZonedDatesInRange("2024-02-28T12:00:00+00:00[UTC]", "2024-03-02T12:00:00+00:00[UTC]") // ["2024-02-28", "2024-02-29", "2024-03-01", "2024-03-02"]
* @example mapZonedDatesInRange("2024-02-28T12:00:00+00:00[UTC]", "2024-03-02T12:00:00+00:00[UTC]", 2) // ["2024-02-28", "2024-03-01"]
* @example mapZonedDatesInRange("2024-02-28T12:00:00+00:00[UTC]", "2024-03-01T12:00:00+00:00[UTC]", undefined) // ["2024-02-28", "2024-02-29", "2024-03-01"] (undefined is the default step)
* @example mapZonedDatesInRange("invalid", "2024-03-02T12:00:00+00:00[UTC]") // []
* @example mapZonedDatesInRange("2024-02-28T12:00:00+00:00[UTC]", "2024-03-02T12:00:00+00:00[UTC]", 1, { maxPieces: 3 }) // [] (more dates than the limit)
* @example mapZonedDatesInRange("2024-02-28T12:00:00+00:00[UTC]", "2024-03-02T12:00:00+00:00[UTC]", 1, { maxPieces: 10 }) // ["2024-02-28", "2024-02-29", "2024-03-01", "2024-03-02"]
*/
export declare function mapZonedDatesInRange(startZonedDateTime: string, endZonedDateTime: string, stepDays?: number, options?: {
/**
* The most dates the result may hold. A result that would hold more, or more than the longest
* possible array (2^32 - 1 elements), returns `[]` and none is built. A value that is not a
* positive safe integer also returns `[]`.
*
* @defaultValue `1_000_000`
*/
maxPieces?: number;
}): string[];