#1215·compromise

Compromise-dates plugin: add option for inclusive duration ranges

Author: FdawgsCreated Aug 13, 2026Updated Aug 27, 2026

Duration ranges like 'in 2 to 4 weeks' and '2 to 4 weeks ago' resolve to a start/end pair via .dates(),:

javascript
nlp('in 1 to 5 months').dates({ today: '2026-01-01', timezone: 'UTC' }).get()
/*
[{
  start: '2026-02-01T00:00:00.000Z',
  end:   '2026-06-01T23:59:59.999Z',
  duration: { years: 0, months: 4, days: 1, hours: 0, minutes: 0 }
}]
*/

At present these are not inclusive, as shown.

It would be great if either the dates were inclusive (though this would be a breaking change), or alternatively an inclusive option, defaulting to false, could be passed to .dates():

javascript
nlp('in 1 to 5 months').dates({ today: '2026-01-01', timezone: 'UTC', inclusive: true }).get()
/*
[{
  start: '2026-02-01T00:00:00.000Z',
  end:   '2026-06-30T23:59:59.999Z',
  duration: { years: 0, months: 5, days: 0, hours: 0, minutes: 0 }
}]
*/

Examples of how inclusive: true would work

All with today: '2026-01-01', timezone: 'UTC'. Every start is T00:00:00.000Z and every end is T23:59:59.999Z, but I have trimmed them in below tables for readability sake.

Future, the end widens:

phrase start end duration
in 2 to 4 days now 2026-01-03 2026-01-05 {days: 3}
inclusive 2026-01-03 2026-01-05 {days: 3} (unchanged)
in 1 to 2 weeks now 2026-01-08 2026-01-15 {days: 8}
inclusive 2026-01-08 2026-01-21 {days: 14}
in 2 to 4 weeks now 2026-01-15 2026-01-29 {days: 15}
inclusive 2026-01-15 2026-02-04 {days: 21}
in 1 to 5 months now 2026-02-01 2026-06-01 {months: 4, days: 1}
inclusive 2026-02-01 2026-06-30 {months: 5}
in 2 to 4 years now 2028-01-01 2030-01-01 {years: 2, days: 1}
inclusive 2028-01-01 2030-12-31 {years: 3}

Past, the start widens, so the range doesn't leak into the current partial unit:

phrase start end duration
2 to 4 days ago now 2025-12-28 2025-12-30 {days: 3}
inclusive 2025-12-28 2025-12-30 {days: 3} (unchanged)
1 to 2 weeks ago now 2025-12-18 2025-12-25 {days: 8}
inclusive 2025-12-12 2025-12-25 {days: 14}
2 to 4 weeks ago now 2025-12-04 2025-12-18 {days: 15}
inclusive 2025-11-28 2025-12-18 {days: 21}
1 to 5 months ago now 2025-08-01 2025-12-01 {months: 4, days: 1}
inclusive 2025-07-02 2025-12-01 {months: 5}
2 to 4 years ago now 2022-01-01 2024-01-01 {years: 2, days: 1}
inclusive 2021-01-02 2024-01-01 {years: 3}

Durations were inclusive in #1137 but that functionality got lost somewhere along the way.

Happy to make a PR for this!

Source: spencermountain/compromise