chronic 0.1.5 → 0.6.5
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/.gemtest +0 -0
- data/.gitignore +5 -0
- data/.yardopts +3 -0
- data/HISTORY.md +180 -0
- data/LICENSE +21 -0
- data/README.md +176 -0
- data/Rakefile +39 -32
- data/chronic.gemspec +17 -0
- data/lib/chronic/chronic.rb +294 -208
- data/lib/chronic/grabber.rb +22 -17
- data/lib/chronic/handler.rb +90 -0
- data/lib/chronic/handlers.rb +365 -278
- data/lib/chronic/mini_date.rb +38 -0
- data/lib/chronic/numerizer.rb +121 -0
- data/lib/chronic/ordinal.rb +23 -19
- data/lib/chronic/pointer.rb +20 -17
- data/lib/chronic/repeater.rb +126 -105
- data/lib/chronic/repeaters/repeater_day.rb +49 -43
- data/lib/chronic/repeaters/repeater_day_name.rb +48 -42
- data/lib/chronic/repeaters/repeater_day_portion.rb +81 -80
- data/lib/chronic/repeaters/repeater_fortnight.rb +59 -53
- data/lib/chronic/repeaters/repeater_hour.rb +49 -43
- data/lib/chronic/repeaters/repeater_minute.rb +55 -39
- data/lib/chronic/repeaters/repeater_month.rb +77 -55
- data/lib/chronic/repeaters/repeater_month_name.rb +83 -82
- data/lib/chronic/repeaters/repeater_season.rb +107 -21
- data/lib/chronic/repeaters/repeater_season_name.rb +41 -22
- data/lib/chronic/repeaters/repeater_second.rb +39 -33
- data/lib/chronic/repeaters/repeater_time.rb +117 -103
- data/lib/chronic/repeaters/repeater_week.rb +63 -57
- data/lib/chronic/repeaters/repeater_weekday.rb +85 -0
- data/lib/chronic/repeaters/repeater_weekend.rb +64 -9
- data/lib/chronic/repeaters/repeater_year.rb +70 -51
- data/lib/chronic/scalar.rb +64 -29
- data/lib/chronic/season.rb +37 -0
- data/lib/chronic/separator.rb +50 -38
- data/lib/chronic/span.rb +31 -0
- data/lib/chronic/tag.rb +42 -0
- data/lib/chronic/time_zone.rb +30 -0
- data/lib/chronic/token.rb +45 -0
- data/lib/chronic.rb +86 -22
- data/test/helper.rb +6 -0
- data/test/test_Chronic.rb +118 -20
- data/test/test_DaylightSavings.rb +118 -0
- data/test/test_Handler.rb +36 -42
- data/test/test_MiniDate.rb +32 -0
- data/test/test_Numerizer.rb +72 -0
- data/test/test_RepeaterDayName.rb +15 -16
- data/test/test_RepeaterFortnight.rb +16 -17
- data/test/test_RepeaterHour.rb +22 -19
- data/test/test_RepeaterMinute.rb +34 -0
- data/test/test_RepeaterMonth.rb +20 -17
- data/test/test_RepeaterMonthName.rb +17 -18
- data/test/test_RepeaterSeason.rb +40 -0
- data/test/test_RepeaterTime.rb +20 -22
- data/test/test_RepeaterWeek.rb +16 -17
- data/test/test_RepeaterWeekday.rb +55 -0
- data/test/test_RepeaterWeekend.rb +74 -0
- data/test/test_RepeaterYear.rb +24 -18
- data/test/test_Span.rb +5 -6
- data/test/test_Token.rb +5 -6
- data/test/test_parsing.rb +743 -338
- metadata +81 -54
- data/History.txt +0 -29
- data/Manifest.txt +0 -43
- data/README.txt +0 -149
- data/test/parse_numbers.rb +0 -50
- data/test/suite.rb +0 -9
|
@@ -1,46 +1,52 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
@
|
|
1
|
+
module Chronic
|
|
2
|
+
class RepeaterDayName < Repeater #:nodoc:
|
|
3
|
+
DAY_SECONDS = 86400 # (24 * 60 * 60)
|
|
4
|
+
|
|
5
|
+
def initialize(type)
|
|
6
|
+
super
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def next(pointer)
|
|
10
|
+
super
|
|
11
|
+
|
|
12
|
+
direction = pointer == :future ? 1 : -1
|
|
13
|
+
|
|
14
|
+
if !@current_date
|
|
15
|
+
@current_date = Date.new(@now.year, @now.month, @now.day)
|
|
16
|
+
@current_date += direction
|
|
17
|
+
|
|
18
|
+
day_num = symbol_to_number(@type)
|
|
19
|
+
|
|
20
|
+
while @current_date.wday != day_num
|
|
21
|
+
@current_date += direction
|
|
22
|
+
end
|
|
23
|
+
else
|
|
24
|
+
@current_date += direction * 7
|
|
17
25
|
end
|
|
18
|
-
|
|
19
|
-
@
|
|
26
|
+
next_date = @current_date.succ
|
|
27
|
+
Span.new(Chronic.construct(@current_date.year, @current_date.month, @current_date.day), Chronic.construct(next_date.year, next_date.month, next_date.day))
|
|
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")
|
|
20
50
|
end
|
|
21
|
-
|
|
22
|
-
Chronic::Span.new(@current_day_start, @current_day_start + DAY_SECONDS)
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
def this(pointer = :future)
|
|
26
|
-
super
|
|
27
|
-
|
|
28
|
-
pointer = :future if pointer == :none
|
|
29
|
-
self.next(pointer)
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
def width
|
|
33
|
-
DAY_SECONDS
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
def to_s
|
|
37
|
-
super << '-dayofweek-' << @type.to_s
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
private
|
|
41
|
-
|
|
42
|
-
def symbol_to_number(sym)
|
|
43
|
-
lookup = {:sunday => 0, :monday => 1, :tuesday => 2, :wednesday => 3, :thursday => 4, :friday => 5, :saturday => 6}
|
|
44
|
-
lookup[sym] || raise("Invalid symbol specified")
|
|
45
51
|
end
|
|
46
52
|
end
|
|
@@ -1,93 +1,94 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
1
|
+
module Chronic
|
|
2
|
+
class RepeaterDayPortion < Repeater #:nodoc:
|
|
3
|
+
PORTIONS = {
|
|
4
|
+
:am => 0..(12 * 60 * 60 - 1),
|
|
5
|
+
:pm => (12 * 60 * 60)..(24 * 60 * 60 - 1),
|
|
6
|
+
:morning => (6 * 60 * 60)..(12 * 60 * 60), # 6am-12am,
|
|
7
|
+
:afternoon => (13 * 60 * 60)..(17 * 60 * 60), # 1pm-5pm,
|
|
8
|
+
:evening => (17 * 60 * 60)..(20 * 60 * 60), # 5pm-8pm,
|
|
9
|
+
:night => (20 * 60 * 60)..(24 * 60 * 60), # 8pm-12pm
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
def initialize(type)
|
|
13
|
+
super
|
|
14
|
+
|
|
15
|
+
if type.kind_of? Integer
|
|
16
|
+
@range = (@type * 60 * 60)..((@type + 12) * 60 * 60)
|
|
17
|
+
else
|
|
18
|
+
@range = PORTIONS[type]
|
|
19
|
+
@range || raise("Invalid type '#{type}' for RepeaterDayPortion")
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
@range || raise("Range should have been set by now")
|
|
21
23
|
end
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
24
|
+
|
|
25
|
+
def next(pointer)
|
|
26
|
+
super
|
|
27
|
+
|
|
28
|
+
full_day = 60 * 60 * 24
|
|
29
|
+
|
|
30
|
+
if !@current_span
|
|
31
|
+
now_seconds = @now - Chronic.construct(@now.year, @now.month, @now.day)
|
|
32
|
+
if now_seconds < @range.begin
|
|
33
|
+
case pointer
|
|
34
|
+
when :future
|
|
35
|
+
range_start = Chronic.construct(@now.year, @now.month, @now.day) + @range.begin
|
|
36
|
+
when :past
|
|
37
|
+
range_start = Chronic.construct(@now.year, @now.month, @now.day) - full_day + @range.begin
|
|
38
|
+
end
|
|
39
|
+
elsif now_seconds > @range.end
|
|
40
|
+
case pointer
|
|
41
|
+
when :future
|
|
42
|
+
range_start = Chronic.construct(@now.year, @now.month, @now.day) + full_day + @range.begin
|
|
43
|
+
when :past
|
|
44
|
+
range_start = Chronic.construct(@now.year, @now.month, @now.day) + @range.begin
|
|
45
|
+
end
|
|
46
|
+
else
|
|
47
|
+
case pointer
|
|
48
|
+
when :future
|
|
49
|
+
range_start = Chronic.construct(@now.year, @now.month, @now.day) + full_day + @range.begin
|
|
50
|
+
when :past
|
|
51
|
+
range_start = Chronic.construct(@now.year, @now.month, @now.day) - full_day + @range.begin
|
|
52
|
+
end
|
|
45
53
|
end
|
|
54
|
+
|
|
55
|
+
@current_span = Span.new(range_start, range_start + (@range.end - @range.begin))
|
|
46
56
|
else
|
|
47
57
|
case pointer
|
|
48
58
|
when :future
|
|
49
|
-
|
|
59
|
+
@current_span += full_day
|
|
50
60
|
when :past
|
|
51
|
-
|
|
61
|
+
@current_span -= full_day
|
|
52
62
|
end
|
|
53
63
|
end
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
def this(context = :future)
|
|
67
|
+
super
|
|
68
|
+
|
|
69
|
+
range_start = Chronic.construct(@now.year, @now.month, @now.day) + @range.begin
|
|
70
|
+
@current_span = Span.new(range_start, range_start + (@range.end - @range.begin))
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
def offset(span, amount, pointer)
|
|
74
|
+
@now = span.begin
|
|
75
|
+
portion_span = self.next(pointer)
|
|
76
|
+
direction = pointer == :future ? 1 : -1
|
|
77
|
+
portion_span + (direction * (amount - 1) * RepeaterDay::DAY_SECONDS)
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
def width
|
|
81
|
+
@range || raise("Range has not been set")
|
|
82
|
+
return @current_span.width if @current_span
|
|
83
|
+
if @type.kind_of? Integer
|
|
84
|
+
return (12 * 60 * 60)
|
|
85
|
+
else
|
|
86
|
+
@range.end - @range.begin
|
|
62
87
|
end
|
|
63
88
|
end
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
super
|
|
68
|
-
|
|
69
|
-
range_start = Time.local(@now.year, @now.month, @now.day) + @range.begin
|
|
70
|
-
@current_span = Chronic::Span.new(range_start, range_start + (@range.end - @range.begin))
|
|
71
|
-
end
|
|
72
|
-
|
|
73
|
-
def offset(span, amount, pointer)
|
|
74
|
-
@now = span.begin
|
|
75
|
-
portion_span = self.next(pointer)
|
|
76
|
-
direction = pointer == :future ? 1 : -1
|
|
77
|
-
portion_span + (direction * (amount - 1) * Chronic::RepeaterDay::DAY_SECONDS)
|
|
78
|
-
end
|
|
79
|
-
|
|
80
|
-
def width
|
|
81
|
-
@range || raise("Range has not been set")
|
|
82
|
-
return @current_span.width if @current_span
|
|
83
|
-
if @type.kind_of? Integer
|
|
84
|
-
return (12 * 60 * 60)
|
|
85
|
-
else
|
|
86
|
-
@range.end - @range.begin
|
|
89
|
+
|
|
90
|
+
def to_s
|
|
91
|
+
super << '-dayportion-' << @type.to_s
|
|
87
92
|
end
|
|
88
93
|
end
|
|
89
|
-
|
|
90
|
-
def to_s
|
|
91
|
-
super << '-dayportion-' << @type.to_s
|
|
92
|
-
end
|
|
93
94
|
end
|
|
@@ -1,65 +1,71 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
module Chronic
|
|
2
|
+
class RepeaterFortnight < Repeater #:nodoc:
|
|
3
|
+
FORTNIGHT_SECONDS = 1_209_600 # (14 * 24 * 60 * 60)
|
|
4
|
+
|
|
5
|
+
def initialize(type)
|
|
6
|
+
super
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def next(pointer)
|
|
10
|
+
super
|
|
11
|
+
|
|
12
|
+
if !@current_fortnight_start
|
|
13
|
+
case pointer
|
|
14
|
+
when :future
|
|
15
|
+
sunday_repeater = 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 = RepeaterDayName.new(:sunday)
|
|
21
|
+
sunday_repeater.start = (@now + 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
|
+
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
|
+
|
|
8
39
|
case pointer
|
|
9
40
|
when :future
|
|
10
|
-
|
|
41
|
+
this_fortnight_start = Chronic.construct(@now.year, @now.month, @now.day, @now.hour) + RepeaterHour::HOUR_SECONDS
|
|
42
|
+
sunday_repeater = RepeaterDayName.new(:sunday)
|
|
11
43
|
sunday_repeater.start = @now
|
|
12
|
-
|
|
13
|
-
|
|
44
|
+
sunday_repeater.this(:future)
|
|
45
|
+
this_sunday_span = sunday_repeater.this(:future)
|
|
46
|
+
this_fortnight_end = this_sunday_span.begin
|
|
47
|
+
Span.new(this_fortnight_start, this_fortnight_end)
|
|
14
48
|
when :past
|
|
15
|
-
|
|
16
|
-
sunday_repeater
|
|
17
|
-
|
|
49
|
+
this_fortnight_end = Chronic.construct(@now.year, @now.month, @now.day, @now.hour)
|
|
50
|
+
sunday_repeater = RepeaterDayName.new(:sunday)
|
|
51
|
+
sunday_repeater.start = @now
|
|
18
52
|
last_sunday_span = sunday_repeater.next(:past)
|
|
19
|
-
|
|
53
|
+
this_fortnight_start = last_sunday_span.begin
|
|
54
|
+
Span.new(this_fortnight_start, this_fortnight_end)
|
|
20
55
|
end
|
|
21
|
-
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def offset(span, amount, pointer)
|
|
22
59
|
direction = pointer == :future ? 1 : -1
|
|
23
|
-
|
|
60
|
+
span + direction * amount * FORTNIGHT_SECONDS
|
|
24
61
|
end
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
def this(pointer = :future)
|
|
30
|
-
super
|
|
31
|
-
|
|
32
|
-
pointer = :future if pointer == :none
|
|
33
|
-
|
|
34
|
-
case pointer
|
|
35
|
-
when :future
|
|
36
|
-
this_fortnight_start = Time.local(@now.year, @now.month, @now.day, @now.hour) + Chronic::RepeaterHour::HOUR_SECONDS
|
|
37
|
-
sunday_repeater = Chronic::RepeaterDayName.new(:sunday)
|
|
38
|
-
sunday_repeater.start = @now
|
|
39
|
-
sunday_repeater.this(:future)
|
|
40
|
-
this_sunday_span = sunday_repeater.this(:future)
|
|
41
|
-
this_fortnight_end = this_sunday_span.begin
|
|
42
|
-
Chronic::Span.new(this_fortnight_start, this_fortnight_end)
|
|
43
|
-
when :past
|
|
44
|
-
this_fortnight_end = Time.local(@now.year, @now.month, @now.day, @now.hour)
|
|
45
|
-
sunday_repeater = Chronic::RepeaterDayName.new(:sunday)
|
|
46
|
-
sunday_repeater.start = @now
|
|
47
|
-
last_sunday_span = sunday_repeater.next(:past)
|
|
48
|
-
this_fortnight_start = last_sunday_span.begin
|
|
49
|
-
Chronic::Span.new(this_fortnight_start, this_fortnight_end)
|
|
62
|
+
|
|
63
|
+
def width
|
|
64
|
+
FORTNIGHT_SECONDS
|
|
50
65
|
end
|
|
51
|
-
end
|
|
52
|
-
|
|
53
|
-
def offset(span, amount, pointer)
|
|
54
|
-
direction = pointer == :future ? 1 : -1
|
|
55
|
-
span + direction * amount * FORTNIGHT_SECONDS
|
|
56
|
-
end
|
|
57
66
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
def to_s
|
|
63
|
-
super << '-fortnight'
|
|
67
|
+
def to_s
|
|
68
|
+
super << '-fortnight'
|
|
69
|
+
end
|
|
64
70
|
end
|
|
65
71
|
end
|
|
@@ -1,52 +1,58 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
module Chronic
|
|
2
|
+
class RepeaterHour < Repeater #:nodoc:
|
|
3
|
+
HOUR_SECONDS = 3600 # 60 * 60
|
|
4
|
+
|
|
5
|
+
def initialize(type)
|
|
6
|
+
super
|
|
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 = Chronic.construct(@now.year, @now.month, @now.day, @now.hour + 1)
|
|
16
|
+
when :past
|
|
17
|
+
@current_hour_start = Chronic.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
|
+
Span.new(@current_hour_start, @current_hour_start + HOUR_SECONDS)
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def this(pointer = :future)
|
|
28
|
+
super
|
|
29
|
+
|
|
8
30
|
case pointer
|
|
9
31
|
when :future
|
|
10
|
-
|
|
32
|
+
hour_start = Chronic.construct(@now.year, @now.month, @now.day, @now.hour, @now.min + 1)
|
|
33
|
+
hour_end = Chronic.construct(@now.year, @now.month, @now.day, @now.hour + 1)
|
|
11
34
|
when :past
|
|
12
|
-
|
|
35
|
+
hour_start = Chronic.construct(@now.year, @now.month, @now.day, @now.hour)
|
|
36
|
+
hour_end = Chronic.construct(@now.year, @now.month, @now.day, @now.hour, @now.min)
|
|
37
|
+
when :none
|
|
38
|
+
hour_start = Chronic.construct(@now.year, @now.month, @now.day, @now.hour)
|
|
39
|
+
hour_end = hour_start + HOUR_SECONDS
|
|
13
40
|
end
|
|
14
|
-
|
|
41
|
+
|
|
42
|
+
Span.new(hour_start, hour_end)
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def offset(span, amount, pointer)
|
|
15
46
|
direction = pointer == :future ? 1 : -1
|
|
16
|
-
|
|
47
|
+
span + direction * amount * HOUR_SECONDS
|
|
17
48
|
end
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
case pointer
|
|
26
|
-
when :future
|
|
27
|
-
hour_start = Time.local(@now.year, @now.month, @now.day, @now.hour, @now.min + 1)
|
|
28
|
-
hour_end = Time.local(@now.year, @now.month, @now.day, @now.hour + 1)
|
|
29
|
-
when :past
|
|
30
|
-
hour_start = Time.local(@now.year, @now.month, @now.day, @now.hour)
|
|
31
|
-
hour_end = Time.local(@now.year, @now.month, @now.day, @now.hour, @now.min)
|
|
32
|
-
when :none
|
|
33
|
-
hour_start = Time.local(@now.year, @now.month, @now.day, @now.hour)
|
|
34
|
-
hour_end = hour_begin + HOUR_SECONDS
|
|
49
|
+
|
|
50
|
+
def width
|
|
51
|
+
HOUR_SECONDS
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def to_s
|
|
55
|
+
super << '-hour'
|
|
35
56
|
end
|
|
36
|
-
|
|
37
|
-
Chronic::Span.new(hour_start, hour_end)
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
def offset(span, amount, pointer)
|
|
41
|
-
direction = pointer == :future ? 1 : -1
|
|
42
|
-
span + direction * amount * HOUR_SECONDS
|
|
43
|
-
end
|
|
44
|
-
|
|
45
|
-
def width
|
|
46
|
-
HOUR_SECONDS
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
def to_s
|
|
50
|
-
super << '-hour'
|
|
51
57
|
end
|
|
52
58
|
end
|
|
@@ -1,42 +1,58 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
1
|
+
module Chronic
|
|
2
|
+
class RepeaterMinute < Repeater #:nodoc:
|
|
3
|
+
MINUTE_SECONDS = 60
|
|
4
|
+
|
|
5
|
+
def initialize(type)
|
|
6
|
+
super
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def next(pointer = :future)
|
|
10
|
+
super
|
|
11
|
+
|
|
12
|
+
if !@current_minute_start
|
|
13
|
+
case pointer
|
|
14
|
+
when :future
|
|
15
|
+
@current_minute_start = Chronic.construct(@now.year, @now.month, @now.day, @now.hour, @now.min + 1)
|
|
16
|
+
when :past
|
|
17
|
+
@current_minute_start = Chronic.construct(@now.year, @now.month, @now.day, @now.hour, @now.min - 1)
|
|
18
|
+
end
|
|
19
|
+
else
|
|
20
|
+
direction = pointer == :future ? 1 : -1
|
|
21
|
+
@current_minute_start += direction * MINUTE_SECONDS
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
Span.new(@current_minute_start, @current_minute_start + MINUTE_SECONDS)
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def this(pointer = :future)
|
|
28
|
+
super
|
|
29
|
+
|
|
30
|
+
case pointer
|
|
31
|
+
when :future
|
|
32
|
+
minute_begin = @now
|
|
33
|
+
minute_end = Chronic.construct(@now.year, @now.month, @now.day, @now.hour, @now.min)
|
|
34
|
+
when :past
|
|
35
|
+
minute_begin = Chronic.construct(@now.year, @now.month, @now.day, @now.hour, @now.min)
|
|
36
|
+
minute_end = @now
|
|
37
|
+
when :none
|
|
38
|
+
minute_begin = Chronic.construct(@now.year, @now.month, @now.day, @now.hour, @now.min)
|
|
39
|
+
minute_end = Chronic.construct(@now.year, @now.month, @now.day, @now.hour, @now.min) + MINUTE_SECONDS
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
Span.new(minute_begin, minute_end)
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def offset(span, amount, pointer)
|
|
46
|
+
direction = pointer == :future ? 1 : -1
|
|
47
|
+
span + direction * amount * MINUTE_SECONDS
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def width
|
|
51
|
+
MINUTE_SECONDS
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def to_s
|
|
55
|
+
super << '-minute'
|
|
25
56
|
end
|
|
26
|
-
|
|
27
|
-
Chronic::Span.new(minute_begin, minute_end)
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
def offset(span, amount, pointer)
|
|
31
|
-
direction = pointer == :future ? 1 : -1
|
|
32
|
-
span + direction * amount * MINUTE_SECONDS
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
def width
|
|
36
|
-
MINUTE_SECONDS
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
def to_s
|
|
40
|
-
super << '-minute'
|
|
41
57
|
end
|
|
42
58
|
end
|