Skip to content

Getting Started

DTRExp: Date-Time Range & Recurrence Expression — a compact string expression for describing “when”, evaluated by coverage. The name reads as “DTR Expression”; dtrexp is its package spelling.

An expression like T0900:1800 E1:5 (Mon–Fri, 09:00–18:00) means the same thing in every language, and so does the code around it; parsing, coverage checks and warnings share one vocabulary across all implementations. Learn one library and you know them all.

Pick your language. Every implementation is zero-dependency and passes the same conformance vectors.

Terminal window
npm i dtrexp

Requires Node.js ≥ 22. This is the reference implementation, in TypeScript.

import { parse } from 'dtrexp';
const dtr = parse('T0900:1800 E1:5');
// coverage — built for per-request hot paths
dtr.covers(new Date(), { tz: 'Europe/Berlin' });
// —> true (weekday, 09:00–18:00 Berlin local time)
// enumeration on demand — a finite window is always a finite list
dtr.intersect('2026-07-06T00:00:00Z', '2026-07-13T00:00:00Z');
// —> 5 intervals, one per business day
// "when does it next apply?"
dtr.next('2026-07-11T10:00:00Z');
// —> { start: 2026-07-13T09:00:00Z, end: 2026-07-13T18:00:00Z }
parse('E7#-1 M4').describe();
// —> 'the last Sunday in April'
parse('D25 M12').toRRule();
// —> 'RRULE:FREQ=YEARLY;BYMONTH=12;BYMONTHDAY=25'

Note: the timezone is an evaluation parameter, never part of the expression. T0900:1800 means local business hours wherever you evaluate it; omit the zone and evaluation is in UTC.

Components are space-separated and intersect (D13 E5 = day 13 and a Friday); | unions alternatives. Each component is a designator letter plus values: Y year, Q quarter, M month, W ISO week, D day, E ISO weekday, T a clock range, H/m/s hour/minute/second patterns. Values take ranges (E1:5), lists (M3,6,9), negation (M!7), ordinals (E7#-1) and strides (Y*/2); a date literal anchors absolute bounds or a cadence (20200106/10D). The full grammar fits in one page of the spec.

  • Why DTRExp — what it can express that cron, RRULE and ISO 8601 can’t; and where they win.
  • The Spec — the model, the grammar and the evaluation semantics. Draft 2.8.
  • Implementations — all packages, registries and platform notes in one place.