mojombo / chronic

Chronic is a pure Ruby natural language date parser.
http://injekt.github.com/chronic
MIT License
3.24k stars 458 forks source link

Question about next day/current day #339

Open pikitgb opened 7 years ago

pikitgb commented 7 years ago

Amazing gem guys ! i really love it.

I have a question about this:

If today is Monday (Oct/3/2016) and i wanna get the next Monday there is anyway to get today has the first Monday available?

Current behavior: Chronic.parse("monday", now: DateTime.current) # it returns => Mon Oct/10/2016

How can it look like. (is this correct ?) Chronic.parse("monday", now: DateTime.current - 1.day) # it returns => Mon Oct/3/2016

Anyway to return by default current day ? is the day match with the first param criteria ?

Best regards.

davispuh commented 7 years ago

Chronic is actually missing such feature... There's a parameter context but currently it supports only :past and :future

I've been working on #278 which fixes a lot of issues and it does implement this feature but it's not really ready yet...

with my rewrite branch

date = DateTime.parse('2016-10-03')
Chronic.parse("monday", now: date, context: :past)
=> 2016-09-26 12:00:00 +0300
Chronic.parse("monday", now: date, context: :present)
=> 2016-10-03 12:00:00 +0300
Chronic.parse("monday", now: date, context: :future)
=> 2016-10-10 12:00:00 +0300