chrono icon indicating copy to clipboard operation
chrono copied to clipboard

How do I make this interpret mon, tue, thu etc as the most recent day instead of the nearest day?

Open kamal2311 opened this issue 8 years ago • 3 comments

How do I make chrono-node interpret mon, tue, thu etc as the most recent day( in the past) instead of the nearest day which is sometimes in future?

kamal2311 avatar Oct 23 '17 19:10 kamal2311

As described in the README:

Chrono lets you define a reference date using chrono.parse(text, ref) and chrono.parseDate(text, ref).

For your case just use the current date a week ago as reference date:

var moment = require('moment');

chrono.parse('mon', moment().subtract(1, 'week'); 

amuelli avatar Nov 19 '17 18:11 amuelli

This 1 week back ref date solution would disturb the interpretation of terms like 'yesterday' ' 2 days ago' etc.

kamal2311 avatar Nov 21 '17 00:11 kamal2311

You are right it affects other parsers. There is also still the issue that e.g.tue by default will be interpreted as the closest Tuesday to the ref date, so that with the 1 week back ref solution it might even be 2 weeks back. I think you have to write your own refiner to accomplish exactly what you need, something like this: https://github.com/wanasit/chrono/issues/19#issuecomment-164419896

amuelli avatar Nov 21 '17 13:11 amuelli