gitlab-chronic 0.10.4 → 0.10.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (54) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +0 -1
  3. data/.travis.yml +4 -6
  4. data/HISTORY.md +4 -0
  5. data/README.md +7 -10
  6. data/chronic.gemspec +1 -1
  7. data/lib/chronic/date.rb +7 -6
  8. data/lib/chronic/{tags/grabber.rb → grabber.rb} +10 -6
  9. data/lib/chronic/handlers.rb +2 -27
  10. data/lib/chronic/mini_date.rb +2 -2
  11. data/lib/chronic/numerizer.rb +130 -0
  12. data/lib/chronic/{tags/ordinal.rb → ordinal.rb} +8 -11
  13. data/lib/chronic/parser.rb +80 -34
  14. data/lib/chronic/{tags/pointer.rb → pointer.rb} +9 -5
  15. data/lib/chronic/{tags/repeater.rb → repeater.rb} +11 -26
  16. data/lib/chronic/repeaters/repeater_day.rb +1 -1
  17. data/lib/chronic/repeaters/repeater_day_name.rb +2 -2
  18. data/lib/chronic/repeaters/repeater_day_portion.rb +3 -3
  19. data/lib/chronic/repeaters/repeater_fortnight.rb +1 -1
  20. data/lib/chronic/repeaters/repeater_hour.rb +1 -1
  21. data/lib/chronic/repeaters/repeater_minute.rb +1 -1
  22. data/lib/chronic/repeaters/repeater_month.rb +1 -1
  23. data/lib/chronic/repeaters/repeater_month_name.rb +2 -2
  24. data/lib/chronic/repeaters/repeater_season.rb +1 -1
  25. data/lib/chronic/repeaters/repeater_second.rb +1 -1
  26. data/lib/chronic/repeaters/repeater_time.rb +2 -2
  27. data/lib/chronic/repeaters/repeater_week.rb +22 -23
  28. data/lib/chronic/repeaters/repeater_weekday.rb +2 -2
  29. data/lib/chronic/repeaters/repeater_weekend.rb +1 -1
  30. data/lib/chronic/repeaters/repeater_year.rb +1 -1
  31. data/lib/chronic/{tags/scalar.rb → scalar.rb} +10 -18
  32. data/lib/chronic/separator.rb +207 -0
  33. data/lib/chronic/{tags/sign.rb → sign.rb} +16 -2
  34. data/lib/chronic/tag.rb +7 -59
  35. data/lib/chronic/time.rb +8 -8
  36. data/lib/chronic/{tags/time_zone.rb → time_zone.rb} +1 -1
  37. data/lib/chronic/token.rb +3 -13
  38. data/lib/chronic/version.rb +1 -1
  39. data/lib/gitlab-chronic.rb +14 -18
  40. data/test/test_chronic.rb +6 -26
  41. data/test/test_handler.rb +1 -1
  42. data/test/test_numerizer.rb +86 -0
  43. data/test/test_parsing.rb +8 -306
  44. data/test/test_repeater_week.rb +0 -53
  45. data/test/test_token.rb +0 -6
  46. metadata +13 -19
  47. data/lib/chronic/definition.rb +0 -128
  48. data/lib/chronic/dictionary.rb +0 -36
  49. data/lib/chronic/repeaters/repeater_quarter.rb +0 -59
  50. data/lib/chronic/repeaters/repeater_quarter_name.rb +0 -40
  51. data/lib/chronic/tags/separator.rb +0 -123
  52. data/lib/chronic/tokenizer.rb +0 -38
  53. data/test/test_repeater_quarter.rb +0 -70
  54. data/test/test_repeater_quarter_name.rb +0 -198
