chronic 0.2.2 → 0.10.2
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.
- checksums.yaml +7 -0
- data/.gitignore +6 -0
- data/.travis.yml +8 -0
- data/HISTORY.md +243 -0
- data/LICENSE +21 -0
- data/README.md +182 -0
- data/Rakefile +62 -15
- data/chronic.gemspec +23 -0
- data/lib/chronic/date.rb +82 -0
- data/lib/chronic/grabber.rb +24 -17
- data/lib/chronic/handler.rb +97 -0
- data/lib/chronic/handlers.rb +490 -312
- data/lib/chronic/mini_date.rb +38 -0
- data/lib/chronic/numerizer.rb +130 -0
- data/lib/chronic/ordinal.rb +33 -24
- data/lib/chronic/parser.rb +268 -0
- data/lib/chronic/pointer.rb +22 -17
- data/lib/chronic/repeater.rb +137 -107
- data/lib/chronic/repeaters/repeater_day.rb +51 -44
- data/lib/chronic/repeaters/repeater_day_name.rb +50 -43
- data/lib/chronic/repeaters/repeater_day_portion.rb +97 -81
- data/lib/chronic/repeaters/repeater_fortnight.rb +61 -54
- data/lib/chronic/repeaters/repeater_hour.rb +51 -44
- data/lib/chronic/repeaters/repeater_minute.rb +51 -44
- data/lib/chronic/repeaters/repeater_month.rb +79 -60
- data/lib/chronic/repeaters/repeater_month_name.rb +85 -83
- data/lib/chronic/repeaters/repeater_season.rb +110 -22
- data/lib/chronic/repeaters/repeater_season_name.rb +41 -22
- data/lib/chronic/repeaters/repeater_second.rb +41 -34
- data/lib/chronic/repeaters/repeater_time.rb +128 -104
- data/lib/chronic/repeaters/repeater_week.rb +65 -58
- data/lib/chronic/repeaters/repeater_weekday.rb +86 -0
- data/lib/chronic/repeaters/repeater_weekend.rb +59 -52
- data/lib/chronic/repeaters/repeater_year.rb +72 -52
- data/lib/chronic/scalar.rb +53 -46
- data/lib/chronic/season.rb +26 -0
- data/lib/chronic/separator.rb +174 -43
- data/lib/chronic/sign.rb +49 -0
- data/lib/chronic/span.rb +31 -0
- data/lib/chronic/tag.rb +37 -0
- data/lib/chronic/time.rb +40 -0
- data/lib/chronic/time_zone.rb +21 -11
- data/lib/chronic/token.rb +51 -0
- data/lib/chronic.rb +94 -69
- data/test/helper.rb +12 -0
- data/test/test_chronic.rb +183 -0
- data/test/test_daylight_savings.rb +118 -0
- data/test/{test_Handler.rb → test_handler.rb} +73 -55
- data/test/test_mini_date.rb +32 -0
- data/test/test_numerizer.rb +86 -0
- data/test/test_parsing.rb +891 -248
- data/test/{test_RepeaterDayName.rb → test_repeater_day_name.rb} +16 -17
- data/test/test_repeater_day_portion.rb +254 -0
- data/test/{test_RepeaterFortnight.rb → test_repeater_fortnight.rb} +17 -18
- data/test/{test_RepeaterHour.rb → test_repeater_hour.rb} +23 -20
- data/test/test_repeater_minute.rb +34 -0
- data/test/{test_RepeaterMonth.rb → test_repeater_month.rb} +21 -18
- data/test/{test_RepeaterMonthName.rb → test_repeater_month_name.rb} +18 -19
- data/test/test_repeater_season.rb +40 -0
- data/test/{test_RepeaterTime.rb → test_repeater_time.rb} +39 -23
- data/test/{test_RepeaterWeek.rb → test_repeater_week.rb} +17 -18
- data/test/test_repeater_weekday.rb +55 -0
- data/test/{test_RepeaterWeekend.rb → test_repeater_weekend.rb} +22 -23
- data/test/{test_RepeaterYear.rb → test_repeater_year.rb} +25 -19
- data/test/{test_Span.rb → test_span.rb} +7 -8
- data/test/{test_Token.rb → test_token.rb} +6 -7
- metadata +163 -85
- data/History.txt +0 -49
- data/Manifest.txt +0 -47
- data/README.txt +0 -149
- data/lib/chronic/chronic.rb +0 -239
- data/lib/numerizer/numerizer.rb +0 -103
- data/test/suite.rb +0 -9
- data/test/test_Chronic.rb +0 -50
- data/test/test_Numerizer.rb +0 -48
- data/test/test_Time.rb +0 -50
|
@@ -1,23 +1,111 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
module Chronic
|
|
2
|
+
class RepeaterSeason < Repeater #:nodoc:
|
|
3
|
+
SEASON_SECONDS = 7_862_400 # 91 * 24 * 60 * 60
|
|
4
|
+
SEASONS = {
|
|
5
|
+
:spring => Season.new(MiniDate.new(3,20), MiniDate.new(6,20)),
|
|
6
|
+
:summer => Season.new(MiniDate.new(6,21), MiniDate.new(9,22)),
|
|
7
|
+
:autumn => Season.new(MiniDate.new(9,23), MiniDate.new(12,21)),
|
|
8
|
+
:winter => Season.new(MiniDate.new(12,22), MiniDate.new(3,19))
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
def initialize(type, options = {})
|
|
12
|
+
super
|
|
13
|
+
@next_season_start = nil
|
|
14
|
+
@next_season_end = nil
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def next(pointer)
|
|
18
|
+
super
|
|
19
|
+
|
|
20
|
+
direction = pointer == :future ? 1 : -1
|
|
21
|
+
next_season = Season.find_next_season(find_current_season(MiniDate.from_time(@now)), direction)
|
|
22
|
+
|
|
23
|
+
find_next_season_span(direction, next_season)
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def this(pointer = :future)
|
|
27
|
+
super
|
|
28
|
+
|
|
29
|
+
direction = pointer == :future ? 1 : -1
|
|
30
|
+
|
|
31
|
+
today = Chronic.construct(@now.year, @now.month, @now.day)
|
|
32
|
+
this_ssn = find_current_season(MiniDate.from_time(@now))
|
|
33
|
+
case pointer
|
|
34
|
+
when :past
|
|
35
|
+
this_ssn_start = today + direction * num_seconds_til_start(this_ssn, direction)
|
|
36
|
+
this_ssn_end = today
|
|
37
|
+
when :future
|
|
38
|
+
this_ssn_start = today + RepeaterDay::DAY_SECONDS
|
|
39
|
+
this_ssn_end = today + direction * num_seconds_til_end(this_ssn, direction)
|
|
40
|
+
when :none
|
|
41
|
+
this_ssn_start = today + direction * num_seconds_til_start(this_ssn, direction)
|
|
42
|
+
this_ssn_end = today + direction * num_seconds_til_end(this_ssn, direction)
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
construct_season(this_ssn_start, this_ssn_end)
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def offset(span, amount, pointer)
|
|
49
|
+
Span.new(offset_by(span.begin, amount, pointer), offset_by(span.end, amount, pointer))
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def offset_by(time, amount, pointer)
|
|
53
|
+
direction = pointer == :future ? 1 : -1
|
|
54
|
+
time + amount * direction * SEASON_SECONDS
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def width
|
|
58
|
+
SEASON_SECONDS
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
def to_s
|
|
62
|
+
super << '-season'
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
private
|
|
66
|
+
|
|
67
|
+
def find_next_season_span(direction, next_season)
|
|
68
|
+
unless @next_season_start || @next_season_end
|
|
69
|
+
@next_season_start = Chronic.construct(@now.year, @now.month, @now.day)
|
|
70
|
+
@next_season_end = Chronic.construct(@now.year, @now.month, @now.day)
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
@next_season_start += direction * num_seconds_til_start(next_season, direction)
|
|
74
|
+
@next_season_end += direction * num_seconds_til_end(next_season, direction)
|
|
75
|
+
|
|
76
|
+
construct_season(@next_season_start, @next_season_end)
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
def find_current_season(md)
|
|
80
|
+
[:spring, :summer, :autumn, :winter].find do |season|
|
|
81
|
+
md.is_between?(SEASONS[season].start, SEASONS[season].end)
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
def num_seconds_til(goal, direction)
|
|
86
|
+
start = Chronic.construct(@now.year, @now.month, @now.day)
|
|
87
|
+
seconds = 0
|
|
88
|
+
|
|
89
|
+
until MiniDate.from_time(start + direction * seconds).equals?(goal)
|
|
90
|
+
seconds += RepeaterDay::DAY_SECONDS
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
seconds
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
def num_seconds_til_start(season_symbol, direction)
|
|
97
|
+
num_seconds_til(SEASONS[season_symbol].start, direction)
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
def num_seconds_til_end(season_symbol, direction)
|
|
101
|
+
num_seconds_til(SEASONS[season_symbol].end, direction)
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
def construct_season(start, finish)
|
|
105
|
+
Span.new(
|
|
106
|
+
Chronic.construct(start.year, start.month, start.day),
|
|
107
|
+
Chronic.construct(finish.year, finish.month, finish.day)
|
|
108
|
+
)
|
|
109
|
+
end
|
|
8
110
|
end
|
|
9
|
-
|
|
10
|
-
def this(pointer = :future)
|
|
11
|
-
super
|
|
12
|
-
|
|
13
|
-
raise 'Not implemented'
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
def width
|
|
17
|
-
SEASON_SECONDS
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
def to_s
|
|
21
|
-
super << '-season'
|
|
22
|
-
end
|
|
23
|
-
end
|
|
111
|
+
end
|
|
@@ -1,24 +1,43 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
1
|
+
module Chronic
|
|
2
|
+
class RepeaterSeasonName < RepeaterSeason #:nodoc:
|
|
3
|
+
SEASON_SECONDS = 7_862_400 # 91 * 24 * 60 * 60
|
|
4
|
+
DAY_SECONDS = 86_400 # (24 * 60 * 60)
|
|
5
|
+
|
|
6
|
+
def next(pointer)
|
|
7
|
+
direction = pointer == :future ? 1 : -1
|
|
8
|
+
find_next_season_span(direction, @type)
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def this(pointer = :future)
|
|
12
|
+
direction = pointer == :future ? 1 : -1
|
|
13
|
+
|
|
14
|
+
today = Chronic.construct(@now.year, @now.month, @now.day)
|
|
15
|
+
goal_ssn_start = today + direction * num_seconds_til_start(@type, direction)
|
|
16
|
+
goal_ssn_end = today + direction * num_seconds_til_end(@type, direction)
|
|
17
|
+
curr_ssn = find_current_season(MiniDate.from_time(@now))
|
|
18
|
+
case pointer
|
|
19
|
+
when :past
|
|
20
|
+
this_ssn_start = goal_ssn_start
|
|
21
|
+
this_ssn_end = (curr_ssn == @type) ? today : goal_ssn_end
|
|
22
|
+
when :future
|
|
23
|
+
this_ssn_start = (curr_ssn == @type) ? today + RepeaterDay::DAY_SECONDS : goal_ssn_start
|
|
24
|
+
this_ssn_end = goal_ssn_end
|
|
25
|
+
when :none
|
|
26
|
+
this_ssn_start = goal_ssn_start
|
|
27
|
+
this_ssn_end = goal_ssn_end
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
construct_season(this_ssn_start, this_ssn_end)
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def offset(span, amount, pointer)
|
|
34
|
+
Span.new(offset_by(span.begin, amount, pointer), offset_by(span.end, amount, pointer))
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def offset_by(time, amount, pointer)
|
|
38
|
+
direction = pointer == :future ? 1 : -1
|
|
39
|
+
time + amount * direction * RepeaterYear::YEAR_SECONDS
|
|
40
|
+
end
|
|
41
|
+
|
|
23
42
|
end
|
|
24
43
|
end
|
|
@@ -1,36 +1,43 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
1
|
+
module Chronic
|
|
2
|
+
class RepeaterSecond < Repeater #:nodoc:
|
|
3
|
+
SECOND_SECONDS = 1 # haha, awesome
|
|
4
|
+
|
|
5
|
+
def initialize(type, options = {})
|
|
6
|
+
super
|
|
7
|
+
@second_start = nil
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def next(pointer = :future)
|
|
11
|
+
super
|
|
12
|
+
|
|
13
|
+
direction = pointer == :future ? 1 : -1
|
|
14
|
+
|
|
15
|
+
unless @second_start
|
|
16
|
+
@second_start = @now + (direction * SECOND_SECONDS)
|
|
17
|
+
else
|
|
18
|
+
@second_start += SECOND_SECONDS * direction
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
Span.new(@second_start, @second_start + SECOND_SECONDS)
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def this(pointer = :future)
|
|
25
|
+
super
|
|
26
|
+
|
|
27
|
+
Span.new(@now, @now + 1)
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def offset(span, amount, pointer)
|
|
31
|
+
direction = pointer == :future ? 1 : -1
|
|
32
|
+
span + direction * amount * SECOND_SECONDS
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def width
|
|
36
|
+
SECOND_SECONDS
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def to_s
|
|
40
|
+
super << '-second'
|
|
13
41
|
end
|
|
14
|
-
|
|
15
|
-
Chronic::Span.new(@second_start, @second_start + SECOND_SECONDS)
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
def this(pointer = :future)
|
|
19
|
-
super
|
|
20
|
-
|
|
21
|
-
Chronic::Span.new(@now, @now + 1)
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
def offset(span, amount, pointer)
|
|
25
|
-
direction = pointer == :future ? 1 : -1
|
|
26
|
-
span + direction * amount * SECOND_SECONDS
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
def width
|
|
30
|
-
SECOND_SECONDS
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
def to_s
|
|
34
|
-
super << '-second'
|
|
35
42
|
end
|
|
36
|
-
end
|
|
43
|
+
end
|
|
@@ -1,114 +1,138 @@
|
|
|
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
|
-
|
|
28
|
+
|
|
29
|
+
def initialize(time, options = {})
|
|
30
|
+
@current_time = nil
|
|
31
|
+
@options = options
|
|
32
|
+
time_parts = time.split(':')
|
|
33
|
+
raise ArgumentError, "Time cannot have more than 4 groups of ':'" if time_parts.count > 4
|
|
34
|
+
|
|
35
|
+
if time_parts.first.length > 2 and time_parts.count == 1
|
|
36
|
+
if time_parts.first.length > 4
|
|
37
|
+
second_index = time_parts.first.length - 2
|
|
38
|
+
time_parts.insert(1, time_parts.first[second_index..time_parts.first.length])
|
|
39
|
+
time_parts[0] = time_parts.first[0..second_index - 1]
|
|
40
|
+
end
|
|
41
|
+
minute_index = time_parts.first.length - 2
|
|
42
|
+
time_parts.insert(1, time_parts.first[minute_index..time_parts.first.length])
|
|
43
|
+
time_parts[0] = time_parts.first[0..minute_index - 1]
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
ambiguous = false
|
|
47
|
+
hours = time_parts.first.to_i
|
|
48
|
+
|
|
49
|
+
if @options[:hours24].nil? or (not @options[:hours24].nil? and @options[:hours24] != true)
|
|
50
|
+
ambiguous = true if (time_parts.first.length == 1 and hours > 0) or (hours >= 10 and hours <= 12) or (@options[:hours24] == false and hours > 0)
|
|
51
|
+
hours = 0 if hours == 12 and ambiguous
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
hours *= 60 * 60
|
|
55
|
+
minutes = 0
|
|
56
|
+
seconds = 0
|
|
57
|
+
subseconds = 0
|
|
58
|
+
|
|
59
|
+
minutes = time_parts[1].to_i * 60 if time_parts.count > 1
|
|
60
|
+
seconds = time_parts[2].to_i if time_parts.count > 2
|
|
61
|
+
subseconds = time_parts[3].to_f / (10 ** time_parts[3].length) if time_parts.count > 3
|
|
62
|
+
|
|
63
|
+
@type = Tick.new(hours + minutes + seconds + subseconds, ambiguous)
|
|
44
64
|
end
|
|
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
|
-
[midnight + half_day + @type, midnight + @type, yesterday_midnight + @type * 2].each do |t|
|
|
78
|
-
(@current_time = t; throw :done) if t < @now
|
|
65
|
+
|
|
66
|
+
# Return the next past or future Span for the time that this Repeater represents
|
|
67
|
+
# pointer - Symbol representing which temporal direction to fetch the next day
|
|
68
|
+
# must be either :past or :future
|
|
69
|
+
def next(pointer)
|
|
70
|
+
super
|
|
71
|
+
|
|
72
|
+
half_day = 60 * 60 * 12
|
|
73
|
+
full_day = 60 * 60 * 24
|
|
74
|
+
|
|
75
|
+
first = false
|
|
76
|
+
|
|
77
|
+
unless @current_time
|
|
78
|
+
first = true
|
|
79
|
+
midnight = Chronic.time_class.local(@now.year, @now.month, @now.day)
|
|
80
|
+
|
|
81
|
+
yesterday_midnight = midnight - full_day
|
|
82
|
+
tomorrow_midnight = midnight + full_day
|
|
83
|
+
|
|
84
|
+
offset_fix = midnight.gmt_offset - tomorrow_midnight.gmt_offset
|
|
85
|
+
tomorrow_midnight += offset_fix
|
|
86
|
+
|
|
87
|
+
catch :done do
|
|
88
|
+
if pointer == :future
|
|
89
|
+
if @type.ambiguous?
|
|
90
|
+
[midnight + @type.time + offset_fix, midnight + half_day + @type.time + offset_fix, tomorrow_midnight + @type.time].each do |t|
|
|
91
|
+
(@current_time = t; throw :done) if t >= @now
|
|
92
|
+
end
|
|
93
|
+
else
|
|
94
|
+
[midnight + @type.time + offset_fix, tomorrow_midnight + @type.time].each do |t|
|
|
95
|
+
(@current_time = t; throw :done) if t >= @now
|
|
96
|
+
end
|
|
79
97
|
end
|
|
80
|
-
else
|
|
81
|
-
|
|
82
|
-
|
|
98
|
+
else # pointer == :past
|
|
99
|
+
if @type.ambiguous?
|
|
100
|
+
[midnight + half_day + @type.time + offset_fix, midnight + @type.time + offset_fix, yesterday_midnight + @type.time + half_day].each do |t|
|
|
101
|
+
(@current_time = t; throw :done) if t <= @now
|
|
102
|
+
end
|
|
103
|
+
else
|
|
104
|
+
[midnight + @type.time + offset_fix, yesterday_midnight + @type.time].each do |t|
|
|
105
|
+
(@current_time = t; throw :done) if t <= @now
|
|
106
|
+
end
|
|
83
107
|
end
|
|
84
108
|
end
|
|
85
109
|
end
|
|
110
|
+
|
|
111
|
+
@current_time || raise("Current time cannot be nil at this point")
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
unless first
|
|
115
|
+
increment = @type.ambiguous? ? half_day : full_day
|
|
116
|
+
@current_time += pointer == :future ? increment : -increment
|
|
86
117
|
end
|
|
87
|
-
|
|
88
|
-
@current_time
|
|
118
|
+
|
|
119
|
+
Span.new(@current_time, @current_time + width)
|
|
89
120
|
end
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
121
|
+
|
|
122
|
+
def this(context = :future)
|
|
123
|
+
super
|
|
124
|
+
|
|
125
|
+
context = :future if context == :none
|
|
126
|
+
|
|
127
|
+
self.next(context)
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
def width
|
|
131
|
+
1
|
|
132
|
+
end
|
|
133
|
+
|
|
134
|
+
def to_s
|
|
135
|
+
super << '-time-' << @type.to_s
|
|
94
136
|
end
|
|
95
|
-
|
|
96
|
-
Chronic::Span.new(@current_time, @current_time + width)
|
|
97
|
-
end
|
|
98
|
-
|
|
99
|
-
def this(context = :future)
|
|
100
|
-
super
|
|
101
|
-
|
|
102
|
-
context = :future if context == :none
|
|
103
|
-
|
|
104
|
-
self.next(context)
|
|
105
|
-
end
|
|
106
|
-
|
|
107
|
-
def width
|
|
108
|
-
1
|
|
109
|
-
end
|
|
110
|
-
|
|
111
|
-
def to_s
|
|
112
|
-
super << '-time-' << @type.to_s
|
|
113
137
|
end
|
|
114
|
-
end
|
|
138
|
+
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, options = {})
|
|
6
|
+
super
|
|
7
|
+
@current_week_start = nil
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def next(pointer)
|
|
11
|
+
super
|
|
12
|
+
|
|
13
|
+
unless @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
74
|
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
|
-
end
|
|
68
|
-
end
|
|
75
|
+
end
|