wanasit / chrono

A natural language date parser in Javascript
MIT License
4.6k stars 341 forks source link

"n weeks ago" returns a date in the future with forwardDate, unlike "n days ago" and "n months ago" #568

Closed malcolmredheron closed 2 months ago

malcolmredheron commented 2 months ago

Using v2.7.6, when I run:

import * as chrono from 'chrono-node';

var now = new Date();
console.log("Reference date", now)
console.log("2 days ago", chrono.parseDate('2 days ago', now, {}));
console.log("2 weeks ago", chrono.parseDate('2 weeks ago', now, {}));
console.log("2 months ago", chrono.parseDate('2 months ago', now, {}));
console.log("2 days ago, forwardDate", chrono.parseDate('2 days ago', now, { forwardDate: true }));
console.log("2 weeks ago, forwardDate", chrono.parseDate('2 weeks ago', now, { forwardDate: true }));
console.log("2 months ago, forwardDate", chrono.parseDate('2 months ago', now, { forwardDate: true }));

I get

Reference date 2024-09-10T21:24:37.968Z
2 days ago 2024-09-08T21:24:37.968Z
2 weeks ago 2024-08-27T21:24:37.968Z
2 months ago 2024-07-10T21:24:37.968Z
2 days ago, forwardDate 2024-09-08T21:24:37.968Z
2 weeks ago, forwardDate 2024-09-11T21:24:37.968Z
2 months ago, forwardDate 2024-07-10T21:24:37.968Z

Note that all of them are in the past except for "2 weeks ago, forwardDate", which is 1 day in the future

This is demonstrated in https://replit.com/@group44/HarshPalegreenFacts

wanasit commented 2 months ago

Thanks for reporting this.

The forwardDate can't work with "n ago" pattern, but I ensure the option doesn't affect the result.

This is fixed in 31bcae3.

malcolmredheron commented 2 months ago

Thank you!