chronic 0.5.0 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/HISTORY.md +14 -1
- data/lib/chronic.rb +6 -42
- data/lib/chronic/chronic.rb +73 -48
- data/lib/chronic/handler.rb +90 -0
- data/lib/chronic/handlers.rb +131 -139
- data/lib/chronic/mini_date.rb +12 -6
- data/lib/chronic/numerizer.rb +3 -2
- data/lib/chronic/pointer.rb +1 -2
- data/lib/chronic/repeater.rb +3 -6
- data/lib/chronic/repeaters/repeater_day.rb +6 -6
- data/lib/chronic/repeaters/repeater_day_name.rb +1 -1
- data/lib/chronic/repeaters/repeater_day_portion.rb +8 -8
- data/lib/chronic/repeaters/repeater_fortnight.rb +2 -2
- data/lib/chronic/repeaters/repeater_hour.rb +7 -7
- data/lib/chronic/repeaters/repeater_minute.rb +6 -6
- data/lib/chronic/repeaters/repeater_month.rb +10 -10
- data/lib/chronic/repeaters/repeater_month_name.rb +9 -9
- data/lib/chronic/repeaters/repeater_season.rb +10 -10
- data/lib/chronic/repeaters/repeater_season_name.rb +2 -2
- data/lib/chronic/repeaters/repeater_weekday.rb +1 -1
- data/lib/chronic/repeaters/repeater_year.rb +11 -11
- data/lib/chronic/season.rb +3 -3
- data/lib/chronic/tag.rb +2 -0
- data/test/test_Chronic.rb +48 -4
- data/test/test_DaylightSavings.rb +1 -1
- data/test/test_Handler.rb +1 -6
- data/test/test_MiniDate.rb +3 -3
- data/test/test_Numerizer.rb +1 -1
- data/test/test_RepeaterDayName.rb +1 -1
- data/test/test_RepeaterFortnight.rb +1 -1
- data/test/test_RepeaterHour.rb +1 -1
- data/test/test_RepeaterMinute.rb +1 -1
- data/test/test_RepeaterMonth.rb +1 -1
- data/test/test_RepeaterMonthName.rb +1 -1
- data/test/test_RepeaterSeason.rb +1 -1
- data/test/test_RepeaterTime.rb +1 -1
- data/test/test_RepeaterWeek.rb +1 -1
- data/test/test_RepeaterWeekday.rb +1 -1
- data/test/test_RepeaterWeekend.rb +1 -1
- data/test/test_RepeaterYear.rb +1 -1
- data/test/test_Span.rb +1 -1
- data/test/test_Token.rb +1 -1
- data/test/test_parsing.rb +12 -6
- metadata +3 -5
- data/Manifest.txt +0 -63
- data/test/test_Time.rb +0 -49
data/lib/chronic/season.rb
CHANGED
@@ -17,9 +17,9 @@ module Chronic
|
|
17
17
|
# @param [Integer] pointer The direction (-1 for past, 1 for future)
|
18
18
|
# @return [Symbol] The new season name
|
19
19
|
def self.find_next_season(season, pointer)
|
20
|
-
lookup =
|
21
|
-
next_season_num = (lookup
|
22
|
-
lookup
|
20
|
+
lookup = [:spring, :summer, :autumn, :winter]
|
21
|
+
next_season_num = (lookup.index(season) + 1 * pointer) % 4
|
22
|
+
lookup[next_season_num]
|
23
23
|
end
|
24
24
|
|
25
25
|
# @param [Symbol] season The season name
|
data/lib/chronic/tag.rb
CHANGED
data/test/test_Chronic.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require 'helper'
|
2
2
|
|
3
3
|
class TestChronic < Test::Unit::TestCase
|
4
4
|
|
@@ -74,17 +74,17 @@ class TestChronic < Test::Unit::TestCase
|
|
74
74
|
defs = Chronic.definitions(:endian_precedence => [:little, :middle])
|
75
75
|
assert_equal endians.reverse, defs[:endian]
|
76
76
|
|
77
|
-
assert_raises(
|
77
|
+
assert_raises(ArgumentError) do
|
78
78
|
Chronic.definitions(:endian_precedence => :invalid)
|
79
79
|
end
|
80
80
|
end
|
81
81
|
|
82
82
|
def test_passing_options
|
83
|
-
assert_raises(
|
83
|
+
assert_raises(ArgumentError) do
|
84
84
|
Chronic.parse('now', :invalid => :option)
|
85
85
|
end
|
86
86
|
|
87
|
-
assert_raises(
|
87
|
+
assert_raises(ArgumentError) do
|
88
88
|
Chronic.parse('now', :context => :invalid_context)
|
89
89
|
end
|
90
90
|
end
|
@@ -101,4 +101,48 @@ class TestChronic < Test::Unit::TestCase
|
|
101
101
|
Chronic.debug = false
|
102
102
|
end
|
103
103
|
|
104
|
+
# Chronic.construct
|
105
|
+
|
106
|
+
def test_normal
|
107
|
+
assert_equal Time.local(2006, 1, 2, 0, 0, 0), Chronic.construct(2006, 1, 2, 0, 0, 0)
|
108
|
+
assert_equal Time.local(2006, 1, 2, 3, 0, 0), Chronic.construct(2006, 1, 2, 3, 0, 0)
|
109
|
+
assert_equal Time.local(2006, 1, 2, 3, 4, 0), Chronic.construct(2006, 1, 2, 3, 4, 0)
|
110
|
+
assert_equal Time.local(2006, 1, 2, 3, 4, 5), Chronic.construct(2006, 1, 2, 3, 4, 5)
|
111
|
+
end
|
112
|
+
|
113
|
+
def test_second_overflow
|
114
|
+
assert_equal Time.local(2006, 1, 1, 0, 1, 30), Chronic.construct(2006, 1, 1, 0, 0, 90)
|
115
|
+
assert_equal Time.local(2006, 1, 1, 0, 5, 0), Chronic.construct(2006, 1, 1, 0, 0, 300)
|
116
|
+
end
|
117
|
+
|
118
|
+
def test_minute_overflow
|
119
|
+
assert_equal Time.local(2006, 1, 1, 1, 30), Chronic.construct(2006, 1, 1, 0, 90)
|
120
|
+
assert_equal Time.local(2006, 1, 1, 5), Chronic.construct(2006, 1, 1, 0, 300)
|
121
|
+
end
|
122
|
+
|
123
|
+
def test_hour_overflow
|
124
|
+
assert_equal Time.local(2006, 1, 2, 12), Chronic.construct(2006, 1, 1, 36)
|
125
|
+
assert_equal Time.local(2006, 1, 7), Chronic.construct(2006, 1, 1, 144)
|
126
|
+
end
|
127
|
+
|
128
|
+
def test_day_overflow
|
129
|
+
assert_equal Time.local(2006, 2, 1), Chronic.construct(2006, 1, 32)
|
130
|
+
assert_equal Time.local(2006, 3, 5), Chronic.construct(2006, 2, 33)
|
131
|
+
assert_equal Time.local(2004, 3, 4), Chronic.construct(2004, 2, 33)
|
132
|
+
assert_equal Time.local(2000, 3, 4), Chronic.construct(2000, 2, 33)
|
133
|
+
|
134
|
+
assert_nothing_raised do
|
135
|
+
Chronic.construct(2006, 1, 56)
|
136
|
+
end
|
137
|
+
|
138
|
+
assert_raise(RuntimeError) do
|
139
|
+
Chronic.construct(2006, 1, 57)
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
def test_month_overflow
|
144
|
+
assert_equal Time.local(2006, 1), Chronic.construct(2005, 13)
|
145
|
+
assert_equal Time.local(2005, 12), Chronic.construct(2000, 72)
|
146
|
+
end
|
147
|
+
|
104
148
|
end
|
data/test/test_Handler.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require 'helper'
|
2
2
|
|
3
3
|
class TestHandler < Test::Unit::TestCase
|
4
4
|
|
@@ -101,9 +101,4 @@ class TestHandler < Test::Unit::TestCase
|
|
101
101
|
assert handler.match(tokens, Chronic.definitions)
|
102
102
|
end
|
103
103
|
|
104
|
-
def test_constantize
|
105
|
-
handler = Chronic::Handler.new([], :handler)
|
106
|
-
assert_equal Chronic::RepeaterTime, handler.constantize(:repeater_time)
|
107
|
-
end
|
108
|
-
|
109
104
|
end
|
data/test/test_MiniDate.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
|
-
require
|
1
|
+
require 'helper'
|
2
2
|
|
3
3
|
class TestMiniDate < Test::Unit::TestCase
|
4
4
|
def test_valid_month
|
5
|
-
assert_raise(
|
6
|
-
assert_raise(
|
5
|
+
assert_raise(ArgumentError){ Chronic::MiniDate.new(0,12) }
|
6
|
+
assert_raise(ArgumentError){ Chronic::MiniDate.new(13,1) }
|
7
7
|
end
|
8
8
|
|
9
9
|
def test_is_between
|
data/test/test_Numerizer.rb
CHANGED
data/test/test_RepeaterHour.rb
CHANGED
data/test/test_RepeaterMinute.rb
CHANGED
data/test/test_RepeaterMonth.rb
CHANGED
data/test/test_RepeaterSeason.rb
CHANGED
data/test/test_RepeaterTime.rb
CHANGED
data/test/test_RepeaterWeek.rb
CHANGED
data/test/test_RepeaterYear.rb
CHANGED
data/test/test_Span.rb
CHANGED
data/test/test_Token.rb
CHANGED
data/test/test_parsing.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require 'helper'
|
2
2
|
|
3
3
|
class TestParsing < Test::Unit::TestCase
|
4
4
|
# Wed Aug 16 14:00:00 UTC 2006
|
@@ -8,9 +8,6 @@ class TestParsing < Test::Unit::TestCase
|
|
8
8
|
@time_2006_08_16_14_00_00 = TIME_2006_08_16_14_00_00
|
9
9
|
end
|
10
10
|
|
11
|
-
def test_parse_m_d
|
12
|
-
end
|
13
|
-
|
14
11
|
def test_handle_rmn_sd
|
15
12
|
time = parse_now("aug 3")
|
16
13
|
assert_equal Time.local(2006, 8, 3, 12), time
|
@@ -109,6 +106,11 @@ class TestParsing < Test::Unit::TestCase
|
|
109
106
|
assert_equal 1175558400, time.to_i
|
110
107
|
end
|
111
108
|
|
109
|
+
def test_handle_sy_sm_sd_t_tz
|
110
|
+
time = parse_now("2011-07-03 22:11:35 +0100")
|
111
|
+
assert_equal 1309727495, time.to_i
|
112
|
+
end
|
113
|
+
|
112
114
|
def test_handle_rmn_sd_sy
|
113
115
|
time = parse_now("November 18, 2010")
|
114
116
|
assert_equal Time.local(2010, 11, 18, 12), time
|
@@ -207,6 +209,10 @@ class TestParsing < Test::Unit::TestCase
|
|
207
209
|
|
208
210
|
time = parse_now("5/27/1979 4am")
|
209
211
|
assert_equal Time.local(1979, 5, 27, 4), time
|
212
|
+
|
213
|
+
# month day overflows
|
214
|
+
time = parse_now("30/2/2000")
|
215
|
+
assert_nil time
|
210
216
|
end
|
211
217
|
|
212
218
|
def test_handle_sd_sm_sy
|
@@ -777,11 +783,11 @@ class TestParsing < Test::Unit::TestCase
|
|
777
783
|
end
|
778
784
|
|
779
785
|
def test_argument_validation
|
780
|
-
assert_raise(
|
786
|
+
assert_raise(ArgumentError) do
|
781
787
|
time = Chronic.parse("may 27", :foo => :bar)
|
782
788
|
end
|
783
789
|
|
784
|
-
assert_raise(
|
790
|
+
assert_raise(ArgumentError) do
|
785
791
|
time = Chronic.parse("may 27", :context => :bar)
|
786
792
|
end
|
787
793
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: chronic
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2011-07-
|
13
|
+
date: 2011-07-19 00:00:00.000000000 +01:00
|
14
14
|
default_executable:
|
15
15
|
dependencies: []
|
16
16
|
description: Chronic is a natural language date/time parser written in pure Ruby.
|
@@ -29,13 +29,13 @@ files:
|
|
29
29
|
- .yardopts
|
30
30
|
- HISTORY.md
|
31
31
|
- LICENSE
|
32
|
-
- Manifest.txt
|
33
32
|
- README.md
|
34
33
|
- Rakefile
|
35
34
|
- chronic.gemspec
|
36
35
|
- lib/chronic.rb
|
37
36
|
- lib/chronic/chronic.rb
|
38
37
|
- lib/chronic/grabber.rb
|
38
|
+
- lib/chronic/handler.rb
|
39
39
|
- lib/chronic/handlers.rb
|
40
40
|
- lib/chronic/mini_date.rb
|
41
41
|
- lib/chronic/numerizer.rb
|
@@ -84,7 +84,6 @@ files:
|
|
84
84
|
- test/test_RepeaterWeekend.rb
|
85
85
|
- test/test_RepeaterYear.rb
|
86
86
|
- test/test_Span.rb
|
87
|
-
- test/test_Time.rb
|
88
87
|
- test/test_Token.rb
|
89
88
|
- test/test_parsing.rb
|
90
89
|
has_rdoc: true
|
@@ -133,6 +132,5 @@ test_files:
|
|
133
132
|
- test/test_RepeaterWeekend.rb
|
134
133
|
- test/test_RepeaterYear.rb
|
135
134
|
- test/test_Span.rb
|
136
|
-
- test/test_Time.rb
|
137
135
|
- test/test_Token.rb
|
138
136
|
- test/test_parsing.rb
|
data/Manifest.txt
DELETED
@@ -1,63 +0,0 @@
|
|
1
|
-
.gemtest
|
2
|
-
.gitignore
|
3
|
-
.yardopts
|
4
|
-
HISTORY.md
|
5
|
-
LICENSE
|
6
|
-
Manifest.txt
|
7
|
-
README.md
|
8
|
-
Rakefile
|
9
|
-
chronic.gemspec
|
10
|
-
lib/chronic.rb
|
11
|
-
lib/chronic/chronic.rb
|
12
|
-
lib/chronic/grabber.rb
|
13
|
-
lib/chronic/handlers.rb
|
14
|
-
lib/chronic/mini_date.rb
|
15
|
-
lib/chronic/numerizer.rb
|
16
|
-
lib/chronic/ordinal.rb
|
17
|
-
lib/chronic/pointer.rb
|
18
|
-
lib/chronic/repeater.rb
|
19
|
-
lib/chronic/repeaters/repeater_day.rb
|
20
|
-
lib/chronic/repeaters/repeater_day_name.rb
|
21
|
-
lib/chronic/repeaters/repeater_day_portion.rb
|
22
|
-
lib/chronic/repeaters/repeater_fortnight.rb
|
23
|
-
lib/chronic/repeaters/repeater_hour.rb
|
24
|
-
lib/chronic/repeaters/repeater_minute.rb
|
25
|
-
lib/chronic/repeaters/repeater_month.rb
|
26
|
-
lib/chronic/repeaters/repeater_month_name.rb
|
27
|
-
lib/chronic/repeaters/repeater_season.rb
|
28
|
-
lib/chronic/repeaters/repeater_season_name.rb
|
29
|
-
lib/chronic/repeaters/repeater_second.rb
|
30
|
-
lib/chronic/repeaters/repeater_time.rb
|
31
|
-
lib/chronic/repeaters/repeater_week.rb
|
32
|
-
lib/chronic/repeaters/repeater_weekday.rb
|
33
|
-
lib/chronic/repeaters/repeater_weekend.rb
|
34
|
-
lib/chronic/repeaters/repeater_year.rb
|
35
|
-
lib/chronic/scalar.rb
|
36
|
-
lib/chronic/season.rb
|
37
|
-
lib/chronic/separator.rb
|
38
|
-
lib/chronic/span.rb
|
39
|
-
lib/chronic/tag.rb
|
40
|
-
lib/chronic/time_zone.rb
|
41
|
-
lib/chronic/token.rb
|
42
|
-
test/helper.rb
|
43
|
-
test/test_Chronic.rb
|
44
|
-
test/test_DaylightSavings.rb
|
45
|
-
test/test_Handler.rb
|
46
|
-
test/test_MiniDate.rb
|
47
|
-
test/test_Numerizer.rb
|
48
|
-
test/test_RepeaterDayName.rb
|
49
|
-
test/test_RepeaterFortnight.rb
|
50
|
-
test/test_RepeaterHour.rb
|
51
|
-
test/test_RepeaterMinute.rb
|
52
|
-
test/test_RepeaterMonth.rb
|
53
|
-
test/test_RepeaterMonthName.rb
|
54
|
-
test/test_RepeaterSeason.rb
|
55
|
-
test/test_RepeaterTime.rb
|
56
|
-
test/test_RepeaterWeek.rb
|
57
|
-
test/test_RepeaterWeekday.rb
|
58
|
-
test/test_RepeaterWeekend.rb
|
59
|
-
test/test_RepeaterYear.rb
|
60
|
-
test/test_Span.rb
|
61
|
-
test/test_Time.rb
|
62
|
-
test/test_Token.rb
|
63
|
-
test/test_parsing.rb
|
data/test/test_Time.rb
DELETED
@@ -1,49 +0,0 @@
|
|
1
|
-
require File.join(File.dirname(__FILE__), *%w[helper])
|
2
|
-
|
3
|
-
class TestTime < Test::Unit::TestCase
|
4
|
-
|
5
|
-
def setup
|
6
|
-
end
|
7
|
-
|
8
|
-
def test_normal
|
9
|
-
assert_equal Time.local(2006, 1, 2, 0, 0, 0), Time.construct(2006, 1, 2, 0, 0, 0)
|
10
|
-
assert_equal Time.local(2006, 1, 2, 3, 0, 0), Time.construct(2006, 1, 2, 3, 0, 0)
|
11
|
-
assert_equal Time.local(2006, 1, 2, 3, 4, 0), Time.construct(2006, 1, 2, 3, 4, 0)
|
12
|
-
assert_equal Time.local(2006, 1, 2, 3, 4, 5), Time.construct(2006, 1, 2, 3, 4, 5)
|
13
|
-
end
|
14
|
-
|
15
|
-
def test_second_overflow
|
16
|
-
assert_equal Time.local(2006, 1, 1, 0, 1, 30), Time.construct(2006, 1, 1, 0, 0, 90)
|
17
|
-
assert_equal Time.local(2006, 1, 1, 0, 5, 0), Time.construct(2006, 1, 1, 0, 0, 300)
|
18
|
-
end
|
19
|
-
|
20
|
-
def test_minute_overflow
|
21
|
-
assert_equal Time.local(2006, 1, 1, 1, 30), Time.construct(2006, 1, 1, 0, 90)
|
22
|
-
assert_equal Time.local(2006, 1, 1, 5), Time.construct(2006, 1, 1, 0, 300)
|
23
|
-
end
|
24
|
-
|
25
|
-
def test_hour_overflow
|
26
|
-
assert_equal Time.local(2006, 1, 2, 12), Time.construct(2006, 1, 1, 36)
|
27
|
-
assert_equal Time.local(2006, 1, 7), Time.construct(2006, 1, 1, 144)
|
28
|
-
end
|
29
|
-
|
30
|
-
def test_day_overflow
|
31
|
-
assert_equal Time.local(2006, 2, 1), Time.construct(2006, 1, 32)
|
32
|
-
assert_equal Time.local(2006, 3, 5), Time.construct(2006, 2, 33)
|
33
|
-
assert_equal Time.local(2004, 3, 4), Time.construct(2004, 2, 33)
|
34
|
-
assert_equal Time.local(2000, 3, 4), Time.construct(2000, 2, 33)
|
35
|
-
|
36
|
-
assert_nothing_raised do
|
37
|
-
Time.construct(2006, 1, 56)
|
38
|
-
end
|
39
|
-
|
40
|
-
assert_raise(RuntimeError) do
|
41
|
-
Time.construct(2006, 1, 57)
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
def test_month_overflow
|
46
|
-
assert_equal Time.local(2006, 1), Time.construct(2005, 13)
|
47
|
-
assert_equal Time.local(2005, 12), Time.construct(2000, 72)
|
48
|
-
end
|
49
|
-
end
|