chronic 0.2.3 → 0.4.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 +103 -0
- data/LICENSE +21 -0
- data/Manifest.txt +16 -5
- data/README.md +171 -0
- data/Rakefile +136 -15
- data/benchmark/benchmark.rb +13 -0
- data/chronic.gemspec +82 -0
- data/lib/chronic/chronic.rb +65 -147
- data/lib/chronic/grabber.rb +13 -17
- data/lib/chronic/handlers.rb +216 -138
- data/lib/chronic/mini_date.rb +27 -0
- data/lib/chronic/numerizer.rb +120 -0
- data/lib/chronic/ordinal.rb +11 -16
- data/lib/chronic/pointer.rb +11 -13
- data/lib/chronic/repeater.rb +117 -106
- data/lib/chronic/repeaters/repeater_day.rb +50 -43
- data/lib/chronic/repeaters/repeater_day_name.rb +49 -42
- data/lib/chronic/repeaters/repeater_day_portion.rb +82 -80
- data/lib/chronic/repeaters/repeater_fortnight.rb +60 -53
- data/lib/chronic/repeaters/repeater_hour.rb +50 -43
- data/lib/chronic/repeaters/repeater_minute.rb +50 -43
- data/lib/chronic/repeaters/repeater_month.rb +63 -56
- data/lib/chronic/repeaters/repeater_month_name.rb +91 -82
- data/lib/chronic/repeaters/repeater_season.rb +125 -20
- data/lib/chronic/repeaters/repeater_season_name.rb +43 -22
- data/lib/chronic/repeaters/repeater_second.rb +40 -33
- data/lib/chronic/repeaters/repeater_time.rb +118 -106
- data/lib/chronic/repeaters/repeater_week.rb +64 -57
- data/lib/chronic/repeaters/repeater_weekday.rb +86 -0
- data/lib/chronic/repeaters/repeater_weekend.rb +58 -51
- data/lib/chronic/repeaters/repeater_year.rb +58 -50
- data/lib/chronic/scalar.rb +37 -27
- data/lib/chronic/separator.rb +34 -37
- data/lib/chronic/span.rb +31 -0
- data/lib/chronic/tag.rb +26 -0
- data/lib/chronic/time_zone.rb +9 -10
- data/lib/chronic/token.rb +35 -0
- data/lib/chronic.rb +34 -25
- data/test/helper.rb +6 -0
- data/test/test_Chronic.rb +22 -18
- data/test/test_DaylightSavings.rb +118 -0
- data/test/test_Handler.rb +37 -38
- data/test/test_Numerizer.rb +66 -42
- 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 +16 -17
- data/test/test_RepeaterMonthName.rb +17 -18
- 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 +21 -22
- data/test/test_RepeaterYear.rb +17 -18
- data/test/test_Span.rb +5 -6
- data/test/test_Time.rb +11 -12
- data/test/test_Token.rb +5 -6
- data/test/test_parsing.rb +395 -208
- metadata +68 -52
- data/History.txt +0 -53
- data/README.txt +0 -149
- data/lib/numerizer/numerizer.rb +0 -103
- data/test/suite.rb +0 -9
|
@@ -1,117 +1,129 @@
|
|
|
1
|
-
|
|
2
|
-
class
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
1
|
+
module Chronic
|
|
2
|
+
class RepeaterTime < Repeater #:nodoc:
|
|
3
|
+
class Tick #:nodoc:
|
|
4
|
+
attr_accessor :time
|
|
5
|
+
|
|
6
|
+
def initialize(time, ambiguous = false)
|
|
7
|
+
@time = time
|
|
8
|
+
@ambiguous = ambiguous
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def ambiguous?
|
|
12
|
+
@ambiguous
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def *(other)
|
|
16
|
+
Tick.new(@time * other, @ambiguous)
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def to_f
|
|
20
|
+
@time.to_f
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def to_s
|
|
24
|
+
@time.to_s + (@ambiguous ? '?' : '')
|
|
25
|
+
end
|
|
26
|
+
|
|
24
27
|
end
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
28
|
+
|
|
29
|
+
def initialize(time)
|
|
30
|
+
@current_time = nil
|
|
31
|
+
t = time.gsub(/\:/, '')
|
|
32
|
+
|
|
33
|
+
@type =
|
|
34
|
+
case t.size
|
|
35
|
+
when 1..2
|
|
36
|
+
hours = t.to_i
|
|
37
|
+
hours == 12 ? Tick.new(0 * 60 * 60, true) : Tick.new(hours * 60 * 60, true)
|
|
38
|
+
when 3
|
|
39
|
+
hours = t[0..0].to_i
|
|
40
|
+
ambiguous = hours > 1
|
|
41
|
+
Tick.new((hours * 60 * 60) + (t[1..2].to_i * 60), ambiguous)
|
|
42
|
+
when 4
|
|
43
|
+
ambiguous = time =~ /:/ && t[0..0].to_i != 0 && t[0..1].to_i <= 12
|
|
44
|
+
hours = t[0..1].to_i
|
|
45
|
+
hours == 12 ? Tick.new(0 * 60 * 60 + t[2..3].to_i * 60, ambiguous) : Tick.new(hours * 60 * 60 + t[2..3].to_i * 60, ambiguous)
|
|
46
|
+
when 5
|
|
47
|
+
Tick.new(t[0..0].to_i * 60 * 60 + t[1..2].to_i * 60 + t[3..4].to_i, true)
|
|
48
|
+
when 6
|
|
49
|
+
ambiguous = time =~ /:/ && t[0..0].to_i != 0 && t[0..1].to_i <= 12
|
|
50
|
+
hours = t[0..1].to_i
|
|
51
|
+
hours == 12 ? Tick.new(0 * 60 * 60 + t[2..3].to_i * 60 + t[4..5].to_i, ambiguous) : Tick.new(hours * 60 * 60 + t[2..3].to_i * 60 + t[4..5].to_i, ambiguous)
|
|
52
|
+
else
|
|
53
|
+
raise("Time cannot exceed six digits")
|
|
54
|
+
end
|
|
47
55
|
end
|
|
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
|
-
[midnight + half_day + @type, midnight + @type, yesterday_midnight + @type * 2].each do |t|
|
|
81
|
-
(@current_time = t; throw :done) if t <= @now
|
|
56
|
+
|
|
57
|
+
# Return the next past or future Span for the time that this Repeater represents
|
|
58
|
+
# pointer - Symbol representing which temporal direction to fetch the next day
|
|
59
|
+
# must be either :past or :future
|
|
60
|
+
def next(pointer)
|
|
61
|
+
super
|
|
62
|
+
|
|
63
|
+
half_day = 60 * 60 * 12
|
|
64
|
+
full_day = 60 * 60 * 24
|
|
65
|
+
|
|
66
|
+
first = false
|
|
67
|
+
|
|
68
|
+
unless @current_time
|
|
69
|
+
first = true
|
|
70
|
+
midnight = Chronic.time_class.local(@now.year, @now.month, @now.day)
|
|
71
|
+
|
|
72
|
+
yesterday_midnight = midnight - full_day
|
|
73
|
+
tomorrow_midnight = midnight + full_day
|
|
74
|
+
|
|
75
|
+
offset_fix = midnight.gmt_offset - tomorrow_midnight.gmt_offset
|
|
76
|
+
tomorrow_midnight += offset_fix
|
|
77
|
+
|
|
78
|
+
catch :done do
|
|
79
|
+
if pointer == :future
|
|
80
|
+
if @type.ambiguous?
|
|
81
|
+
[midnight + @type.time + offset_fix, midnight + half_day + @type.time + offset_fix, tomorrow_midnight + @type.time].each do |t|
|
|
82
|
+
(@current_time = t; throw :done) if t >= @now
|
|
83
|
+
end
|
|
84
|
+
else
|
|
85
|
+
[midnight + @type.time + offset_fix, tomorrow_midnight + @type.time].each do |t|
|
|
86
|
+
(@current_time = t; throw :done) if t >= @now
|
|
87
|
+
end
|
|
82
88
|
end
|
|
83
|
-
else
|
|
84
|
-
|
|
85
|
-
|
|
89
|
+
else # pointer == :past
|
|
90
|
+
if @type.ambiguous?
|
|
91
|
+
[midnight + half_day + @type.time + offset_fix, midnight + @type.time + offset_fix, yesterday_midnight + @type.time + half_day].each do |t|
|
|
92
|
+
(@current_time = t; throw :done) if t <= @now
|
|
93
|
+
end
|
|
94
|
+
else
|
|
95
|
+
[midnight + @type.time + offset_fix, yesterday_midnight + @type.time].each do |t|
|
|
96
|
+
(@current_time = t; throw :done) if t <= @now
|
|
97
|
+
end
|
|
86
98
|
end
|
|
87
99
|
end
|
|
88
100
|
end
|
|
101
|
+
|
|
102
|
+
@current_time || raise("Current time cannot be nil at this point")
|
|
89
103
|
end
|
|
90
|
-
|
|
91
|
-
|
|
104
|
+
|
|
105
|
+
unless first
|
|
106
|
+
increment = @type.ambiguous? ? half_day : full_day
|
|
107
|
+
@current_time += pointer == :future ? increment : -increment
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
Span.new(@current_time, @current_time + width)
|
|
92
111
|
end
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
112
|
+
|
|
113
|
+
def this(context = :future)
|
|
114
|
+
super
|
|
115
|
+
|
|
116
|
+
context = :future if context == :none
|
|
117
|
+
|
|
118
|
+
self.next(context)
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
def width
|
|
122
|
+
1
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
def to_s
|
|
126
|
+
super << '-time-' << @type.to_s
|
|
97
127
|
end
|
|
98
|
-
|
|
99
|
-
Chronic::Span.new(@current_time, @current_time + width)
|
|
100
|
-
end
|
|
101
|
-
|
|
102
|
-
def this(context = :future)
|
|
103
|
-
super
|
|
104
|
-
|
|
105
|
-
context = :future if context == :none
|
|
106
|
-
|
|
107
|
-
self.next(context)
|
|
108
|
-
end
|
|
109
|
-
|
|
110
|
-
def width
|
|
111
|
-
1
|
|
112
|
-
end
|
|
113
|
-
|
|
114
|
-
def to_s
|
|
115
|
-
super << '-time-' << @type.to_s
|
|
116
128
|
end
|
|
117
129
|
end
|
|
@@ -1,68 +1,75 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
module Chronic
|
|
2
|
+
class RepeaterWeek < Repeater #:nodoc:
|
|
3
|
+
WEEK_SECONDS = 604800 # (7 * 24 * 60 * 60)
|
|
4
|
+
|
|
5
|
+
def initialize(type)
|
|
6
|
+
super
|
|
7
|
+
@current_week_start = nil
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def next(pointer)
|
|
11
|
+
super
|
|
12
|
+
|
|
13
|
+
if !@current_week_start
|
|
14
|
+
case pointer
|
|
15
|
+
when :future
|
|
16
|
+
sunday_repeater = RepeaterDayName.new(:sunday)
|
|
17
|
+
sunday_repeater.start = @now
|
|
18
|
+
next_sunday_span = sunday_repeater.next(:future)
|
|
19
|
+
@current_week_start = next_sunday_span.begin
|
|
20
|
+
when :past
|
|
21
|
+
sunday_repeater = RepeaterDayName.new(:sunday)
|
|
22
|
+
sunday_repeater.start = (@now + RepeaterDay::DAY_SECONDS)
|
|
23
|
+
sunday_repeater.next(:past)
|
|
24
|
+
last_sunday_span = sunday_repeater.next(:past)
|
|
25
|
+
@current_week_start = last_sunday_span.begin
|
|
26
|
+
end
|
|
27
|
+
else
|
|
28
|
+
direction = pointer == :future ? 1 : -1
|
|
29
|
+
@current_week_start += direction * WEEK_SECONDS
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
Span.new(@current_week_start, @current_week_start + WEEK_SECONDS)
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def this(pointer = :future)
|
|
36
|
+
super
|
|
37
|
+
|
|
8
38
|
case pointer
|
|
9
39
|
when :future
|
|
10
|
-
|
|
40
|
+
this_week_start = Chronic.time_class.local(@now.year, @now.month, @now.day, @now.hour) + RepeaterHour::HOUR_SECONDS
|
|
41
|
+
sunday_repeater = RepeaterDayName.new(:sunday)
|
|
11
42
|
sunday_repeater.start = @now
|
|
12
|
-
|
|
13
|
-
|
|
43
|
+
this_sunday_span = sunday_repeater.this(:future)
|
|
44
|
+
this_week_end = this_sunday_span.begin
|
|
45
|
+
Span.new(this_week_start, this_week_end)
|
|
14
46
|
when :past
|
|
15
|
-
|
|
16
|
-
sunday_repeater
|
|
17
|
-
sunday_repeater.
|
|
47
|
+
this_week_end = Chronic.time_class.local(@now.year, @now.month, @now.day, @now.hour)
|
|
48
|
+
sunday_repeater = RepeaterDayName.new(:sunday)
|
|
49
|
+
sunday_repeater.start = @now
|
|
50
|
+
last_sunday_span = sunday_repeater.next(:past)
|
|
51
|
+
this_week_start = last_sunday_span.begin
|
|
52
|
+
Span.new(this_week_start, this_week_end)
|
|
53
|
+
when :none
|
|
54
|
+
sunday_repeater = RepeaterDayName.new(:sunday)
|
|
55
|
+
sunday_repeater.start = @now
|
|
18
56
|
last_sunday_span = sunday_repeater.next(:past)
|
|
19
|
-
|
|
57
|
+
this_week_start = last_sunday_span.begin
|
|
58
|
+
Span.new(this_week_start, this_week_start + WEEK_SECONDS)
|
|
20
59
|
end
|
|
21
|
-
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def offset(span, amount, pointer)
|
|
22
63
|
direction = pointer == :future ? 1 : -1
|
|
23
|
-
|
|
64
|
+
span + direction * amount * WEEK_SECONDS
|
|
24
65
|
end
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
case pointer
|
|
33
|
-
when :future
|
|
34
|
-
this_week_start = Time.local(@now.year, @now.month, @now.day, @now.hour) + Chronic::RepeaterHour::HOUR_SECONDS
|
|
35
|
-
sunday_repeater = Chronic::RepeaterDayName.new(:sunday)
|
|
36
|
-
sunday_repeater.start = @now
|
|
37
|
-
this_sunday_span = sunday_repeater.this(:future)
|
|
38
|
-
this_week_end = this_sunday_span.begin
|
|
39
|
-
Chronic::Span.new(this_week_start, this_week_end)
|
|
40
|
-
when :past
|
|
41
|
-
this_week_end = Time.local(@now.year, @now.month, @now.day, @now.hour)
|
|
42
|
-
sunday_repeater = Chronic::RepeaterDayName.new(:sunday)
|
|
43
|
-
sunday_repeater.start = @now
|
|
44
|
-
last_sunday_span = sunday_repeater.next(:past)
|
|
45
|
-
this_week_start = last_sunday_span.begin
|
|
46
|
-
Chronic::Span.new(this_week_start, this_week_end)
|
|
47
|
-
when :none
|
|
48
|
-
sunday_repeater = Chronic::RepeaterDayName.new(:sunday)
|
|
49
|
-
sunday_repeater.start = @now
|
|
50
|
-
last_sunday_span = sunday_repeater.next(:past)
|
|
51
|
-
this_week_start = last_sunday_span.begin
|
|
52
|
-
Chronic::Span.new(this_week_start, this_week_start + WEEK_SECONDS)
|
|
66
|
+
|
|
67
|
+
def width
|
|
68
|
+
WEEK_SECONDS
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
def to_s
|
|
72
|
+
super << '-week'
|
|
53
73
|
end
|
|
54
|
-
end
|
|
55
|
-
|
|
56
|
-
def offset(span, amount, pointer)
|
|
57
|
-
direction = pointer == :future ? 1 : -1
|
|
58
|
-
span + direction * amount * WEEK_SECONDS
|
|
59
|
-
end
|
|
60
|
-
|
|
61
|
-
def width
|
|
62
|
-
WEEK_SECONDS
|
|
63
|
-
end
|
|
64
|
-
|
|
65
|
-
def to_s
|
|
66
|
-
super << '-week'
|
|
67
74
|
end
|
|
68
75
|
end
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
module Chronic
|
|
2
|
+
class RepeaterWeekday < Repeater #:nodoc:
|
|
3
|
+
DAY_SECONDS = 86400 # (24 * 60 * 60)
|
|
4
|
+
DAYS = {
|
|
5
|
+
:sunday => 0,
|
|
6
|
+
:monday => 1,
|
|
7
|
+
:tuesday => 2,
|
|
8
|
+
:wednesday => 3,
|
|
9
|
+
:thursday => 4,
|
|
10
|
+
:friday => 5,
|
|
11
|
+
:saturday => 6
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
def initialize(type)
|
|
15
|
+
super
|
|
16
|
+
@current_weekday_start = nil
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def next(pointer)
|
|
20
|
+
super
|
|
21
|
+
|
|
22
|
+
direction = pointer == :future ? 1 : -1
|
|
23
|
+
|
|
24
|
+
if !@current_weekday_start
|
|
25
|
+
@current_weekday_start = Time.construct(@now.year, @now.month, @now.day)
|
|
26
|
+
@current_weekday_start += direction * DAY_SECONDS
|
|
27
|
+
|
|
28
|
+
until is_weekday?(@current_weekday_start.wday)
|
|
29
|
+
@current_weekday_start += direction * DAY_SECONDS
|
|
30
|
+
end
|
|
31
|
+
else
|
|
32
|
+
loop do
|
|
33
|
+
@current_weekday_start += direction * DAY_SECONDS
|
|
34
|
+
break if is_weekday?(@current_weekday_start.wday)
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
Span.new(@current_weekday_start, @current_weekday_start + DAY_SECONDS)
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def this(pointer = :future)
|
|
42
|
+
super
|
|
43
|
+
|
|
44
|
+
case pointer
|
|
45
|
+
when :past
|
|
46
|
+
self.next(:past)
|
|
47
|
+
when :future, :none
|
|
48
|
+
self.next(:future)
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def offset(span, amount, pointer)
|
|
53
|
+
direction = pointer == :future ? 1 : -1
|
|
54
|
+
|
|
55
|
+
num_weekdays_passed = 0; offset = 0
|
|
56
|
+
until num_weekdays_passed == amount
|
|
57
|
+
offset += direction * DAY_SECONDS
|
|
58
|
+
num_weekdays_passed += 1 if is_weekday?((span.begin+offset).wday)
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
span + offset
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
def width
|
|
65
|
+
DAY_SECONDS
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
def to_s
|
|
69
|
+
super << '-weekday'
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
private
|
|
73
|
+
|
|
74
|
+
def is_weekend?(day)
|
|
75
|
+
day == symbol_to_number(:saturday) || day == symbol_to_number(:sunday)
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
def is_weekday?(day)
|
|
79
|
+
!is_weekend?(day)
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
def symbol_to_number(sym)
|
|
83
|
+
DAYS[sym] || raise("Invalid symbol specified")
|
|
84
|
+
end
|
|
85
|
+
end
|
|
86
|
+
end
|
|
@@ -1,60 +1,67 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
module Chronic
|
|
2
|
+
class RepeaterWeekend < Repeater #:nodoc:
|
|
3
|
+
WEEKEND_SECONDS = 172_800 # (2 * 24 * 60 * 60)
|
|
4
|
+
|
|
5
|
+
def initialize(type)
|
|
6
|
+
super
|
|
7
|
+
@current_week_start = nil
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def next(pointer)
|
|
11
|
+
super
|
|
12
|
+
|
|
13
|
+
if !@current_week_start
|
|
14
|
+
case pointer
|
|
15
|
+
when :future
|
|
16
|
+
saturday_repeater = RepeaterDayName.new(:saturday)
|
|
17
|
+
saturday_repeater.start = @now
|
|
18
|
+
next_saturday_span = saturday_repeater.next(:future)
|
|
19
|
+
@current_week_start = next_saturday_span.begin
|
|
20
|
+
when :past
|
|
21
|
+
saturday_repeater = RepeaterDayName.new(:saturday)
|
|
22
|
+
saturday_repeater.start = (@now + RepeaterDay::DAY_SECONDS)
|
|
23
|
+
last_saturday_span = saturday_repeater.next(:past)
|
|
24
|
+
@current_week_start = last_saturday_span.begin
|
|
25
|
+
end
|
|
26
|
+
else
|
|
27
|
+
direction = pointer == :future ? 1 : -1
|
|
28
|
+
@current_week_start += direction * RepeaterWeek::WEEK_SECONDS
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
Span.new(@current_week_start, @current_week_start + WEEKEND_SECONDS)
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def this(pointer = :future)
|
|
35
|
+
super
|
|
36
|
+
|
|
8
37
|
case pointer
|
|
9
|
-
when :future
|
|
10
|
-
saturday_repeater =
|
|
38
|
+
when :future, :none
|
|
39
|
+
saturday_repeater = RepeaterDayName.new(:saturday)
|
|
11
40
|
saturday_repeater.start = @now
|
|
12
|
-
|
|
13
|
-
|
|
41
|
+
this_saturday_span = saturday_repeater.this(:future)
|
|
42
|
+
Span.new(this_saturday_span.begin, this_saturday_span.begin + WEEKEND_SECONDS)
|
|
14
43
|
when :past
|
|
15
|
-
saturday_repeater =
|
|
16
|
-
saturday_repeater.start =
|
|
17
|
-
last_saturday_span = saturday_repeater.
|
|
18
|
-
|
|
44
|
+
saturday_repeater = RepeaterDayName.new(:saturday)
|
|
45
|
+
saturday_repeater.start = @now
|
|
46
|
+
last_saturday_span = saturday_repeater.this(:past)
|
|
47
|
+
Span.new(last_saturday_span.begin, last_saturday_span.begin + WEEKEND_SECONDS)
|
|
19
48
|
end
|
|
20
|
-
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def offset(span, amount, pointer)
|
|
21
52
|
direction = pointer == :future ? 1 : -1
|
|
22
|
-
|
|
53
|
+
weekend = RepeaterWeekend.new(:weekend)
|
|
54
|
+
weekend.start = span.begin
|
|
55
|
+
start = weekend.next(pointer).begin + (amount - 1) * direction * RepeaterWeek::WEEK_SECONDS
|
|
56
|
+
Span.new(start, start + (span.end - span.begin))
|
|
23
57
|
end
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
case pointer
|
|
32
|
-
when :future, :none
|
|
33
|
-
saturday_repeater = Chronic::RepeaterDayName.new(:saturday)
|
|
34
|
-
saturday_repeater.start = @now
|
|
35
|
-
this_saturday_span = saturday_repeater.this(:future)
|
|
36
|
-
Chronic::Span.new(this_saturday_span.begin, this_saturday_span.begin + WEEKEND_SECONDS)
|
|
37
|
-
when :past
|
|
38
|
-
saturday_repeater = Chronic::RepeaterDayName.new(:saturday)
|
|
39
|
-
saturday_repeater.start = @now
|
|
40
|
-
last_saturday_span = saturday_repeater.this(:past)
|
|
41
|
-
Chronic::Span.new(last_saturday_span.begin, last_saturday_span.begin + WEEKEND_SECONDS)
|
|
58
|
+
|
|
59
|
+
def width
|
|
60
|
+
WEEKEND_SECONDS
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def to_s
|
|
64
|
+
super << '-weekend'
|
|
42
65
|
end
|
|
43
|
-
end
|
|
44
|
-
|
|
45
|
-
def offset(span, amount, pointer)
|
|
46
|
-
direction = pointer == :future ? 1 : -1
|
|
47
|
-
weekend = Chronic::RepeaterWeekend.new(:weekend)
|
|
48
|
-
weekend.start = span.begin
|
|
49
|
-
start = weekend.next(pointer).begin + (amount - 1) * direction * Chronic::RepeaterWeek::WEEK_SECONDS
|
|
50
|
-
Chronic::Span.new(start, start + (span.end - span.begin))
|
|
51
|
-
end
|
|
52
|
-
|
|
53
|
-
def width
|
|
54
|
-
WEEKEND_SECONDS
|
|
55
|
-
end
|
|
56
|
-
|
|
57
|
-
def to_s
|
|
58
|
-
super << '-weekend'
|
|
59
66
|
end
|
|
60
67
|
end
|