ChronosChronos

Date Range Plugin

Date Range Plugin — Chronos Plugin Documentation.

About Date Range Plugin

Date range plugin is a plugin that adds date range related functionalities to Chronos.

Import & Usage

Import

To use the Date Range Plugin, import it first:

import { Chronos, chronos } from "chronos-date";
import { dateRangePlugin } from 'chronos-date/plugins/dateRangePlugin';

Register

Now you can use the plugin's methods:

// Register the plugin globally
Chronos.use(dateRangePlugin);
// or
chronos.use(dateRangePlugin);
// or
Chronos.register(dateRangePlugin);
// or
chronos.register(dateRangePlugin);

Usage

Example usage of the dateRangePlugin:

const c = new Chronos();

const datesInRange = c.getDatesInRange({
    from: '2025-01-01',
    to: '2025-01-31',
    skipDays: ['Saturday', 'Sunday'] // or [6, 0]
});

console.log(datesInRange);

Example Usage

playground.ts

Overview

The dateRangePlugin adds comprehensive date range functionalities to Chronos, enabling:

  • Generating an array of ISO date strings within a specified date range
  • Generating an array of Chronos instances if format is set to 'chronos'

Methods Added by the Plugin

Note

All these methods are provided by dateRangePlugin. You must register it using Chronos.use(dateRangePlugin) before calling them. Once registered, all Chronos instances will have access to these methods.

MethodDescriptionReturns
getDatesInRangeGenerate an array of ISO date strings or Chronos instances in the range.(string | Chronos)[]

API Reference

getDatesInRange()

Generate an array of ISO date strings within a specified date range.

Signatures

getDatesInRange<F extends ISODateFormat | 'chronos' = 'local'>(options?: RangeWithDates<F>): DateRangeResult<F>

Overview

Generates dates between two points in time with:

  • Fixed date ranges (from/to) or relative ranges (span/unit)
  • Weekday filtering (skipDays/onlyDays)
  • Format control (local/utc/chronos)
  • Date boundary rounding

Parameters

options (Optional)

Configuration object accepting either fixed or relative range parameters:

ParameterTypeDefaultDescription
fromChronosInputCurrent dateStart date (inclusive)
toChronosInput4 weeks from fromEnd date (inclusive)
spannumber4Number of time units
unit'year'|'month'|'week'|'day''week'Unit of time for relative ranges
format'local'|'utc'|'chronos''local'Output format for ISO strings or Chronos instances
skipDaysWeekDay[] | Enumerate<7>[][]Weekdays to exclude (e.g. ['Sunday', 'Saturday'] or [0, 6])
onlyDaysWeekDay[] | Enumerate<7>[][]Include these (e.g. ['Monday'] or [1], overrides skipDays)
roundDatebooleanfalseRound dates to start of day
interface RangeWithDates {
	/** Start date of the range (inclusive). Defaults to the current `Chronos` instance if not provided. */
	from?: ChronosInput;
	/** End date of the range (inclusive). Defaults to **4 weeks from the current `Chronos` instance** if not provided. */
	to?: ChronosInput;
  /** Output format. Default: 'local' */
  format?: 'local' | 'utc' | 'chronos';
  /**
    * An array of weekdays to exclude from the date range.
    * - Accepts either weekday names (e.g., `'Saturday'`, `'Sunday'`) or numeric indices (0 for Sunday to 6 for Saturday).
    * - Ignored if `onlyDays` is provided.
    */
  skipDays?: Array<WeekDay> | Array<Enumerate<7>>;
  /**
    * An array of weekdays to explicitly include in the date range.
    * - Accepts either weekday names (e.g., `'Monday'`, `'Wednesday'`) or numeric indices (0 for Sunday to 6 for Saturday).
    * - When provided, this overrides `skipDays` and includes only the specified days.
    */
  onlyDays?: Array<WeekDay> | Array<Enumerate<7>>;
  /** Round dates to start of day. Default: false */
  roundDate?: boolean;
}

Return Value

DateRangeResult<F> - Array of ISO date strings or Chronos instances based on the format option.

Tips

  • When format is chronos, the method returns an array of Chronos instances.
  • Thus you can call any method of Chronos on each element of the returned array.
  • Note: Each Chronos instance will be in the same time zone as the original instance.

Behavior

  • Fixed ranges: Includes all dates between from and to (inclusive)
  • Relative ranges: Generates dates forward from current date
  • onlyDays takes precedence over skipDays when both are provided
  • Defaults to 4-week range when no options provided

Note

  • 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.

Examples

import { dateRangePlugin } from 'chronos-date/plugins/dateRangePlugin';

Chronos.use(dateRangePlugin);

// Get all dates in January 2025
new Chronos().getDatesInRange({
  from: '2025-01-01',
  to: '2025-01-31',
  skipDays: ['Saturday', 'Sunday'] // or [6, 0]
});

// Include only Fridays in a full month range
const now = new Chronos();
now.getDatesInRange({
  from: now.startOf('month'),
  to: now.endOf('month'),
  onlyDays: ['Friday'],
  roundDate: true
});

// Include only Mondays and Wednesdays in the range
new Chronos().getDatesInRange({
  from: '2025-07-01',
  to: '2025-07-15',
  onlyDays: ['Monday', 'Wednesday']
});

Notes

Important

  • Weekday names must exactly match: 'Monday', 'Tuesday', etc. (case-sensitive)
  • When using onlyDays, all other days are excluded regardless of skipDays

Similar Static Method

Last updated: Sat, Jun 27, 2026 03:21:48PM (UTC)

On this page