pangel-chronic 0.3.0.3 → 0.3.10
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/{README.rdoc → README.txt} +7 -22
- data/lib/chronic.rb +89 -12
- data/lib/chronic/chronic.rb +260 -301
- data/lib/chronic/grabber.rb +23 -23
- data/lib/chronic/handlers.rb +538 -557
- data/lib/chronic/ordinal.rb +36 -35
- data/lib/chronic/pointer.rb +24 -26
- data/lib/chronic/repeater.rb +128 -138
- data/lib/chronic/repeaters/repeater_day.rb +51 -51
- data/lib/chronic/repeaters/repeater_day_name.rb +50 -52
- data/lib/chronic/repeaters/repeater_day_portion.rb +93 -93
- data/lib/chronic/repeaters/repeater_fortnight.rb +66 -66
- data/lib/chronic/repeaters/repeater_hour.rb +56 -57
- data/lib/chronic/repeaters/repeater_minute.rb +56 -56
- data/lib/chronic/repeaters/repeater_month.rb +71 -62
- data/lib/chronic/repeaters/repeater_month_name.rb +95 -95
- data/lib/chronic/repeaters/repeater_season.rb +142 -142
- data/lib/chronic/repeaters/repeater_season_name.rb +42 -42
- data/lib/chronic/repeaters/repeater_second.rb +40 -40
- data/lib/chronic/repeaters/repeater_time.rb +124 -123
- data/lib/chronic/repeaters/repeater_week.rb +70 -70
- data/lib/chronic/repeaters/repeater_weekday.rb +76 -76
- data/lib/chronic/repeaters/repeater_weekend.rb +63 -63
- data/lib/chronic/repeaters/repeater_year.rb +63 -63
- data/lib/chronic/scalar.rb +89 -70
- data/lib/chronic/separator.rb +88 -88
- data/lib/chronic/time_zone.rb +23 -20
- data/lib/numerizer/numerizer.rb +93 -94
- data/test/suite.rb +2 -2
- data/test/test_Chronic.rb +47 -47
- data/test/test_Handler.rb +106 -106
- data/test/test_Numerizer.rb +47 -49
- data/test/test_RepeaterDayName.rb +48 -48
- data/test/test_RepeaterFortnight.rb +59 -59
- data/test/test_RepeaterHour.rb +61 -64
- data/test/test_RepeaterMonth.rb +43 -43
- data/test/test_RepeaterMonthName.rb +53 -53
- data/test/test_RepeaterTime.rb +68 -68
- data/test/test_RepeaterWeek.rb +59 -59
- data/test/test_RepeaterWeekday.rb +53 -53
- data/test/test_RepeaterWeekend.rb +71 -71
- data/test/test_RepeaterYear.rb +59 -59
- data/test/test_Span.rb +19 -28
- data/test/test_Time.rb +46 -46
- data/test/test_Token.rb +22 -22
- data/test/test_parsing.rb +726 -792
- metadata +6 -10
@@ -1,53 +1,51 @@
|
|
1
|
-
require 'date'
|
2
1
|
class Chronic::RepeaterDayName < Chronic::Repeater #:nodoc:
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
end
|
2
|
+
DAY_SECONDS = 86400 # (24 * 60 * 60)
|
3
|
+
|
4
|
+
def initialize(type)
|
5
|
+
super
|
6
|
+
@current_day_start = nil
|
7
|
+
end
|
8
|
+
|
9
|
+
def next(pointer)
|
10
|
+
super
|
11
|
+
|
12
|
+
direction = pointer == :future ? 1 : -1
|
13
|
+
|
14
|
+
if !@current_day_start
|
15
|
+
@current_day_start = Time.construct(@now.year, @now.month, @now.day)
|
16
|
+
@current_day_start += direction * DAY_SECONDS
|
17
|
+
|
18
|
+
day_num = symbol_to_number(@type)
|
19
|
+
|
20
|
+
while @current_day_start.wday != day_num
|
21
|
+
@current_day_start += direction * DAY_SECONDS
|
22
|
+
end
|
23
|
+
else
|
24
|
+
@current_day_start += direction * 7 * DAY_SECONDS
|
25
|
+
end
|
26
|
+
|
27
|
+
Chronic::Span.new(@current_day_start, @current_day_start + DAY_SECONDS)
|
28
|
+
end
|
29
|
+
|
30
|
+
def this(pointer = :future)
|
31
|
+
super
|
32
|
+
|
33
|
+
pointer = :future if pointer == :none
|
34
|
+
self.next(pointer)
|
35
|
+
end
|
36
|
+
|
37
|
+
def width
|
38
|
+
DAY_SECONDS
|
39
|
+
end
|
40
|
+
|
41
|
+
def to_s
|
42
|
+
super << '-dayname-' << @type.to_s
|
43
|
+
end
|
44
|
+
|
45
|
+
private
|
46
|
+
|
47
|
+
def symbol_to_number(sym)
|
48
|
+
lookup = {:sunday => 0, :monday => 1, :tuesday => 2, :wednesday => 3, :thursday => 4, :friday => 5, :saturday => 6}
|
49
|
+
lookup[sym] || raise("Invalid symbol specified")
|
50
|
+
end
|
51
|
+
end
|
@@ -1,94 +1,94 @@
|
|
1
1
|
class Chronic::RepeaterDayPortion < Chronic::Repeater #:nodoc:
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
end
|
2
|
+
@@morning = (6 * 60 * 60)..(12 * 60 * 60) # 6am-12am
|
3
|
+
@@afternoon = (13 * 60 * 60)..(17 * 60 * 60) # 1pm-5pm
|
4
|
+
@@evening = (17 * 60 * 60)..(20 * 60 * 60) # 5pm-8pm
|
5
|
+
@@night = (20 * 60 * 60)..(24 * 60 * 60) # 8pm-12pm
|
6
|
+
|
7
|
+
def initialize(type)
|
8
|
+
super
|
9
|
+
@current_span = nil
|
10
|
+
|
11
|
+
if type.kind_of? Integer
|
12
|
+
@range = (@type * 60 * 60)..((@type + 12) * 60 * 60)
|
13
|
+
else
|
14
|
+
lookup = {:am => 0..(12 * 60 * 60 - 1),
|
15
|
+
:pm => (12 * 60 * 60)..(24 * 60 * 60 - 1),
|
16
|
+
:morning => @@morning,
|
17
|
+
:afternoon => @@afternoon,
|
18
|
+
:evening => @@evening,
|
19
|
+
:night => @@night}
|
20
|
+
@range = lookup[type]
|
21
|
+
lookup[type] || raise("Invalid type '#{type}' for RepeaterDayPortion")
|
22
|
+
end
|
23
|
+
@range || raise("Range should have been set by now")
|
24
|
+
end
|
25
|
+
|
26
|
+
def next(pointer)
|
27
|
+
super
|
28
|
+
|
29
|
+
full_day = 60 * 60 * 24
|
30
|
+
|
31
|
+
if !@current_span
|
32
|
+
now_seconds = @now - Time.construct(@now.year, @now.month, @now.day)
|
33
|
+
if now_seconds < @range.begin
|
34
|
+
case pointer
|
35
|
+
when :future
|
36
|
+
range_start = Time.construct(@now.year, @now.month, @now.day) + @range.begin
|
37
|
+
when :past
|
38
|
+
range_start = Time.construct(@now.year, @now.month, @now.day) - full_day + @range.begin
|
39
|
+
end
|
40
|
+
elsif now_seconds > @range.end
|
41
|
+
case pointer
|
42
|
+
when :future
|
43
|
+
range_start = Time.construct(@now.year, @now.month, @now.day) + full_day + @range.begin
|
44
|
+
when :past
|
45
|
+
range_start = Time.construct(@now.year, @now.month, @now.day) + @range.begin
|
46
|
+
end
|
47
|
+
else
|
48
|
+
case pointer
|
49
|
+
when :future
|
50
|
+
range_start = Time.construct(@now.year, @now.month, @now.day) + full_day + @range.begin
|
51
|
+
when :past
|
52
|
+
range_start = Time.construct(@now.year, @now.month, @now.day) - full_day + @range.begin
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
@current_span = Chronic::Span.new(range_start, range_start + (@range.end - @range.begin))
|
57
|
+
else
|
58
|
+
case pointer
|
59
|
+
when :future
|
60
|
+
@current_span += full_day
|
61
|
+
when :past
|
62
|
+
@current_span -= full_day
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def this(context = :future)
|
68
|
+
super
|
69
|
+
|
70
|
+
range_start = Time.construct(@now.year, @now.month, @now.day) + @range.begin
|
71
|
+
@current_span = Chronic::Span.new(range_start, range_start + (@range.end - @range.begin))
|
72
|
+
end
|
73
|
+
|
74
|
+
def offset(span, amount, pointer)
|
75
|
+
@now = span.begin
|
76
|
+
portion_span = self.next(pointer)
|
77
|
+
direction = pointer == :future ? 1 : -1
|
78
|
+
portion_span + (direction * (amount - 1) * Chronic::RepeaterDay::DAY_SECONDS)
|
79
|
+
end
|
80
|
+
|
81
|
+
def width
|
82
|
+
@range || raise("Range has not been set")
|
83
|
+
return @current_span.width if @current_span
|
84
|
+
if @type.kind_of? Integer
|
85
|
+
return (12 * 60 * 60)
|
86
|
+
else
|
87
|
+
@range.end - @range.begin
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
def to_s
|
92
|
+
super << '-dayportion-' << @type.to_s
|
93
|
+
end
|
94
|
+
end
|
@@ -1,70 +1,70 @@
|
|
1
1
|
class Chronic::RepeaterFortnight < Chronic::Repeater #:nodoc:
|
2
|
-
|
2
|
+
FORTNIGHT_SECONDS = 1_209_600 # (14 * 24 * 60 * 60)
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
4
|
+
def initialize(type)
|
5
|
+
super
|
6
|
+
@current_fortnight_start = nil
|
7
|
+
end
|
8
8
|
|
9
|
-
|
10
|
-
|
9
|
+
def next(pointer)
|
10
|
+
super
|
11
|
+
|
12
|
+
if !@current_fortnight_start
|
13
|
+
case pointer
|
14
|
+
when :future
|
15
|
+
sunday_repeater = Chronic::RepeaterDayName.new(:sunday)
|
16
|
+
sunday_repeater.start = @now
|
17
|
+
next_sunday_span = sunday_repeater.next(:future)
|
18
|
+
@current_fortnight_start = next_sunday_span.begin
|
19
|
+
when :past
|
20
|
+
sunday_repeater = Chronic::RepeaterDayName.new(:sunday)
|
21
|
+
sunday_repeater.start = (@now + Chronic::RepeaterDay::DAY_SECONDS)
|
22
|
+
2.times { sunday_repeater.next(:past) }
|
23
|
+
last_sunday_span = sunday_repeater.next(:past)
|
24
|
+
@current_fortnight_start = last_sunday_span.begin
|
25
|
+
end
|
26
|
+
else
|
27
|
+
direction = pointer == :future ? 1 : -1
|
28
|
+
@current_fortnight_start += direction * FORTNIGHT_SECONDS
|
29
|
+
end
|
30
|
+
|
31
|
+
Chronic::Span.new(@current_fortnight_start, @current_fortnight_start + FORTNIGHT_SECONDS)
|
32
|
+
end
|
33
|
+
|
34
|
+
def this(pointer = :future)
|
35
|
+
super
|
36
|
+
|
37
|
+
pointer = :future if pointer == :none
|
38
|
+
|
39
|
+
case pointer
|
40
|
+
when :future
|
41
|
+
this_fortnight_start = Time.construct(@now.year, @now.month, @now.day, @now.hour) + Chronic::RepeaterHour::HOUR_SECONDS
|
42
|
+
sunday_repeater = Chronic::RepeaterDayName.new(:sunday)
|
43
|
+
sunday_repeater.start = @now
|
44
|
+
sunday_repeater.this(:future)
|
45
|
+
this_sunday_span = sunday_repeater.this(:future)
|
46
|
+
this_fortnight_end = this_sunday_span.begin
|
47
|
+
Chronic::Span.new(this_fortnight_start, this_fortnight_end)
|
48
|
+
when :past
|
49
|
+
this_fortnight_end = Time.construct(@now.year, @now.month, @now.day, @now.hour)
|
50
|
+
sunday_repeater = Chronic::RepeaterDayName.new(:sunday)
|
51
|
+
sunday_repeater.start = @now
|
52
|
+
last_sunday_span = sunday_repeater.next(:past)
|
53
|
+
this_fortnight_start = last_sunday_span.begin
|
54
|
+
Chronic::Span.new(this_fortnight_start, this_fortnight_end)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def offset(span, amount, pointer)
|
59
|
+
direction = pointer == :future ? 1 : -1
|
60
|
+
span + direction * amount * FORTNIGHT_SECONDS
|
61
|
+
end
|
11
62
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
sunday_repeater = Chronic::RepeaterDayName.new(:sunday)
|
21
|
-
sunday_repeater.start = (@now + Chronic::RepeaterDay::DAY_SECONDS)
|
22
|
-
2.times { sunday_repeater.next(:past) }
|
23
|
-
last_sunday_span = sunday_repeater.next(:past)
|
24
|
-
@current_fortnight_start = last_sunday_span.begin
|
25
|
-
end
|
26
|
-
else
|
27
|
-
direction = pointer == :future ? 1 : -1
|
28
|
-
@current_fortnight_start += direction * FORTNIGHT_SECONDS
|
29
|
-
end
|
30
|
-
|
31
|
-
Chronic::Span.new(@current_fortnight_start, @current_fortnight_start + FORTNIGHT_SECONDS)
|
32
|
-
end
|
33
|
-
|
34
|
-
def this(pointer = :future)
|
35
|
-
super
|
36
|
-
|
37
|
-
pointer = :future if pointer == :none
|
38
|
-
|
39
|
-
case pointer
|
40
|
-
when :future
|
41
|
-
this_fortnight_start = Time.construct(@now.year, @now.month, @now.day, @now.hour) + Chronic::RepeaterHour::HOUR_SECONDS
|
42
|
-
sunday_repeater = Chronic::RepeaterDayName.new(:sunday)
|
43
|
-
sunday_repeater.start = @now
|
44
|
-
sunday_repeater.this(:future)
|
45
|
-
this_sunday_span = sunday_repeater.this(:future)
|
46
|
-
this_fortnight_end = this_sunday_span.begin
|
47
|
-
Chronic::Span.new(this_fortnight_start, this_fortnight_end)
|
48
|
-
when :past
|
49
|
-
this_fortnight_end = Time.construct(@now.year, @now.month, @now.day, @now.hour)
|
50
|
-
sunday_repeater = Chronic::RepeaterDayName.new(:sunday)
|
51
|
-
sunday_repeater.start = @now
|
52
|
-
last_sunday_span = sunday_repeater.next(:past)
|
53
|
-
this_fortnight_start = last_sunday_span.begin
|
54
|
-
Chronic::Span.new(this_fortnight_start, this_fortnight_end)
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
def offset(span, amount, pointer)
|
59
|
-
direction = pointer == :future ? 1 : -1
|
60
|
-
span + direction * amount * FORTNIGHT_SECONDS
|
61
|
-
end
|
62
|
-
|
63
|
-
def width
|
64
|
-
FORTNIGHT_SECONDS
|
65
|
-
end
|
66
|
-
|
67
|
-
def to_s
|
68
|
-
super << '-fortnight'
|
69
|
-
end
|
70
|
-
end
|
63
|
+
def width
|
64
|
+
FORTNIGHT_SECONDS
|
65
|
+
end
|
66
|
+
|
67
|
+
def to_s
|
68
|
+
super << '-fortnight'
|
69
|
+
end
|
70
|
+
end
|
@@ -1,58 +1,57 @@
|
|
1
1
|
class Chronic::RepeaterHour < Chronic::Repeater #:nodoc:
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
end
|
2
|
+
HOUR_SECONDS = 3600 # 60 * 60
|
3
|
+
|
4
|
+
def initialize(type)
|
5
|
+
super
|
6
|
+
@current_hour_start = nil
|
7
|
+
end
|
8
|
+
|
9
|
+
def next(pointer)
|
10
|
+
super
|
11
|
+
|
12
|
+
if !@current_hour_start
|
13
|
+
case pointer
|
14
|
+
when :future
|
15
|
+
@current_hour_start = Time.construct(@now.year, @now.month, @now.day, @now.hour + 1)
|
16
|
+
when :past
|
17
|
+
@current_hour_start = Time.construct(@now.year, @now.month, @now.day, @now.hour - 1)
|
18
|
+
end
|
19
|
+
else
|
20
|
+
direction = pointer == :future ? 1 : -1
|
21
|
+
@current_hour_start += direction * HOUR_SECONDS
|
22
|
+
end
|
23
|
+
|
24
|
+
Chronic::Span.new(@current_hour_start, @current_hour_start + HOUR_SECONDS)
|
25
|
+
end
|
26
|
+
|
27
|
+
def this(pointer = :future)
|
28
|
+
super
|
29
|
+
|
30
|
+
case pointer
|
31
|
+
when :future
|
32
|
+
hour_start = Time.construct(@now.year, @now.month, @now.day, @now.hour, @now.min + 1)
|
33
|
+
hour_end = Time.construct(@now.year, @now.month, @now.day, @now.hour + 1)
|
34
|
+
when :past
|
35
|
+
hour_start = Time.construct(@now.year, @now.month, @now.day, @now.hour)
|
36
|
+
hour_end = Time.construct(@now.year, @now.month, @now.day, @now.hour, @now.min)
|
37
|
+
when :none
|
38
|
+
hour_start = Time.construct(@now.year, @now.month, @now.day, @now.hour)
|
39
|
+
hour_end = hour_begin + HOUR_SECONDS
|
40
|
+
end
|
41
|
+
|
42
|
+
Chronic::Span.new(hour_start, hour_end)
|
43
|
+
end
|
44
|
+
|
45
|
+
def offset(span, amount, pointer)
|
46
|
+
direction = pointer == :future ? 1 : -1
|
47
|
+
span + direction * amount * HOUR_SECONDS
|
48
|
+
end
|
49
|
+
|
50
|
+
def width
|
51
|
+
HOUR_SECONDS
|
52
|
+
end
|
53
|
+
|
54
|
+
def to_s
|
55
|
+
super << '-hour'
|
56
|
+
end
|
57
|
+
end
|