chronic icon indicating copy to clipboard operation
chronic copied to clipboard

Parse `monday` returns next monday

Open xpepermint opened this issue 10 years ago • 6 comments

Today is monday (9. feb. 2015, ~12:20). When parsing monday parser returns next monday instead.

Chronic.parse('monday') 
#2015-02-16 12:00:00 +0100
Chronic.parse('this monday') 
#2015-02-16 12:00:00 +0100
Chronic.parse('monday at 16:30')
#2015-02-16 16:30:00 +0100

xpepermint avatar Feb 09 '15 11:02 xpepermint

that's kinda expected, because by default :context => :future, but current version is still bugged... currently you can use some hacks like subtracting day or using :context => :past for this case...

in next, yet unreleased version (my rewrite branch) it will be

Chronic.parse('monday', :context => nil)
# 2015-02-09 12:00:00 +0200
Chronic.parse('this monday', :context => nil)  # this is debatable if it should be today...
# 2015-02-16 12:00:00 +0200
Chronic.parse('monday at 16:30', :context => nil)
# 2015-02-09 16:30:30 +0200

davispuh avatar Feb 09 '15 14:02 davispuh

@davispuh Thanks for your answer. context: nil sound good. In my current project I need to execute an action e.g. every Monday. It would be great if context: nil will find the closest Monday - if today is Monday it will return today's Time if today is Tuesday it will return next week's Monday. What do you think?

xpepermint avatar Feb 09 '15 14:02 xpepermint

it's not really implemented so... context: nil would return Monday in that week so for Tuesday it would be like last Monday, for your case seems you need context: :future but just some flag so that current day is returned if it's Monday which is only exception

davispuh avatar Feb 09 '15 15:02 davispuh

Yes, a flag would do the trick.

xpepermint avatar Feb 09 '15 22:02 xpepermint

Just noting that I would be interested in this flag functionality as well!

aripatrick avatar Mar 04 '15 17:03 aripatrick

Any news on this? It has been over a year?

JPThorne avatar Dec 12 '16 15:12 JPThorne