@@ -1,38 +0,0 @@
1
- module Chronic
2
- module Tokenizer
3
- def self.char_type(char)
4
- case char
5
- when '.'
6
- :period
7
- when /[[:alpha:]]/
8
- :letter
9
- when /[[:digit:]]/
10
- :digit
11
- when /[[:space:]]/
12
- :space
13
- when /[[:punct:]]/
14
- :punct
15
- else
16
- :other
17
- end
18
- end
19
-
20
- # Proccess text to tokens
21
- def self.tokenize(text)
22
- tokens = []
23
- index = 0
24
- previos_index = 0
25
- text.each_char do |char|
26
- type = char_type(char)
27
- if type == :space
28
- tokens << Token.new(text[previos_index...index], text, previos_index)
29
- previos_index = index+1
30
- end
31
- index += 1
32
- end
33
- tokens << Token.new(text[previos_index...index], text, previos_index)
34
- tokens
35
- end
36
-
37
- end
38
- end
@@ -1,70 +0,0 @@
1
- require 'helper'
2
-
3
- class TestRepeaterQuarter < TestCase
4
- def setup
5
- @now = Time.local(2006, 8, 16, 14, 0, 0, 0)
6
- end
7
-
8
- def test_match
9
- token = Chronic::Token.new('q')
10
- repeater = Chronic::Repeater.scan_for_units(token)
11
- assert_equal Chronic::RepeaterQuarter, repeater.class
12
- assert_equal :quarter, repeater.type
13
- end
14
-
15
- def test_this
16
- quarter = Chronic::RepeaterQuarter.new(:quarter)
17
- quarter.start = @now
18
-
19
- time = quarter.this
20
- assert_equal Time.local(2006, 7, 1), time.begin
21
- assert_equal Time.local(2006, 10, 1), time.end
22
- end
23
-
24
- def test_next_future
25
- quarter = Chronic::RepeaterQuarter.new(:quarter)
26
- quarter.start = @now
27
-
28
- time = quarter.next(:future)
29
- assert_equal Time.local(2006, 10, 1), time.begin
30
- assert_equal Time.local(2007, 1, 1), time.end
31
-
32
- time = quarter.next(:future)
33
- assert_equal Time.local(2007, 1, 1), time.begin
34
- assert_equal Time.local(2007, 4, 1), time.end
35
-
36
- time = quarter.next(:future)
37
- assert_equal Time.local(2007, 4, 1), time.begin
38
- assert_equal Time.local(2007, 7, 1), time.end
39
- end
40
-
41
- def test_next_past
42
- quarter = Chronic::RepeaterQuarter.new(:quarter)
43
- quarter.start = @now
44
-
45
- time = quarter.next(:past)
46
- assert_equal Time.local(2006, 4, 1), time.begin
47
- assert_equal Time.local(2006, 7, 1), time.end
48
-
49
- time = quarter.next(:past)
50
- assert_equal Time.local(2006, 1, 1), time.begin
51
- assert_equal Time.local(2006, 4, 1), time.end
52
-
53
- time = quarter.next(:past)
54
- assert_equal Time.local(2005, 10, 1), time.begin
55
- assert_equal Time.local(2006, 1, 1), time.end
56
- end
57
-
58
- def test_offset
59
- quarter = Chronic::RepeaterQuarter.new(:quarter)
60
- span = Chronic::Span.new(@now, @now + 1)
61
-
62
- time = quarter.offset(span, 1, :future)
63
- assert_equal Time.local(2006, 10, 1), time.begin
64
- assert_equal Time.local(2007, 1, 1), time.end
65
-
66
- time = quarter.offset(span, 1, :past)
67
- assert_equal Time.local(2006, 4, 1), time.begin
68
- assert_equal Time.local(2006, 7, 1), time.end
69
- end
70
- end
@@ -1,198 +0,0 @@
1
- require 'helper'
2
-
3
- class TestRepeaterQuarterName < TestCase
4
- def setup
5
- @now = Time.local(2006, 8, 16, 14, 0, 0, 0)
6
- end
7
-
8
- def test_match
9
- %w[q1 q2 q3 q4].each do |string|
10
- token = Chronic::Token.new(string)
11
- repeater = Chronic::Repeater.scan_for_quarter_names(token)
12
- assert_equal Chronic::RepeaterQuarterName, repeater.class
13
- assert_equal string.to_sym, repeater.type
14
- end
15
- end
16
-
17
- def test_this_none
18
- quarter = Chronic::RepeaterQuarterName.new(:q1)
19
- quarter.start = @now
20
-
21
- time = quarter.this(:none)
22
- assert_equal Time.local(2006, 1, 1), time.begin
23
- assert_equal Time.local(2006, 4, 1), time.end
24
-
25
- quarter = Chronic::RepeaterQuarterName.new(:q2)
26
- quarter.start = @now
27
-
28
- time = quarter.this(:none)
29
- assert_equal Time.local(2006, 4, 1), time.begin
30
- assert_equal Time.local(2006, 7, 1), time.end
31
-
32
- quarter = Chronic::RepeaterQuarterName.new(:q3)
33
- quarter.start = @now
34
-
35
- time = quarter.this(:none)
36
- assert_equal Time.local(2006, 7, 1), time.begin
37
- assert_equal Time.local(2006, 10, 1), time.end
38
-
39
- quarter = Chronic::RepeaterQuarterName.new(:q4)
40
- quarter.start = @now
41
-
42
- time = quarter.this(:none)
43
- assert_equal Time.local(2006, 10, 1), time.begin
44
- assert_equal Time.local(2007, 1, 1), time.end
45
- end
46
-
47
- def test_this_past
48
- quarter = Chronic::RepeaterQuarterName.new(:q1)
49
- quarter.start = @now
50
-
51
- time = quarter.this(:past)
52
- assert_equal Time.local(2006, 1, 1), time.begin
53
- assert_equal Time.local(2006, 4, 1), time.end
54
-
55
- quarter = Chronic::RepeaterQuarterName.new(:q2)
56
- quarter.start = @now
57
-
58
- time = quarter.this(:past)
59
- assert_equal Time.local(2006, 4, 1), time.begin
60
- assert_equal Time.local(2006, 7, 1), time.end
61
-
62
- quarter = Chronic::RepeaterQuarterName.new(:q3)
63
- quarter.start = @now
64
-
65
- time = quarter.this(:past)
66
- assert_equal Time.local(2005, 7, 1), time.begin
67
- assert_equal Time.local(2005, 10, 1), time.end
68
-
69
- quarter = Chronic::RepeaterQuarterName.new(:q4)
70
- quarter.start = @now
71
-
72
- time = quarter.this(:past)
73
- assert_equal Time.local(2005, 10, 1), time.begin
74
- assert_equal Time.local(2006, 1, 1), time.end
75
- end
76
-
77
- def test_this_future
78
- quarter = Chronic::RepeaterQuarterName.new(:q1)
79
- quarter.start = @now
80
-
81
- time = quarter.this(:future)
82
- assert_equal Time.local(2007, 1, 1), time.begin
83
- assert_equal Time.local(2007, 4, 1), time.end
84
-
85
- quarter = Chronic::RepeaterQuarterName.new(:q2)
86
- quarter.start = @now
87
-
88
- time = quarter.this(:future)
89
- assert_equal Time.local(2007, 4, 1), time.begin
90
- assert_equal Time.local(2007, 7, 1), time.end
91
-
92
- quarter = Chronic::RepeaterQuarterName.new(:q3)
93
- quarter.start = @now
94
-
95
- time = quarter.this(:future)
96
- assert_equal Time.local(2007, 7, 1), time.begin
97
- assert_equal Time.local(2007, 10, 1), time.end
98
-
99
- quarter = Chronic::RepeaterQuarterName.new(:q4)
100
- quarter.start = @now
101
-
102
- time = quarter.this(:future)
103
- assert_equal Time.local(2006, 10, 1), time.begin
104
- assert_equal Time.local(2007, 1, 1), time.end
105
- end
106
-
107
- def test_next_future
108
- quarter = Chronic::RepeaterQuarterName.new(:q1)
109
- quarter.start = @now
110
-
111
- time = quarter.next(:future)
112
- assert_equal Time.local(2007, 1, 1), time.begin
113
- assert_equal Time.local(2007, 4, 1), time.end
114
-
115
- time = quarter.next(:future)
116
- assert_equal Time.local(2008, 1, 1), time.begin
117
- assert_equal Time.local(2008, 4, 1), time.end
118
-
119
- quarter = Chronic::RepeaterQuarterName.new(:q2)
120
- quarter.start = @now
121
-
122
- time = quarter.next(:future)
123
- assert_equal Time.local(2007, 4, 1), time.begin
124
- assert_equal Time.local(2007, 7, 1), time.end
125
-
126
- time = quarter.next(:future)
127
- assert_equal Time.local(2008, 4, 1), time.begin
128
- assert_equal Time.local(2008, 7, 1), time.end
129
-
130
- quarter = Chronic::RepeaterQuarterName.new(:q3)
131
- quarter.start = @now
132
-
133
- time = quarter.next(:future)
134
- assert_equal Time.local(2007, 7, 1), time.begin
135
- assert_equal Time.local(2007, 10, 1), time.end
136
-
137
- time = quarter.next(:future)
138
- assert_equal Time.local(2008, 7, 1), time.begin
139
- assert_equal Time.local(2008, 10, 1), time.end
140
-
141
- quarter = Chronic::RepeaterQuarterName.new(:q4)
142
- quarter.start = @now
143
-
144
- time = quarter.next(:future)
145
- assert_equal Time.local(2006, 10, 1), time.begin
146
- assert_equal Time.local(2007, 1, 1), time.end
147
-
148
- time = quarter.next(:future)
149
- assert_equal Time.local(2007, 10, 1), time.begin
150
- assert_equal Time.local(2008, 1, 1), time.end
151
- end
152
-
153
- def test_next_past
154
- quarter = Chronic::RepeaterQuarterName.new(:q1)
155
- quarter.start = @now
156
-
157
- time = quarter.next(:past)
158
- assert_equal Time.local(2006, 1, 1), time.begin
159
- assert_equal Time.local(2006, 4, 1), time.end
160
-
161
- time = quarter.next(:past)
162
- assert_equal Time.local(2005, 1, 1), time.begin
163
- assert_equal Time.local(2005, 4, 1), time.end
164
-
165
- quarter = Chronic::RepeaterQuarterName.new(:q2)
166
- quarter.start = @now
167
-
168
- time = quarter.next(:past)
169
- assert_equal Time.local(2006, 4, 1), time.begin
170
- assert_equal Time.local(2006, 7, 1), time.end
171
-
172
- time = quarter.next(:past)
173
- assert_equal Time.local(2005, 4, 1), time.begin
174
- assert_equal Time.local(2005, 7, 1), time.end
175
-
176
- quarter = Chronic::RepeaterQuarterName.new(:q3)
177
- quarter.start = @now
178
-
179
- time = quarter.next(:past)
180
- assert_equal Time.local(2005, 7, 1), time.begin
181
- assert_equal Time.local(2005, 10, 1), time.end
182
-
183
- time = quarter.next(:past)
184
- assert_equal Time.local(2004, 7, 1), time.begin
185
- assert_equal Time.local(2004, 10, 1), time.end
186
-
187
- quarter = Chronic::RepeaterQuarterName.new(:q4)
188
- quarter.start = @now
189
-
190
- time = quarter.next(:past)
191
- assert_equal Time.local(2005, 10, 1), time.begin
192
- assert_equal Time.local(2006, 1, 1), time.end
193
-
194
- time = quarter.next(:past)
195
- assert_equal Time.local(2004, 10, 1), time.begin
196
- assert_equal Time.local(2005, 1, 1), time.end
197
- end
198
- end