Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parse monday returns next monday #295

Open
xpepermint opened this issue Feb 9, 2015 · 6 comments
Open

Parse monday returns next monday #295

xpepermint opened this issue Feb 9, 2015 · 6 comments

Comments

@xpepermint
Copy link

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
@davispuh
Copy link
Collaborator

davispuh commented Feb 9, 2015

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

@xpepermint
Copy link
Author

@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?

@davispuh
Copy link
Collaborator

davispuh commented Feb 9, 2015

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

@xpepermint
Copy link
Author

Yes, a flag would do the trick.

@aripatrick
Copy link

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

novikserg added a commit to novikserg/chronic that referenced this issue May 15, 2015
Refs mojombo#295
This one allows Chronic.parse method to receive
`today: true` param alongside a string to parse to allow
parsing ambiguous week days by name. E.g.:

Time.now   #=> Sun Aug 27 23:18:25 PDT 2006

Chronic.parse('sunday')

Chronic.parse('sunday', today: true)
novikserg added a commit to novikserg/chronic that referenced this issue May 15, 2015
Refs mojombo#295
This one allows Chronic.parse method to receive
`today: true` param alongside a string to parse to allow
parsing ambiguous week days by name. E.g.:

Time.now  			     #=> Sun Aug 27 23:18:25 PDT 2006
Chronic.parse('sunday') 	     #=> Sun Sep 03 12:00:00 PDT 2006
Chronic.parse('sunday', today: true) #=> Sun Aug 27 12:00:00 PDT 2006
@JPThorne
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants