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.
- checksums.yaml +4 -4
- data/.gitignore +0 -1
- data/.travis.yml +4 -6
- data/HISTORY.md +4 -0
- data/README.md +7 -10
- data/chronic.gemspec +1 -1
- data/lib/chronic/date.rb +7 -6
- data/lib/chronic/{tags/grabber.rb → grabber.rb} +10 -6
- data/lib/chronic/handlers.rb +2 -27
- data/lib/chronic/mini_date.rb +2 -2
- data/lib/chronic/numerizer.rb +130 -0
- data/lib/chronic/{tags/ordinal.rb → ordinal.rb} +8 -11
- data/lib/chronic/parser.rb +80 -34
- data/lib/chronic/{tags/pointer.rb → pointer.rb} +9 -5
- data/lib/chronic/{tags/repeater.rb → repeater.rb} +11 -26
- data/lib/chronic/repeaters/repeater_day.rb +1 -1
- data/lib/chronic/repeaters/repeater_day_name.rb +2 -2
- data/lib/chronic/repeaters/repeater_day_portion.rb +3 -3
- data/lib/chronic/repeaters/repeater_fortnight.rb +1 -1
- data/lib/chronic/repeaters/repeater_hour.rb +1 -1
- data/lib/chronic/repeaters/repeater_minute.rb +1 -1
- data/lib/chronic/repeaters/repeater_month.rb +1 -1
- data/lib/chronic/repeaters/repeater_month_name.rb +2 -2
- data/lib/chronic/repeaters/repeater_season.rb +1 -1
- data/lib/chronic/repeaters/repeater_second.rb +1 -1
- data/lib/chronic/repeaters/repeater_time.rb +2 -2
- data/lib/chronic/repeaters/repeater_week.rb +22 -23
- data/lib/chronic/repeaters/repeater_weekday.rb +2 -2
- data/lib/chronic/repeaters/repeater_weekend.rb +1 -1
- data/lib/chronic/repeaters/repeater_year.rb +1 -1
- data/lib/chronic/{tags/scalar.rb → scalar.rb} +10 -18
- data/lib/chronic/separator.rb +207 -0
- data/lib/chronic/{tags/sign.rb → sign.rb} +16 -2
- data/lib/chronic/tag.rb +7 -59
- data/lib/chronic/time.rb +8 -8
- data/lib/chronic/{tags/time_zone.rb → time_zone.rb} +1 -1
- data/lib/chronic/token.rb +3 -13
- data/lib/chronic/version.rb +1 -1
- data/lib/gitlab-chronic.rb +14 -18
- data/test/test_chronic.rb +6 -26
- data/test/test_handler.rb +1 -1
- data/test/test_numerizer.rb +86 -0
- data/test/test_parsing.rb +8 -306
- data/test/test_repeater_week.rb +0 -53
- data/test/test_token.rb +0 -6
- metadata +13 -19
- data/lib/chronic/definition.rb +0 -128
- data/lib/chronic/dictionary.rb +0 -36
- data/lib/chronic/repeaters/repeater_quarter.rb +0 -59
- data/lib/chronic/repeaters/repeater_quarter_name.rb +0 -40
- data/lib/chronic/tags/separator.rb +0 -123
- data/lib/chronic/tokenizer.rb +0 -38
- data/test/test_repeater_quarter.rb +0 -70
- data/test/test_repeater_quarter_name.rb +0 -198
data/test/test_repeater_week.rb
CHANGED
@@ -59,57 +59,4 @@ class TestRepeaterWeek < TestCase
|
|
59
59
|
assert_equal Time.local(2006, 9, 6, 14, 0, 1), offset_span.end
|
60
60
|
end
|
61
61
|
|
62
|
-
def test_next_future_starting_on_monday
|
63
|
-
weeks = Chronic::RepeaterWeek.new(:week, nil, :week_start => :monday)
|
64
|
-
weeks.start = @now
|
65
|
-
|
66
|
-
next_week = weeks.next(:future)
|
67
|
-
assert_equal Time.local(2006, 8, 21), next_week.begin
|
68
|
-
assert_equal Time.local(2006, 8, 28), next_week.end
|
69
|
-
|
70
|
-
next_next_week = weeks.next(:future)
|
71
|
-
assert_equal Time.local(2006, 8, 28), next_next_week.begin
|
72
|
-
assert_equal Time.local(2006, 9, 4), next_next_week.end
|
73
|
-
end
|
74
|
-
|
75
|
-
def test_next_past_starting_on_monday
|
76
|
-
weeks = Chronic::RepeaterWeek.new(:week, nil, :week_start => :monday)
|
77
|
-
weeks.start = @now
|
78
|
-
|
79
|
-
last_week = weeks.next(:past)
|
80
|
-
assert_equal Time.local(2006, 8, 7), last_week.begin
|
81
|
-
assert_equal Time.local(2006, 8, 14), last_week.end
|
82
|
-
|
83
|
-
last_last_week = weeks.next(:past)
|
84
|
-
assert_equal Time.local(2006, 7, 31), last_last_week.begin
|
85
|
-
assert_equal Time.local(2006, 8, 7), last_last_week.end
|
86
|
-
end
|
87
|
-
|
88
|
-
def test_this_future_starting_on_monday
|
89
|
-
weeks = Chronic::RepeaterWeek.new(:week, nil, :week_start => :monday)
|
90
|
-
weeks.start = @now
|
91
|
-
|
92
|
-
this_week = weeks.this(:future)
|
93
|
-
assert_equal Time.local(2006, 8, 16, 15), this_week.begin
|
94
|
-
assert_equal Time.local(2006, 8, 21), this_week.end
|
95
|
-
end
|
96
|
-
|
97
|
-
def test_this_past_starting_on_monday
|
98
|
-
weeks = Chronic::RepeaterWeek.new(:week, nil, :week_start => :monday)
|
99
|
-
weeks.start = @now
|
100
|
-
|
101
|
-
this_week = weeks.this(:past)
|
102
|
-
assert_equal Time.local(2006, 8, 14, 0), this_week.begin
|
103
|
-
assert_equal Time.local(2006, 8, 16, 14), this_week.end
|
104
|
-
end
|
105
|
-
|
106
|
-
def test_offset_starting_on_monday
|
107
|
-
weeks = Chronic::RepeaterWeek.new(:week, nil, :week_start => :monday)
|
108
|
-
|
109
|
-
span = Chronic::Span.new(@now, @now + 1)
|
110
|
-
offset_span = weeks.offset(span, 3, :future)
|
111
|
-
|
112
|
-
assert_equal Time.local(2006, 9, 6, 14), offset_span.begin
|
113
|
-
assert_equal Time.local(2006, 9, 6, 14, 0, 1), offset_span.end
|
114
|
-
end
|
115
62
|
end
|
data/test/test_token.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gitlab-chronic
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.10.
|
4
|
+
version: 0.10.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tom Preston-Werner
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2019-11-
|
12
|
+
date: 2019-11-25 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: numerizer
|
@@ -102,12 +102,15 @@ files:
|
|
102
102
|
- Rakefile
|
103
103
|
- chronic.gemspec
|
104
104
|
- lib/chronic/date.rb
|
105
|
-
- lib/chronic/
|
106
|
-
- lib/chronic/dictionary.rb
|
105
|
+
- lib/chronic/grabber.rb
|
107
106
|
- lib/chronic/handler.rb
|
108
107
|
- lib/chronic/handlers.rb
|
109
108
|
- lib/chronic/mini_date.rb
|
109
|
+
- lib/chronic/numerizer.rb
|
110
|
+
- lib/chronic/ordinal.rb
|
110
111
|
- lib/chronic/parser.rb
|
112
|
+
- lib/chronic/pointer.rb
|
113
|
+
- lib/chronic/repeater.rb
|
111
114
|
- lib/chronic/repeaters/repeater_day.rb
|
112
115
|
- lib/chronic/repeaters/repeater_day_name.rb
|
113
116
|
- lib/chronic/repeaters/repeater_day_portion.rb
|
@@ -116,8 +119,6 @@ files:
|
|
116
119
|
- lib/chronic/repeaters/repeater_minute.rb
|
117
120
|
- lib/chronic/repeaters/repeater_month.rb
|
118
121
|
- lib/chronic/repeaters/repeater_month_name.rb
|
119
|
-
- lib/chronic/repeaters/repeater_quarter.rb
|
120
|
-
- lib/chronic/repeaters/repeater_quarter_name.rb
|
121
122
|
- lib/chronic/repeaters/repeater_season.rb
|
122
123
|
- lib/chronic/repeaters/repeater_season_name.rb
|
123
124
|
- lib/chronic/repeaters/repeater_second.rb
|
@@ -126,20 +127,15 @@ files:
|
|
126
127
|
- lib/chronic/repeaters/repeater_weekday.rb
|
127
128
|
- lib/chronic/repeaters/repeater_weekend.rb
|
128
129
|
- lib/chronic/repeaters/repeater_year.rb
|
130
|
+
- lib/chronic/scalar.rb
|
129
131
|
- lib/chronic/season.rb
|
132
|
+
- lib/chronic/separator.rb
|
133
|
+
- lib/chronic/sign.rb
|
130
134
|
- lib/chronic/span.rb
|
131
135
|
- lib/chronic/tag.rb
|
132
|
-
- lib/chronic/tags/grabber.rb
|
133
|
-
- lib/chronic/tags/ordinal.rb
|
134
|
-
- lib/chronic/tags/pointer.rb
|
135
|
-
- lib/chronic/tags/repeater.rb
|
136
|
-
- lib/chronic/tags/scalar.rb
|
137
|
-
- lib/chronic/tags/separator.rb
|
138
|
-
- lib/chronic/tags/sign.rb
|
139
|
-
- lib/chronic/tags/time_zone.rb
|
140
136
|
- lib/chronic/time.rb
|
137
|
+
- lib/chronic/time_zone.rb
|
141
138
|
- lib/chronic/token.rb
|
142
|
-
- lib/chronic/tokenizer.rb
|
143
139
|
- lib/chronic/version.rb
|
144
140
|
- lib/gitlab-chronic.rb
|
145
141
|
- test/helper.rb
|
@@ -147,6 +143,7 @@ files:
|
|
147
143
|
- test/test_daylight_savings.rb
|
148
144
|
- test/test_handler.rb
|
149
145
|
- test/test_mini_date.rb
|
146
|
+
- test/test_numerizer.rb
|
150
147
|
- test/test_parsing.rb
|
151
148
|
- test/test_repeater_day_name.rb
|
152
149
|
- test/test_repeater_day_portion.rb
|
@@ -155,8 +152,6 @@ files:
|
|
155
152
|
- test/test_repeater_minute.rb
|
156
153
|
- test/test_repeater_month.rb
|
157
154
|
- test/test_repeater_month_name.rb
|
158
|
-
- test/test_repeater_quarter.rb
|
159
|
-
- test/test_repeater_quarter_name.rb
|
160
155
|
- test/test_repeater_season.rb
|
161
156
|
- test/test_repeater_time.rb
|
162
157
|
- test/test_repeater_week.rb
|
@@ -195,6 +190,7 @@ test_files:
|
|
195
190
|
- test/test_daylight_savings.rb
|
196
191
|
- test/test_handler.rb
|
197
192
|
- test/test_mini_date.rb
|
193
|
+
- test/test_numerizer.rb
|
198
194
|
- test/test_parsing.rb
|
199
195
|
- test/test_repeater_day_name.rb
|
200
196
|
- test/test_repeater_day_portion.rb
|
@@ -203,8 +199,6 @@ test_files:
|
|
203
199
|
- test/test_repeater_minute.rb
|
204
200
|
- test/test_repeater_month.rb
|
205
201
|
- test/test_repeater_month_name.rb
|
206
|
-
- test/test_repeater_quarter.rb
|
207
|
-
- test/test_repeater_quarter_name.rb
|
208
202
|
- test/test_repeater_season.rb
|
209
203
|
- test/test_repeater_time.rb
|
210
204
|
- test/test_repeater_week.rb
|
data/lib/chronic/definition.rb
DELETED
@@ -1,128 +0,0 @@
|
|
1
|
-
require 'chronic/handlers'
|
2
|
-
|
3
|
-
module Chronic
|
4
|
-
# SpanDefinitions subclasses return definitions constructed by Handler instances (see handler.rb)
|
5
|
-
# SpanDefinitions subclasses follow a <Type> + Definitions naming pattern
|
6
|
-
# Types of Definitions are collected in Dictionaries (see dictionary.rb)
|
7
|
-
class Definitions
|
8
|
-
attr_reader :options
|
9
|
-
|
10
|
-
def initialize(options = {})
|
11
|
-
@options = options
|
12
|
-
end
|
13
|
-
|
14
|
-
def definitions
|
15
|
-
raise "definitions are set in subclasses of #{self.class}"
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
class SpanDefinitions < Definitions
|
20
|
-
include Handlers
|
21
|
-
end
|
22
|
-
|
23
|
-
class TimeDefinitions < SpanDefinitions
|
24
|
-
def definitions
|
25
|
-
[
|
26
|
-
Handler.new([:repeater_time, :repeater_day_portion?], nil)
|
27
|
-
]
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
class DateDefinitions < SpanDefinitions
|
32
|
-
def definitions
|
33
|
-
[
|
34
|
-
Handler.new([:repeater_day_name, :repeater_month_name, :scalar_day, :repeater_time, [:separator_slash?, :separator_dash?], :time_zone, :scalar_year], :handle_generic),
|
35
|
-
Handler.new([:repeater_day_name, :repeater_month_name, :scalar_day], :handle_rdn_rmn_sd),
|
36
|
-
Handler.new([:repeater_day_name, :repeater_month_name, :scalar_day, :scalar_year], :handle_rdn_rmn_sd_sy),
|
37
|
-
Handler.new([:repeater_day_name, :repeater_month_name, :ordinal_day], :handle_rdn_rmn_od),
|
38
|
-
Handler.new([:repeater_day_name, :repeater_month_name, :ordinal_day, :scalar_year], :handle_rdn_rmn_od_sy),
|
39
|
-
Handler.new([:repeater_day_name, :repeater_month_name, :scalar_day, :separator_at?, 'time?'], :handle_rdn_rmn_sd),
|
40
|
-
Handler.new([:repeater_day_name, :repeater_month_name, :ordinal_day, :separator_at?, 'time?'], :handle_rdn_rmn_od),
|
41
|
-
Handler.new([:repeater_day_name, :ordinal_day, :separator_at?, 'time?'], :handle_rdn_od),
|
42
|
-
Handler.new([:scalar_year, [:separator_slash, :separator_dash], :scalar_month, [:separator_slash, :separator_dash], :scalar_day, :repeater_time, :time_zone], :handle_generic),
|
43
|
-
Handler.new([:ordinal_day], :handle_generic),
|
44
|
-
Handler.new([:repeater_month_name, :scalar_day, :scalar_year], :handle_rmn_sd_sy),
|
45
|
-
Handler.new([:repeater_month_name, :ordinal_day, :scalar_year], :handle_rmn_od_sy),
|
46
|
-
Handler.new([:repeater_month_name, :scalar_day, :scalar_year, :separator_at?, 'time?'], :handle_rmn_sd_sy),
|
47
|
-
Handler.new([:repeater_month_name, :ordinal_day, :scalar_year, :separator_at?, 'time?'], :handle_rmn_od_sy),
|
48
|
-
Handler.new([:repeater_month_name, [:separator_slash?, :separator_dash?], :scalar_day, :separator_at?, 'time?'], :handle_rmn_sd),
|
49
|
-
Handler.new([:repeater_time, :repeater_day_portion?, :separator_on?, :repeater_month_name, :scalar_day], :handle_rmn_sd_on),
|
50
|
-
Handler.new([:repeater_month_name, :ordinal_day, :separator_at?, 'time?'], :handle_rmn_od),
|
51
|
-
Handler.new([:ordinal_day, :repeater_month_name, :scalar_year, :separator_at?, 'time?'], :handle_od_rmn_sy),
|
52
|
-
Handler.new([:ordinal_day, :repeater_month_name, :separator_at?, 'time?'], :handle_od_rmn),
|
53
|
-
Handler.new([:ordinal_day, :grabber?, :repeater_month, :separator_at?, 'time?'], :handle_od_rm),
|
54
|
-
Handler.new([:scalar_year, :repeater_month_name, :ordinal_day], :handle_sy_rmn_od),
|
55
|
-
Handler.new([:repeater_time, :repeater_day_portion?, :separator_on?, :repeater_month_name, :ordinal_day], :handle_rmn_od_on),
|
56
|
-
Handler.new([:repeater_month_name, :scalar_year], :handle_rmn_sy),
|
57
|
-
Handler.new([:repeater_quarter_name, :scalar_year], :handle_rqn_sy),
|
58
|
-
Handler.new([:scalar_year, :repeater_quarter_name], :handle_sy_rqn),
|
59
|
-
Handler.new([:scalar_day, :repeater_month_name, :scalar_year, :separator_at?, 'time?'], :handle_sd_rmn_sy),
|
60
|
-
Handler.new([:scalar_day, [:separator_slash?, :separator_dash?], :repeater_month_name, :separator_at?, 'time?'], :handle_sd_rmn),
|
61
|
-
Handler.new([:scalar_year, [:separator_slash, :separator_dash], :scalar_month, [:separator_slash, :separator_dash], :scalar_day, :separator_at?, 'time?'], :handle_sy_sm_sd),
|
62
|
-
Handler.new([:scalar_year, [:separator_slash, :separator_dash], :scalar_month], :handle_sy_sm),
|
63
|
-
Handler.new([:scalar_month, [:separator_slash, :separator_dash], :scalar_year], :handle_sm_sy),
|
64
|
-
Handler.new([:scalar_day, [:separator_slash, :separator_dash], :repeater_month_name, [:separator_slash, :separator_dash], :scalar_year, :repeater_time?], :handle_sm_rmn_sy),
|
65
|
-
Handler.new([:scalar_year, [:separator_slash, :separator_dash], :scalar_month, [:separator_slash, :separator_dash], :scalar?, :time_zone], :handle_generic),
|
66
|
-
]
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
|
-
class AnchorDefinitions < SpanDefinitions
|
71
|
-
def definitions
|
72
|
-
[
|
73
|
-
Handler.new([:separator_on?, :grabber?, :repeater, :separator_at?, :repeater?, :repeater?], :handle_r),
|
74
|
-
Handler.new([:grabber?, :repeater, :repeater, :separator?, :repeater?, :repeater?], :handle_r),
|
75
|
-
Handler.new([:repeater, :grabber, :repeater], :handle_r_g_r)
|
76
|
-
]
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
|
-
class ArrowDefinitions < SpanDefinitions
|
81
|
-
def definitions
|
82
|
-
[
|
83
|
-
Handler.new([:repeater_month_name, :scalar, :repeater, :pointer], :handle_rmn_s_r_p),
|
84
|
-
Handler.new([:scalar, :repeater, :pointer], :handle_s_r_p),
|
85
|
-
Handler.new([:scalar, :repeater, :separator_and?, :scalar, :repeater, :pointer, :separator_at?, 'anchor'], :handle_s_r_a_s_r_p_a),
|
86
|
-
Handler.new([:pointer, :scalar, :repeater], :handle_p_s_r),
|
87
|
-
Handler.new([:scalar, :repeater, :pointer, :separator_at?, 'anchor'], :handle_s_r_p_a)
|
88
|
-
]
|
89
|
-
end
|
90
|
-
end
|
91
|
-
|
92
|
-
class NarrowDefinitions < SpanDefinitions
|
93
|
-
def definitions
|
94
|
-
[
|
95
|
-
Handler.new([:ordinal, :repeater, :separator_in, :repeater], :handle_o_r_s_r),
|
96
|
-
Handler.new([:ordinal, :repeater, :grabber, :repeater], :handle_o_r_g_r)
|
97
|
-
]
|
98
|
-
end
|
99
|
-
end
|
100
|
-
|
101
|
-
class EndianDefinitions < SpanDefinitions
|
102
|
-
def definitions
|
103
|
-
prefered_endian
|
104
|
-
end
|
105
|
-
|
106
|
-
def prefered_endian
|
107
|
-
options[:endian_precedence] ||= [:middle, :little]
|
108
|
-
|
109
|
-
definitions = [
|
110
|
-
Handler.new([:scalar_month, [:separator_slash, :separator_dash], :scalar_day, [:separator_slash, :separator_dash], :scalar_year, :separator_at?, 'time?'], :handle_sm_sd_sy),
|
111
|
-
Handler.new([:scalar_month, [:separator_slash, :separator_dash], :scalar_day, :separator_at?, 'time?'], :handle_sm_sd),
|
112
|
-
Handler.new([:scalar_day, [:separator_slash, :separator_dash], :scalar_month, :separator_at?, 'time?'], :handle_sd_sm),
|
113
|
-
Handler.new([:scalar_day, [:separator_slash, :separator_dash], :scalar_month, [:separator_slash, :separator_dash], :scalar_year, :separator_at?, 'time?'], :handle_sd_sm_sy),
|
114
|
-
Handler.new([:scalar_day, :repeater_month_name, :scalar_year, :separator_at?, 'time?'], :handle_sd_rmn_sy)
|
115
|
-
]
|
116
|
-
|
117
|
-
case endian = Array(options[:endian_precedence]).first
|
118
|
-
when :little
|
119
|
-
definitions.reverse
|
120
|
-
when :middle
|
121
|
-
definitions
|
122
|
-
else
|
123
|
-
raise ArgumentError, "Unknown endian option '#{endian}'"
|
124
|
-
end
|
125
|
-
end
|
126
|
-
end
|
127
|
-
|
128
|
-
end
|
data/lib/chronic/dictionary.rb
DELETED
@@ -1,36 +0,0 @@
|
|
1
|
-
require 'chronic/definition'
|
2
|
-
|
3
|
-
module Chronic
|
4
|
-
# A collection of definitions
|
5
|
-
class Dictionary
|
6
|
-
attr_reader :defined_items, :options
|
7
|
-
|
8
|
-
def initialize(options = {})
|
9
|
-
@options = options
|
10
|
-
@defined_items = []
|
11
|
-
end
|
12
|
-
|
13
|
-
# returns a hash of each word's Definitions
|
14
|
-
def definitions
|
15
|
-
defined_items.each_with_object({}) do |word, defs|
|
16
|
-
word_type = "#{word.capitalize.to_s + 'Definitions'}"
|
17
|
-
defs[word] = Chronic.const_get(word_type).new(options).definitions
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
class SpanDictionary < Dictionary
|
23
|
-
# Collection of SpanDefinitions
|
24
|
-
def initialize(options = {})
|
25
|
-
super
|
26
|
-
@defined_items = [:time,:date,:anchor,:arrow,:narrow,:endian]
|
27
|
-
end
|
28
|
-
|
29
|
-
# returns the definitions of a specific subclass of SpanDefinitions
|
30
|
-
# SpanDefinition#definitions returns an Hash of Handler instances
|
31
|
-
# arguments should come in as symbols
|
32
|
-
def [](handler_type=:symbol)
|
33
|
-
definitions[handler_type]
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
@@ -1,59 +0,0 @@
|
|
1
|
-
module Chronic
|
2
|
-
class RepeaterQuarter < Repeater #:nodoc:
|
3
|
-
MONTHS_PER_QUARTER = 3
|
4
|
-
QUARTER_SECONDS = 7_776_000 # 3 * 30 * 24 * 60 * 60
|
5
|
-
|
6
|
-
def next(pointer)
|
7
|
-
@current_span ||= quarter(@now)
|
8
|
-
offset_quarter_amount = pointer == :future ? 1 : -1
|
9
|
-
@current_span = offset_quarter(@current_span.begin, offset_quarter_amount)
|
10
|
-
end
|
11
|
-
|
12
|
-
def this(*)
|
13
|
-
@current_span = quarter(@now)
|
14
|
-
end
|
15
|
-
|
16
|
-
def offset(span, amount, pointer)
|
17
|
-
direction = pointer == :future ? 1 : -1
|
18
|
-
offset_quarter(span.begin, amount * direction)
|
19
|
-
end
|
20
|
-
|
21
|
-
def width
|
22
|
-
@current_span ? @current_span.width : QUARTER_SECONDS
|
23
|
-
end
|
24
|
-
|
25
|
-
def to_s
|
26
|
-
super << '-quarter'
|
27
|
-
end
|
28
|
-
|
29
|
-
protected
|
30
|
-
|
31
|
-
def quarter_index(month)
|
32
|
-
(month - 1) / MONTHS_PER_QUARTER
|
33
|
-
end
|
34
|
-
|
35
|
-
def quarter(time)
|
36
|
-
year, month = time.year, time.month
|
37
|
-
|
38
|
-
quarter_index = quarter_index(month)
|
39
|
-
quarter_month_start = (quarter_index * MONTHS_PER_QUARTER) + 1
|
40
|
-
quarter_month_end = quarter_month_start + MONTHS_PER_QUARTER
|
41
|
-
|
42
|
-
quarter_start = Chronic.construct(year, quarter_month_start)
|
43
|
-
quarter_end = Chronic.construct(year, quarter_month_end)
|
44
|
-
|
45
|
-
Span.new(quarter_start, quarter_end)
|
46
|
-
end
|
47
|
-
|
48
|
-
def offset_quarter(time, amount)
|
49
|
-
new_month = time.month - 1
|
50
|
-
new_month = new_month + MONTHS_PER_QUARTER * amount
|
51
|
-
new_year = time.year + new_month / 12
|
52
|
-
new_month = new_month % 12 + 1
|
53
|
-
|
54
|
-
offset_time_basis = Chronic.construct(new_year, new_month)
|
55
|
-
|
56
|
-
quarter(offset_time_basis)
|
57
|
-
end
|
58
|
-
end
|
59
|
-
end
|
@@ -1,40 +0,0 @@
|
|
1
|
-
module Chronic
|
2
|
-
class RepeaterQuarterName < RepeaterQuarter #:nodoc:
|
3
|
-
QUARTERS = {
|
4
|
-
:q1 => 0,
|
5
|
-
:q2 => 1,
|
6
|
-
:q3 => 2,
|
7
|
-
:q4 => 3
|
8
|
-
}
|
9
|
-
|
10
|
-
def next(pointer)
|
11
|
-
unless @current_span
|
12
|
-
@current_span = this(pointer)
|
13
|
-
else
|
14
|
-
year_offset = pointer == :future ? 1 : -1
|
15
|
-
new_year = @current_span.begin.year + year_offset
|
16
|
-
time_basis = Chronic.construct(new_year, @current_span.begin.month)
|
17
|
-
@current_span = quarter(time_basis)
|
18
|
-
end
|
19
|
-
|
20
|
-
@current_span
|
21
|
-
end
|
22
|
-
|
23
|
-
def this(pointer = :future)
|
24
|
-
current_quarter_index = quarter_index(@now.month)
|
25
|
-
target_quarter_index = QUARTERS[type]
|
26
|
-
|
27
|
-
year_basis_offset = case pointer
|
28
|
-
when :past then current_quarter_index > target_quarter_index ? 0 : -1
|
29
|
-
when :future then current_quarter_index < target_quarter_index ? 0 : 1
|
30
|
-
else 0
|
31
|
-
end
|
32
|
-
|
33
|
-
year_basis = @now.year + year_basis_offset
|
34
|
-
month_basis = (MONTHS_PER_QUARTER * target_quarter_index) + 1
|
35
|
-
time_basis = Chronic.construct(year_basis, month_basis)
|
36
|
-
|
37
|
-
@current_span = quarter(time_basis)
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
@@ -1,123 +0,0 @@
|
|
1
|
-
module Chronic
|
2
|
-
class Separator < Tag
|
3
|
-
|
4
|
-
# Scan an Array of Token objects and apply any necessary Separator
|
5
|
-
# tags to each token.
|
6
|
-
#
|
7
|
-
# tokens - An Array of tokens to scan.
|
8
|
-
# options - The Hash of options specified in Chronic::parse.
|
9
|
-
#
|
10
|
-
# Returns an Array of tokens.
|
11
|
-
def self.scan(tokens, options)
|
12
|
-
tokens.each do |token|
|
13
|
-
token.tag scan_for(token, SeparatorComma, { ','.to_sym => :comma })
|
14
|
-
token.tag scan_for(token, SeparatorDot, { '.'.to_sym => :dot })
|
15
|
-
token.tag scan_for(token, SeparatorColon, { ':'.to_sym => :colon })
|
16
|
-
token.tag scan_for(token, SeparatorSpace, { ' '.to_sym => :space })
|
17
|
-
token.tag scan_for(token, SeparatorSlash, { '/'.to_sym => :slash })
|
18
|
-
token.tag scan_for(token, SeparatorDash, { :- => :dash })
|
19
|
-
token.tag scan_for(token, SeparatorAt, { /^(at|@)$/i => :at })
|
20
|
-
token.tag scan_for(token, SeparatorIn, { 'in' => :in })
|
21
|
-
token.tag scan_for(token, SeparatorOn, { 'on' => :on })
|
22
|
-
token.tag scan_for(token, SeparatorAnd, { 'and' => :and })
|
23
|
-
token.tag scan_for(token, SeparatorT, { :T => :T })
|
24
|
-
token.tag scan_for(token, SeparatorW, { :W => :W })
|
25
|
-
token.tag scan_for_quote(token)
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
# token - The Token object we want to scan.
|
30
|
-
#
|
31
|
-
# Returns a new SeparatorQuote object.
|
32
|
-
def self.scan_for_quote(token)
|
33
|
-
scan_for token, SeparatorQuote,
|
34
|
-
{
|
35
|
-
"'".to_sym => :single_quote,
|
36
|
-
'"'.to_sym => :double_quote
|
37
|
-
}
|
38
|
-
end
|
39
|
-
|
40
|
-
def to_s
|
41
|
-
'separator'
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
class SeparatorComma < Separator #:nodoc:
|
46
|
-
def to_s
|
47
|
-
super << '-comma'
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
class SeparatorDot < Separator #:nodoc:
|
52
|
-
def to_s
|
53
|
-
super << '-dot'
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
class SeparatorColon < Separator #:nodoc:
|
58
|
-
def to_s
|
59
|
-
super << '-colon'
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
class SeparatorSpace < Separator #:nodoc:
|
64
|
-
def to_s
|
65
|
-
super << '-space'
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
class SeparatorSlash < Separator #:nodoc:
|
70
|
-
def to_s
|
71
|
-
super << '-slash'
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
|
-
class SeparatorDash < Separator #:nodoc:
|
76
|
-
def to_s
|
77
|
-
super << '-dash'
|
78
|
-
end
|
79
|
-
end
|
80
|
-
|
81
|
-
class SeparatorQuote < Separator #:nodoc:
|
82
|
-
def to_s
|
83
|
-
super << '-quote-' << @type.to_s
|
84
|
-
end
|
85
|
-
end
|
86
|
-
|
87
|
-
class SeparatorAt < Separator #:nodoc:
|
88
|
-
def to_s
|
89
|
-
super << '-at'
|
90
|
-
end
|
91
|
-
end
|
92
|
-
|
93
|
-
class SeparatorIn < Separator #:nodoc:
|
94
|
-
def to_s
|
95
|
-
super << '-in'
|
96
|
-
end
|
97
|
-
end
|
98
|
-
|
99
|
-
class SeparatorOn < Separator #:nodoc:
|
100
|
-
def to_s
|
101
|
-
super << '-on'
|
102
|
-
end
|
103
|
-
end
|
104
|
-
|
105
|
-
class SeparatorAnd < Separator #:nodoc:
|
106
|
-
def to_s
|
107
|
-
super << '-and'
|
108
|
-
end
|
109
|
-
end
|
110
|
-
|
111
|
-
class SeparatorT < Separator #:nodoc:
|
112
|
-
def to_s
|
113
|
-
super << '-T'
|
114
|
-
end
|
115
|
-
end
|
116
|
-
|
117
|
-
class SeparatorW < Separator #:nodoc:
|
118
|
-
def to_s
|
119
|
-
super << '-W'
|
120
|
-
end
|
121
|
-
end
|
122
|
-
|
123
|
-
end
|