-
Notifications
You must be signed in to change notification settings - Fork 12
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
Recurrance that Skips Periods #26
Comments
Hi Eric, I must admit, I haven't looked at Tickle in a while, but I don't think you're missing something obvious. The underlying code is a bit of a spider's web and you've found one of its many faults. I have some free time coming up so I'll have a look to see what's what. I know I have some unfinished updates too, trying to make the code more straightforward, but as I remember it, it was difficult to fix. Sorry if that's not a very helpful reply. Regards, |
It's not a problem. Prior to seeing your response I decided to see if I can take a whack at implementing a similar library myself. Mostly just a learning exercise. I think I can create a simpler library by doing two things:
Basically the only goal of my library is to provide a grammar that Treetop can use to parse the schedule. Then essentially evaluate the resulting tree to get Montrose options. I'm using many of the examples in Montrose and your docs/tests to find phases I should support (as well as anything I can think of). Just spending a few hours and I already have a good bit parsing while still being maintainable. We'll see if it continues to be that way. Hopefully I'm not stepping on your toes or anything. This is really just a long-winded way of letting you know not to do anything on my account as I'm going a different direction. We'll see if it's successful or I'll be back. :) |
You're not stepping on my toes at all! I'm sure something simpler could be done, I think I was evaluating parsers like Treetop a while back but obviously didn't move forward, and didn't know at all about Montrose, thanks for introducing it to me. The thing I most wanted to do was to create some kind of enumerator that could move to each occurrence using I also asked Claude for some help with it (it's been a while since I'd looked at Tickle), how to share the chat is apparently beyond me but I've pasted the response below, just in case it's of any help. Me: Given the examples from the README, and from the specs, and from your own experience, provide a list of phrases for describing recurring events, like "every other Tuesday". Also, do you think such phrases can be parsed using a PEG? Claude:
START_EVERY_REGEX = /^
(?:
#{START}
)
\s+
(?<start>.*?)
(?:
\s+
#{REPETITION}
)?
\s+
#{SET_IDENTIFIER}
\s+
(?<event>.*)
/ix
Me: Show me how that PEG rule could be expressed using the Ruby Treetop library. Claude:
grammar RecurringEvent
rule recurring_event
bounded_event / simple_event
end
rule bounded_event
start_clause space frequency_clause space? end_clause? {
def to_hash
{
start: start_clause.value,
frequency: frequency_clause.value,
until: end_clause && end_clause.value
}
end
}
end
rule start_clause
('starting' / 'starts' / 'start') space date_expression {
def value
date_expression.value
end
}
end
rule end_clause
('until' / 'ending' / 'ends') space date_expression {
def value
date_expression.value
end
}
end
rule simple_event
frequency_clause {
def to_hash
{ frequency: frequency_clause.value }
end
}
end
rule frequency_clause
frequency space? time_unit (space 'of' space time_scope)? {
def value
{
frequency: frequency.value,
unit: time_unit.value,
scope: respond_to?(:time_scope) ? time_scope.value : nil
}
end
}
end
rule frequency
'every' / 'each' / numeric_frequency {
def value
text_value == 'every' || text_value == 'each' ? 1 : numeric_frequency.value
end
}
end
rule numeric_frequency
number space? 'other'? {
def value
number.value * (text_value.include?('other') ? 2 : 1)
end
}
end
rule time_unit
'day' / 'week' / 'month' / 'year' / weekday {
def value
text_value
end
}
end
rule weekday
'Monday' / 'Tuesday' / 'Wednesday' / 'Thursday' / 'Friday' / 'Saturday' / 'Sunday'
end
rule time_scope
'the month' / 'the year' / month_name
end
rule month_name
'January' / 'February' / 'March' / 'April' / 'May' / 'June' /
'July' / 'August' / 'September' / 'October' / 'November' / 'December'
end
rule date_expression
(!'until' !'ending' !frequency_clause .)+ {
def value
# In practice, you'd want to use Chronic here to parse the date expression
text_value.strip
end
}
end
rule number
[0-9]+ {
def value
text_value.to_i
end
}
end
rule space
[ \t]+
end
end
require 'treetop'
require 'chronic' # For actual date parsing
# Load the grammar
Treetop.load('recurring_event')
parser = RecurringEventParser.new
# Parse some expressions
result = parser.parse("every Monday")
if result
puts result.to_hash # => {frequency: {frequency: 1, unit: "Monday"}}
end
result = parser.parse("starting tomorrow every other week until December 1st")
if result
puts result.to_hash
# => {
# start: "tomorrow",
# frequency: {frequency: 2, unit: "week"},
# until: "December 1st"
# }
end
All in all, it sounds interesting. Let me know if you need anything. Regards, |
I don't understand how to do something like "every other monday". If I just put that in tickle I get an error:
This seems due to this call that only passes a single argument even though
chronic_parse
takes 3.But I'm assuming maybe I'm just not hitting a supported expression. Let's try "every other week starting monday":
K, that looks promising. But once we get to 12/31 how do we get the next date. If I just call it again I will get back 1/6 as it doesn't really have info about my orig start date. For all it knows this is the first time I'm asking and 1/6 is the first instance.
The obvious solution seems to pass
start
so it knows a reference from when to count from but that seems to do nothing. Same result with or without:Given a start date of the 3rd I would expect Jan 6th to be the next date from today that is every other monday but instead it returns Dec 30th. Also the README seems to indicate the start date has a different purpose. More to indicate at what point in the future should the repeating start (rather than just assume today?)
I tried looking at the tests to see how to get more than one date with this sort of skipping but the tests don't seem to do that. I imagine this same sort of issue occurs not just with every other week but anything like "every other day", "every other month", "every 4th day", etc.
Am I missing something obvious?
The text was updated successfully, but these errors were encountered: