UNPKG

@burglekitt/gmt

Version:

Temporal-based date and time utilities with timezone support and polyfill integration

26 lines (25 loc) 1.67 kB
/** * Split a time interval into sub-intervals of `amount × unit`. * * - Returns an array of `{ start, end }` records that tile the interval. * - The final sub-interval is trimmed so its `end` never exceeds the original `end`. * - Returns `[{ start, end }]` when `start === end` (zero-length interval). * - Returns `[]` on invalid input (unparseable start/end, unsupported unit, non-positive amount, * or a unit that has no effect on `PlainTime`, e.g. `"days"`). * * @param start ISO PlainTime string for the interval start * @param end ISO PlainTime string for the interval end * @param unit duration unit string — `"hours" | "minutes" | "seconds" | "milliseconds" | "microseconds" | "nanoseconds"` (calendar units are ignored by PlainTime and return []) * @param amount positive number of units per step * @returns array of `{ start, end }` records, or [] on invalid input * * @example splitIntervalByUnitTime("12:00:00", "14:00:00", "hour", 1) // [{ start: "12:00:00", end: "13:00:00" }, { start: "13:00:00", end: "14:00:00" }] * @example splitIntervalByUnitTime("12:00:00", "14:30:00", "hour", 1) // [{ start: "12:00:00", end: "13:00:00" }, { start: "13:00:00", end: "14:00:00" }, { start: "14:00:00", end: "14:30:00" }] * @example splitIntervalByUnitTime("12:00:00", "12:00:00", "hour", 1) // [{ start: "12:00:00", end: "12:00:00" }] * @example splitIntervalByUnitTime("12:00:00", "14:00:00", "hour", 0) // [] * @example splitIntervalByUnitTime("invalid", "14:00:00", "hour", 1) // [] */ export declare function splitIntervalByUnitTime(start: string, end: string, unit: string, amount: number): Array<{ start: string; end: string; }>;