Skip to content

Commit

Permalink
Add support for 'Wed, Sep 27, 2017' date format
Browse files Browse the repository at this point in the history
DayName, MonthName ScalarDay, ScalarYear
  • Loading branch information
davispuh committed Sep 27, 2017
1 parent 8e243c6 commit ec65880
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/chronic/definition.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ def definitions
class DateDefinitions < SpanDefinitions
def definitions
[
[[DayName, SeparatorSpace, MonthName, SeparatorSpace, OrdinalDay, SeparatorSpace, ScalarYear], :handle_dn_mn_od_sy],
[[DayName, SeparatorSpace, MonthName, SeparatorSpace, ScalarDay, SeparatorSpace, ScalarYear], :handle_dn_mn_sd_sy],
[[DayName, [SeparatorComma, :optional], SeparatorSpace, MonthName, SeparatorSpace, OrdinalDay, [SeparatorComma, :optional], SeparatorSpace, ScalarYear], :handle_dn_mn_od_sy],
[[DayName, [SeparatorComma, :optional], SeparatorSpace, MonthName, SeparatorSpace, ScalarDay, [SeparatorComma, :optional], SeparatorSpace, ScalarYear], :handle_dn_mn_sd_sy],
[[DayName, SeparatorSpace, MonthName, SeparatorSpace, OrdinalDay], :handle_dn_mn_od],
[[DayName, SeparatorSpace, MonthName, SeparatorSpace, ScalarDay], :handle_dn_mn_sd],
[[MonthName, SeparatorSpace, OrdinalDay, [SeparatorComma, SeparatorSpace], [SeparatorSpace, :optional], ScalarYear], :handle_mn_od_sy],
Expand Down
40 changes: 40 additions & 0 deletions test/test_definitions.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
require 'helper'

class TestDefinitions < TestCase

def setup
end

# DayName, MonthName ScalarDay, ScalarYear
def test_dn_mn_sd_sy
time = Chronic.parse('Wed Sep 27 2017', :guess => false)
assert_equal Time.local(2017, 9, 27, 0), time.begin
assert_equal Time.local(2017, 9, 28, 0), time.end

time = Chronic.parse('Wed, Sep 27, 2017', :guess => false)
assert_equal Time.local(2017, 9, 27, 0), time.begin
assert_equal Time.local(2017, 9, 28, 0), time.end
end

# DayName, MonthName OrdinalDay, ScalarYear
def test_dn_mn_od_sy
time = Chronic.parse('Sun Oct 22nd 2017', :guess => false)
assert_equal Time.local(2017, 10, 22, 0), time.begin
assert_equal Time.local(2017, 10, 23, 0), time.end

time = Chronic.parse('Mon Oct 30th 2017', :guess => false)
assert_equal Time.local(2017, 10, 30, 0), time.begin
assert_equal Time.local(2017, 10, 31, 0), time.end

time = Chronic.parse('Sun, Oct 22nd, 2017', :guess => false)
assert_equal Time.local(2017, 10, 22, 0), time.begin
assert_equal Time.local(2017, 10, 23, 0), time.end

time = Chronic.parse('Mon, Oct 30th, 2017', :guess => false)
assert_equal Time.local(2017, 10, 30, 0), time.begin
assert_equal Time.local(2017, 10, 31, 0), time.end

end

end

0 comments on commit ec65880

Please sign in to comment.