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

Day Repeater start fix #429

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion lib/chronic/parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,19 @@ def tokenize(text, options)
tokens.select { |token| token.tagged? }
end

def tokens_to_span(tokens, options)
def cleanup_double_day(tokens)
day_name_index = tokens.index { |o| o.get_tag(RepeaterDayName) }
day_index = tokens.index { |o| o.get_tag(RepeaterDay) || o.get_tag(ScalarDay) || o.get_tag(OrdinalDay) }
year_index = tokens.index { |o| o.get_tag(ScalarYear) || o.get_tag(OrdinalYear) }

if year_index && day_name_index && day_index && day_name_index < day_index
tokens.delete_at(day_name_index)
end

tokens
end

def tokens_to_span(tokens, options, cleaned = false)
definitions = definitions(options)

(definitions[:endian] + definitions[:date]).each do |handler|
Expand Down Expand Up @@ -216,6 +228,8 @@ def tokens_to_span(tokens, options)
end

puts '-none' if Chronic.debug

return tokens_to_span(cleanup_double_day(tokens), options, true) unless cleaned
return nil
end
end
Expand Down
2 changes: 1 addition & 1 deletion test/helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

require 'minitest/autorun'

class TestCase < MiniTest::Test
class TestCase < Minitest::Test
def self.test(name, &block)
define_method("test_#{name.gsub(/\W/, '_')}", &block) if block
end
Expand Down
3 changes: 3 additions & 0 deletions test/test_parsing.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ def test_handle_generic
time = Chronic.parse("2012-08-02T13:00:00")
assert_equal Time.local(2012, 8, 2, 13), time

time = Chronic.parse("Sunday 2025-01-19 at 5pm")
assert_equal Time.local(2025, 1, 19, 17), time

time = Chronic.parse("2012-08-02T13:00:00+01:00")
assert_equal Time.utc(2012, 8, 2, 12), time

Expand Down