Skip to content

Commit ec65880

Browse files
committed
Add support for 'Wed, Sep 27, 2017' date format
DayName, MonthName ScalarDay, ScalarYear
1 parent 8e243c6 commit ec65880

File tree

2 files changed

+42
-2
lines changed

2 files changed

+42
-2
lines changed

lib/chronic/definition.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ def definitions
4444
class DateDefinitions < SpanDefinitions
4545
def definitions
4646
[
47-
[[DayName, SeparatorSpace, MonthName, SeparatorSpace, OrdinalDay, SeparatorSpace, ScalarYear], :handle_dn_mn_od_sy],
48-
[[DayName, SeparatorSpace, MonthName, SeparatorSpace, ScalarDay, SeparatorSpace, ScalarYear], :handle_dn_mn_sd_sy],
47+
[[DayName, [SeparatorComma, :optional], SeparatorSpace, MonthName, SeparatorSpace, OrdinalDay, [SeparatorComma, :optional], SeparatorSpace, ScalarYear], :handle_dn_mn_od_sy],
48+
[[DayName, [SeparatorComma, :optional], SeparatorSpace, MonthName, SeparatorSpace, ScalarDay, [SeparatorComma, :optional], SeparatorSpace, ScalarYear], :handle_dn_mn_sd_sy],
4949
[[DayName, SeparatorSpace, MonthName, SeparatorSpace, OrdinalDay], :handle_dn_mn_od],
5050
[[DayName, SeparatorSpace, MonthName, SeparatorSpace, ScalarDay], :handle_dn_mn_sd],
5151
[[MonthName, SeparatorSpace, OrdinalDay, [SeparatorComma, SeparatorSpace], [SeparatorSpace, :optional], ScalarYear], :handle_mn_od_sy],

test/test_definitions.rb

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
require 'helper'
2+
3+
class TestDefinitions < TestCase
4+
5+
def setup
6+
end
7+
8+
# DayName, MonthName ScalarDay, ScalarYear
9+
def test_dn_mn_sd_sy
10+
time = Chronic.parse('Wed Sep 27 2017', :guess => false)
11+
assert_equal Time.local(2017, 9, 27, 0), time.begin
12+
assert_equal Time.local(2017, 9, 28, 0), time.end
13+
14+
time = Chronic.parse('Wed, Sep 27, 2017', :guess => false)
15+
assert_equal Time.local(2017, 9, 27, 0), time.begin
16+
assert_equal Time.local(2017, 9, 28, 0), time.end
17+
end
18+
19+
# DayName, MonthName OrdinalDay, ScalarYear
20+
def test_dn_mn_od_sy
21+
time = Chronic.parse('Sun Oct 22nd 2017', :guess => false)
22+
assert_equal Time.local(2017, 10, 22, 0), time.begin
23+
assert_equal Time.local(2017, 10, 23, 0), time.end
24+
25+
time = Chronic.parse('Mon Oct 30th 2017', :guess => false)
26+
assert_equal Time.local(2017, 10, 30, 0), time.begin
27+
assert_equal Time.local(2017, 10, 31, 0), time.end
28+
29+
time = Chronic.parse('Sun, Oct 22nd, 2017', :guess => false)
30+
assert_equal Time.local(2017, 10, 22, 0), time.begin
31+
assert_equal Time.local(2017, 10, 23, 0), time.end
32+
33+
time = Chronic.parse('Mon, Oct 30th, 2017', :guess => false)
34+
assert_equal Time.local(2017, 10, 30, 0), time.begin
35+
assert_equal Time.local(2017, 10, 31, 0), time.end
36+
37+
end
38+
39+
end
40+

0 commit comments

Comments
 (0)