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

The :now option doesn't seem to work very well #4

Open
gampleman opened this issue Oct 5, 2015 · 2 comments
Open

The :now option doesn't seem to work very well #4

gampleman opened this issue Oct 5, 2015 · 2 comments

Comments

@gampleman
Copy link
Contributor

I have an app that supports cancelling the next occurrence of an event, but for this we need to calculate the next occurrence of the event for an event in the future, i.e.:

Time.now 
# => 2015-10-05 18:13:15 +0100
Tickle.parse('monday', now: Time.now)
# => {:next=>2015-10-12 12:00:00 +0100, :expression=>"monday", :starting=>2015-10-05 18:13:18 +0100, :until=>nil}
Tickle.parse('monday', now: Time.now + 1.day)
# => {:next=>2015-10-12 12:00:00 +0100, :expression=>"monday", :starting=>2015-10-05 18:13:26 +0100, :until=>nil}
Tickle.parse('monday', now: Time.parse('2015-10-12 12:00:00 +0100'))
# => {:next=>2015-10-12 12:00:00 +0100, :expression=>"monday", :starting=>2015-10-05 18:13:53 +0100, :until=>nil}
Tickle.parse('monday', now: Time.parse('2015-10-13 12:00:00 +0100'))
# => {:next=>2015-10-12 12:00:00 +0100, :expression=>"monday", :starting=>2015-10-05 18:14:37 +0100, :until=>nil}
@yb66
Copy link
Owner

yb66 commented Oct 6, 2015

@gampleman

Yes, some of the options weren't being passed on properly before, the parsing code was a bit too complex so arguments were being silently ignored. In the develop branch there are new specs in the context "Given that now is in the future for this kind of thing that I hope work better. If the option isn't working for you when you use that branch, take a look at that block of specs and see if there's an example missing that would catch this, or if it's already been done. Then we can look at fixing the lib for you.

Regards,
iain

@gampleman
Copy link
Contributor Author

Based on the specs it seems to work in the develop branch if also passing the same date with the :start option. Which is fine, albeit somewhat unintuitive.

antogon pushed a commit to antogon/tickle that referenced this issue Oct 11, 2017
Prior to this change, Tickle would throw an error if the start
option passed in was in the past with respect to `Date.today`.
When attempting to enumerate intervals of dates that have already
occurred (in the case of looking backwards in a calendar), it is
important to be able to parse Tickle expressions and determine
what the next occurrence _was_ as opposed to when it _will be_.
While it appears that the parse API already supports a `:now` option,
it seems this option is ignored when checking this condition and,
instead, a `Date.today` is used.  This change simply uses the `:now`
as is passed to the `Tickled` object to validate `start_date`. Since
`Tickled#now` defaults to `Time.now`, this change is minimal but does
add value to the gem.

References: yb66#4
antogon pushed a commit to antogon/tickle that referenced this issue Oct 11, 2017
Prior to this change, Tickle would throw an error if the start
option passed in was in the past with respect to `Date.today`.
When attempting to enumerate intervals of dates that have already
occurred (in the case of looking backwards in a calendar), it is
important to be able to parse Tickle expressions and determine
what the next occurrence _was_ as opposed to when it _will be_.
While it appears that the parse API already supports a `:now` option,
it seems this option is ignored when checking this condition and,
instead, a `Date.today` is used.  This change simply uses the `:now`
as is passed to the `Tickled` object to validate `start_date`. Since
`Tickled#now` defaults to `Time.now`, this change is minimal but does
add value to the gem.

References: yb66#4
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

2 participants