nhb-toolbox
Version:
A versatile collection of smart, efficient, and reusable utility functions, classes and types for everyday development needs.
68 lines (67 loc) • 3.83 kB
TypeScript
import type { $Chronos, ISOTimeString, RangeWithDates, RelativeDateRange } from '../types';
declare module '../Chronos' {
interface Chronos {
/**
* @instance Returns an array of ISO date-time strings within a specific date range.
*
* - If the input is a fixed range (`from` and `to`), it includes all dates between them.
* - If the input is a relative range (`span` and `unit`), it starts from current date and goes forward.
* - If `skipDays` are provided, matching weekdays are excluded from the result.
*
* @param options - Configuration for the date range. Accepts a fixed (`RangeWithDates`) format.
* @returns Array of ISO date-time strings in either local or UTC format, excluding any skipped weekdays if specified.
*
* - Please refer to {@link https://toolbox.nazmul-nhb.dev/docs/classes/Chronos/calculation#getdatesinrange docs} for details.
*
* @remarks
* - When using `Chronos` instances for `from` and/or `to`, ensure both are created in the **same time zone** to avoid mismatched boundaries.
* - Mixing zones may shift the interpreted start or end by several hours, which can cause the range to include or exclude incorrect weekdays.
*
* @example
* // Using a fixed date range:
* new Chronos().getDatesInRange({ from: '2025-01-01', to: '2025-01-03' });
* // → ['2025-01-01T00:00:00+06:00', '2025-01-02T00:00:00+06:00', '2025-01-03T00:00:00+06:00']
*
* @example
* // Using a relative date range with skipDays:
* new Chronos().getDatesInRange({ span: 7, unit: 'day', skipDays: ['Saturday', 'Sunday'] });
* // → Array of 7 dates excluding weekends
*
* @example
* // UTC format:
* new Chronos().getDatesInRange({ span: 2, unit: 'day', format: 'utc' });
* // → ['2025-06-16T00:00:00.000Z', '2025-06-17T00:00:00.000Z']
*/
getDatesInRange(options?: RangeWithDates): ISOTimeString[];
/**
* @instance Returns an array of ISO date-time strings within a specific date range.
*
* - If the input is a fixed range (`from` and `to`), it includes all dates between them.
* - If the input is a relative range (`span` and `unit`), it starts from current date and goes forward.
* - If `skipDays` are provided, matching weekdays are excluded from the result.
*
* @param options - Configuration for the date range. Accepts a relative (`RelativeDateRange`) format.
* @returns Array of ISO date-time strings in either local or UTC format, excluding any skipped weekdays if specified.
*
* - Please refer to {@link https://toolbox.nazmul-nhb.dev/docs/classes/Chronos/calculation#getdatesinrange docs} for details.
*
* @example
* // Using a relative date range with skipDays:
* new Chronos().getDatesInRange({ span: 7, unit: 'day', skipDays: ['Saturday', 'Sunday'] });
* // → Array of 7 dates excluding weekends
*
* @example
* // UTC format:
* new Chronos().getDatesInRange({ span: 2, unit: 'day', format: 'utc' });
* // → ['2025-06-16T00:00:00.000Z', '2025-06-17T00:00:00.000Z']
*
* @example
* // Using a fixed date range:
* new Chronos().getDatesInRange({ from: '2025-01-01', to: '2025-01-03' });
* // → ['2025-01-01T00:00:00+06:00', '2025-01-02T00:00:00+06:00', '2025-01-03T00:00:00+06:00']
*/
getDatesInRange(options?: RelativeDateRange): ISOTimeString[];
}
}
/** * Plugin to inject `getDatesInRange` related method */
export declare const dateRangePlugin: ($Chronos: $Chronos) => void;