@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.
40 lines • 2.66 kB
TypeScript
/**
* Return an array of ISO PlainDate strings between `startDate` and `endDate` inclusive.
*
* - Generates dates with optional step (default 1 day).
* - Returns [] if start > end, invalid inputs, or step <= 0.
* - 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 `endDate` 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 `intervalCountDate`
* counts. To read one set of bounds both ways, pass `addDate(endDate, { days: 1 })` to the
* `interval*` call, or `subtractDate(endDate, { days: 1 })` to this one.
*
* @param startDate ISO PlainDate string for the first date
* @param endDate ISO PlainDate string for the last date (inclusive)
* @param stepDays optional number of days to step between results
* @param options The limit on the size of the result
* @returns array of ISO PlainDate strings, or [] on invalid input
*
* @example mapDatesInRange("2024-03-01", "2024-03-05") // ["2024-03-01", "2024-03-02", "2024-03-03", "2024-03-04", "2024-03-05"]
* @example mapDatesInRange("2024-03-01", "2024-03-05", 2) // ["2024-03-01", "2024-03-03", "2024-03-05"]
* @example mapDatesInRange("+275760-09-11", "+275760-09-13") // ["+275760-09-11", "+275760-09-12", "+275760-09-13"] (a range ending on the last representable date)
* @example mapDatesInRange("2024-03-05", "2024-03-01") // []
* @example mapDatesInRange("invalid", "2024-03-05") // []
* @example mapDatesInRange("2024-03-01", "invalid") // []
* @example mapDatesInRange("2024-03-01", "2024-03-03", undefined) // ["2024-03-01", "2024-03-02", "2024-03-03"] (undefined is the default step)
* @example mapDatesInRange("2024-03-01", "2024-03-05", 0) // []
* @example mapDatesInRange("2024-03-01", "2024-03-05", 1, { maxPieces: 3 }) // [] (more dates than the limit)
* @example mapDatesInRange("2024-03-01", "2024-03-05", 1, { maxPieces: 10 }) // ["2024-03-01", "2024-03-02", "2024-03-03", "2024-03-04", "2024-03-05"]
*/
export declare function mapDatesInRange(startDate: string, endDate: 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[];