chronic 0.2.2 → 0.3.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.
Files changed (57) hide show
  1. data/HISTORY.md +76 -0
  2. data/LICENSE +21 -0
  3. data/README.md +165 -0
  4. data/Rakefile +145 -18
  5. data/benchmark/benchmark.rb +13 -0
  6. data/chronic.gemspec +85 -0
  7. data/lib/chronic/chronic.rb +59 -49
  8. data/lib/chronic/grabber.rb +2 -2
  9. data/lib/chronic/handlers.rb +167 -112
  10. data/lib/{numerizer → chronic/numerizer}/numerizer.rb +17 -23
  11. data/lib/chronic/ordinal.rb +6 -6
  12. data/lib/chronic/pointer.rb +3 -3
  13. data/lib/chronic/repeater.rb +26 -12
  14. data/lib/chronic/repeaters/repeater_day.rb +17 -12
  15. data/lib/chronic/repeaters/repeater_day_name.rb +17 -12
  16. data/lib/chronic/repeaters/repeater_day_portion.rb +15 -14
  17. data/lib/chronic/repeaters/repeater_fortnight.rb +14 -9
  18. data/lib/chronic/repeaters/repeater_hour.rb +15 -10
  19. data/lib/chronic/repeaters/repeater_minute.rb +15 -10
  20. data/lib/chronic/repeaters/repeater_month.rb +20 -15
  21. data/lib/chronic/repeaters/repeater_month_name.rb +21 -16
  22. data/lib/chronic/repeaters/repeater_season.rb +136 -9
  23. data/lib/chronic/repeaters/repeater_season_name.rb +38 -17
  24. data/lib/chronic/repeaters/repeater_second.rb +15 -10
  25. data/lib/chronic/repeaters/repeater_time.rb +53 -43
  26. data/lib/chronic/repeaters/repeater_week.rb +16 -11
  27. data/lib/chronic/repeaters/repeater_weekday.rb +77 -0
  28. data/lib/chronic/repeaters/repeater_weekend.rb +14 -9
  29. data/lib/chronic/repeaters/repeater_year.rb +19 -13
  30. data/lib/chronic/scalar.rb +16 -14
  31. data/lib/chronic/separator.rb +25 -10
  32. data/lib/chronic/time_zone.rb +4 -3
  33. data/lib/chronic.rb +21 -19
  34. data/test/helper.rb +7 -0
  35. data/test/test_Chronic.rb +17 -18
  36. data/test/test_DaylightSavings.rb +118 -0
  37. data/test/test_Handler.rb +37 -38
  38. data/test/test_Numerizer.rb +8 -5
  39. data/test/test_RepeaterDayName.rb +15 -16
  40. data/test/test_RepeaterFortnight.rb +16 -17
  41. data/test/test_RepeaterHour.rb +18 -19
  42. data/test/test_RepeaterMinute.rb +34 -0
  43. data/test/test_RepeaterMonth.rb +16 -17
  44. data/test/test_RepeaterMonthName.rb +17 -18
  45. data/test/test_RepeaterTime.rb +20 -22
  46. data/test/test_RepeaterWeek.rb +16 -17
  47. data/test/test_RepeaterWeekday.rb +55 -0
  48. data/test/test_RepeaterWeekend.rb +21 -22
  49. data/test/test_RepeaterYear.rb +17 -18
  50. data/test/test_Span.rb +5 -6
  51. data/test/test_Time.rb +11 -12
  52. data/test/test_Token.rb +5 -6
  53. data/test/test_parsing.rb +314 -196
  54. metadata +74 -49
  55. data/History.txt +0 -49
  56. data/README.txt +0 -149
  57. data/test/suite.rb +0 -9
@@ -1,23 +1,150 @@
1
+ class Time
2
+ def to_minidate
3
+ MiniDate.new(self.month, self.day)
4
+ end
5
+ end
6
+
7
+ class Season
8
+ attr_reader :start, :end
9
+
10
+ def initialize(myStart, myEnd)
11
+ @start = myStart
12
+ @end = myEnd
13
+ end
14
+
15
+ def self.find_next_season(season, pointer)
16
+ lookup = {:spring => 0, :summer => 1, :autumn => 2, :winter => 3}
17
+ next_season_num = (lookup[season]+1*pointer) % 4
18
+ lookup.invert[next_season_num]
19
+ end
20
+
21
+ def self.season_after(season); find_next_season(season, +1); end
22
+ def self.season_before(season); find_next_season(season, -1); end
23
+ end
24
+
25
+ class MiniDate
26
+ attr_accessor :month, :day
27
+
28
+ def initialize(month, day)
29
+ @month = month
30
+ @day = day
31
+ end
32
+
33
+ def is_between?(md_start, md_end)
34
+ return true if (@month == md_start.month and @day >= md_start.day) ||
35
+ (@month == md_end.month and @day <= md_end.day)
36
+
37
+ i = md_start.month + 1
38
+ until i == md_end.month
39
+ return true if @month == i
40
+ i = (i+1) % 12
41
+ end
42
+
43
+ return false
44
+ end
45
+
46
+ def equals?(other)
47
+ @month == other.month and day == other.day
48
+ end
49
+ end
50
+
1
51
  class Chronic::RepeaterSeason < Chronic::Repeater #:nodoc:
52
+ YEAR_SEASONS = 4
2
53
  SEASON_SECONDS = 7_862_400 # 91 * 24 * 60 * 60
3
-
54
+ SEASONS = { :spring => Season.new( MiniDate.new(3,20),MiniDate.new(6,20) ),
55
+ :summer => Season.new( MiniDate.new(6,21),MiniDate.new(9,22) ),
56
+ :autumn => Season.new( MiniDate.new(9,23),MiniDate.new(12,21) ),
57
+ :winter => Season.new( MiniDate.new(12,22),MiniDate.new(3,19) ) }
58
+
59
+ def initialize(type)
60
+ super
61
+ @next_season_start = nil
62
+ end
63
+
4
64
  def next(pointer)
5
65
  super
6
-
7
- raise 'Not implemented'
66
+
67
+ direction = pointer == :future ? 1 : -1
68
+ next_season = Season.find_next_season(find_current_season(@now.to_minidate), direction)
69
+
70
+ find_next_season_span(direction, next_season)
8
71
  end
9
-
72
+
10
73
  def this(pointer = :future)
11
74
  super
12
-
13
- raise 'Not implemented'
75
+
76
+ direction = pointer == :future ? 1 : -1
77
+
78
+ today = Time.construct(@now.year, @now.month, @now.day)
79
+ this_ssn = find_current_season(@now.to_minidate)
80
+ case pointer
81
+ when :past
82
+ this_ssn_start = today + direction * num_seconds_til_start(this_ssn, direction)
83
+ this_ssn_end = today
84
+ when :future
85
+ this_ssn_start = today + Chronic::RepeaterDay::DAY_SECONDS
86
+ this_ssn_end = today + direction * num_seconds_til_end(this_ssn, direction)
87
+ when :none
88
+ this_ssn_start = today + direction * num_seconds_til_start(this_ssn, direction)
89
+ this_ssn_end = today + direction * num_seconds_til_end(this_ssn, direction)
90
+ end
91
+
92
+ Chronic::Span.new(this_ssn_start, this_ssn_end)
14
93
  end
15
-
94
+
95
+ def offset(span, amount, pointer)
96
+ Chronic::Span.new(offset_by(span.begin, amount, pointer), offset_by(span.end, amount, pointer))
97
+ end
98
+
99
+ def offset_by(time, amount, pointer)
100
+ direction = pointer == :future ? 1 : -1
101
+ time + amount * direction * SEASON_SECONDS
102
+ end
103
+
16
104
  def width
17
105
  SEASON_SECONDS
18
106
  end
19
-
107
+
20
108
  def to_s
21
109
  super << '-season'
22
110
  end
23
- end
111
+
112
+ private
113
+
114
+ def find_next_season_span(direction, next_season)
115
+ if !@next_season_start or !@next_season_end
116
+ @next_season_start = Time.construct(@now.year, @now.month, @now.day)
117
+ @next_season_end = Time.construct(@now.year, @now.month, @now.day)
118
+ end
119
+
120
+ @next_season_start += direction * num_seconds_til_start(next_season, direction)
121
+ @next_season_end += direction * num_seconds_til_end(next_season, direction)
122
+
123
+ Chronic::Span.new(@next_season_start, @next_season_end)
124
+ end
125
+
126
+ def find_current_season(md)
127
+ [:spring, :summer, :autumn, :winter].each do |season|
128
+ return season if md.is_between?(SEASONS[season].start, SEASONS[season].end)
129
+ end
130
+ end
131
+
132
+ def num_seconds_til(goal, direction)
133
+ start = Time.construct(@now.year, @now.month, @now.day)
134
+ seconds = 0
135
+
136
+ until (start + direction * seconds).to_minidate.equals?(goal)
137
+ seconds += Chronic::RepeaterDay::DAY_SECONDS
138
+ end
139
+
140
+ seconds
141
+ end
142
+
143
+ def num_seconds_til_start(season_symbol, direction)
144
+ num_seconds_til(SEASONS[season_symbol].start, direction)
145
+ end
146
+
147
+ def num_seconds_til_end(season_symbol, direction)
148
+ num_seconds_til(SEASONS[season_symbol].end, direction)
149
+ end
150
+ end
@@ -1,24 +1,45 @@
1
+ require 'chronic/repeaters/repeater_season.rb'
2
+
1
3
  class Chronic::RepeaterSeasonName < Chronic::RepeaterSeason #:nodoc:
2
- @summer = ['jul 21', 'sep 22']
3
- @autumn = ['sep 23', 'dec 21']
4
- @winter = ['dec 22', 'mar 19']
5
- @spring = ['mar 20', 'jul 20']
6
-
4
+ SEASON_SECONDS = 7_862_400 # 91 * 24 * 60 * 60
5
+ DAY_SECONDS = 86_400 # (24 * 60 * 60)
6
+
7
7
  def next(pointer)
8
- super
9
- raise 'Not implemented'
8
+ direction = pointer == :future ? 1 : -1
9
+ find_next_season_span(direction, @type)
10
10
  end
11
-
11
+
12
12
  def this(pointer = :future)
13
- super
14
- raise 'Not implemented'
13
+ # super
14
+
15
+ direction = pointer == :future ? 1 : -1
16
+
17
+ today = Time.construct(@now.year, @now.month, @now.day)
18
+ goal_ssn_start = today + direction * num_seconds_til_start(@type, direction)
19
+ goal_ssn_end = today + direction * num_seconds_til_end(@type, direction)
20
+ curr_ssn = find_current_season(@now.to_minidate)
21
+ case pointer
22
+ when :past
23
+ this_ssn_start = goal_ssn_start
24
+ this_ssn_end = (curr_ssn == @type) ? today : goal_ssn_end
25
+ when :future
26
+ this_ssn_start = (curr_ssn == @type) ? today + Chronic::RepeaterDay::DAY_SECONDS : goal_ssn_start
27
+ this_ssn_end = goal_ssn_end
28
+ when :none
29
+ this_ssn_start = goal_ssn_start
30
+ this_ssn_end = goal_ssn_end
31
+ end
32
+
33
+ Chronic::Span.new(this_ssn_start, this_ssn_end)
15
34
  end
16
-
17
- def width
18
- (91 * 24 * 60 * 60)
35
+
36
+ def offset(span, amount, pointer)
37
+ Chronic::Span.new(offset_by(span.begin, amount, pointer), offset_by(span.end, amount, pointer))
19
38
  end
20
-
21
- def to_s
22
- super << '-season-' << @type.to_s
39
+
40
+ def offset_by(time, amount, pointer)
41
+ direction = pointer == :future ? 1 : -1
42
+ time + amount * direction * Chronic::RepeaterYear::YEAR_SECONDS
23
43
  end
24
- end
44
+
45
+ end
@@ -1,36 +1,41 @@
1
1
  class Chronic::RepeaterSecond < Chronic::Repeater #:nodoc:
2
2
  SECOND_SECONDS = 1 # haha, awesome
3
-
3
+
4
+ def initialize(type)
5
+ super
6
+ @second_start = nil
7
+ end
8
+
4
9
  def next(pointer = :future)
5
10
  super
6
-
11
+
7
12
  direction = pointer == :future ? 1 : -1
8
-
13
+
9
14
  if !@second_start
10
15
  @second_start = @now + (direction * SECOND_SECONDS)
11
16
  else
12
17
  @second_start += SECOND_SECONDS * direction
13
18
  end
14
-
19
+
15
20
  Chronic::Span.new(@second_start, @second_start + SECOND_SECONDS)
16
21
  end
17
-
22
+
18
23
  def this(pointer = :future)
19
24
  super
20
-
25
+
21
26
  Chronic::Span.new(@now, @now + 1)
22
27
  end
23
-
28
+
24
29
  def offset(span, amount, pointer)
25
30
  direction = pointer == :future ? 1 : -1
26
31
  span + direction * amount * SECOND_SECONDS
27
32
  end
28
-
33
+
29
34
  def width
30
35
  SECOND_SECONDS
31
36
  end
32
-
37
+
33
38
  def to_s
34
39
  super << '-second'
35
40
  end
36
- end
41
+ end
@@ -1,114 +1,124 @@
1
1
  class Chronic::RepeaterTime < Chronic::Repeater #:nodoc:
2
2
  class Tick #:nodoc:
3
3
  attr_accessor :time
4
-
4
+
5
5
  def initialize(time, ambiguous = false)
6
6
  @time = time
7
7
  @ambiguous = ambiguous
8
8
  end
9
-
9
+
10
10
  def ambiguous?
11
11
  @ambiguous
12
12
  end
13
-
13
+
14
14
  def *(other)
15
15
  Tick.new(@time * other, @ambiguous)
16
16
  end
17
-
17
+
18
18
  def to_f
19
19
  @time.to_f
20
20
  end
21
-
21
+
22
22
  def to_s
23
23
  @time.to_s + (@ambiguous ? '?' : '')
24
24
  end
25
25
  end
26
-
26
+
27
27
  def initialize(time, options = {})
28
+ @current_time = nil
28
29
  t = time.gsub(/\:/, '')
29
- @type =
30
- if (1..2) === t.size
31
- Tick.new(t.to_i * 60 * 60, true)
32
- elsif t.size == 3
33
- Tick.new((t[0..0].to_i * 60 * 60) + (t[1..2].to_i * 60), true)
34
- elsif t.size == 4
35
- ambiguous = time =~ /:/ && t[0..0].to_i != 0 && t[0..1].to_i <= 12
36
- Tick.new(t[0..1].to_i * 60 * 60 + t[2..3].to_i * 60, ambiguous)
37
- elsif t.size == 5
38
- Tick.new(t[0..0].to_i * 60 * 60 + t[1..2].to_i * 60 + t[3..4].to_i, true)
39
- elsif t.size == 6
40
- ambiguous = time =~ /:/ && t[0..0].to_i != 0 && t[0..1].to_i <= 12
41
- Tick.new(t[0..1].to_i * 60 * 60 + t[2..3].to_i * 60 + t[4..5].to_i, ambiguous)
42
- else
43
- raise("Time cannot exceed six digits")
30
+
31
+ @type =
32
+ case t.size
33
+ when 1..2
34
+ hours = t.to_i
35
+ hours == 12 ? Tick.new(0 * 60 * 60, true) : Tick.new(hours * 60 * 60, true)
36
+ when 3
37
+ Tick.new((t[0..0].to_i * 60 * 60) + (t[1..2].to_i * 60), true)
38
+ when 4
39
+ ambiguous = time =~ /:/ && t[0..0].to_i != 0 && t[0..1].to_i <= 12
40
+ hours = t[0..1].to_i
41
+ 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)
42
+ when 5
43
+ Tick.new(t[0..0].to_i * 60 * 60 + t[1..2].to_i * 60 + t[3..4].to_i, true)
44
+ when 6
45
+ ambiguous = time =~ /:/ && t[0..0].to_i != 0 && t[0..1].to_i <= 12
46
+ hours = t[0..1].to_i
47
+ 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)
48
+ else
49
+ raise("Time cannot exceed six digits")
44
50
  end
45
51
  end
46
-
52
+
47
53
  # Return the next past or future Span for the time that this Repeater represents
48
54
  # pointer - Symbol representing which temporal direction to fetch the next day
49
55
  # must be either :past or :future
50
56
  def next(pointer)
51
57
  super
52
-
58
+
53
59
  half_day = 60 * 60 * 12
54
60
  full_day = 60 * 60 * 24
55
-
61
+
56
62
  first = false
57
-
63
+
58
64
  unless @current_time
59
65
  first = true
60
- midnight = Time.local(@now.year, @now.month, @now.day)
66
+ midnight = Chronic.time_class.local(@now.year, @now.month, @now.day)
67
+
61
68
  yesterday_midnight = midnight - full_day
62
69
  tomorrow_midnight = midnight + full_day
63
70
 
71
+ offset_fix = midnight.gmt_offset - tomorrow_midnight.gmt_offset
72
+ tomorrow_midnight += offset_fix
73
+
64
74
  catch :done do
65
75
  if pointer == :future
66
76
  if @type.ambiguous?
67
- [midnight + @type, midnight + half_day + @type, tomorrow_midnight + @type].each do |t|
68
- (@current_time = t; throw :done) if t > @now
77
+ [midnight + @type + offset_fix, midnight + half_day + @type + offset_fix, tomorrow_midnight + @type].each do |t|
78
+ (@current_time = t; throw :done) if t >= @now
69
79
  end
70
80
  else
71
- [midnight + @type, tomorrow_midnight + @type].each do |t|
72
- (@current_time = t; throw :done) if t > @now
81
+ [midnight + @type + offset_fix, tomorrow_midnight + @type].each do |t|
82
+ (@current_time = t; throw :done) if t >= @now
73
83
  end
74
84
  end
75
85
  else # pointer == :past
76
86
  if @type.ambiguous?
77
- [midnight + half_day + @type, midnight + @type, yesterday_midnight + @type * 2].each do |t|
78
- (@current_time = t; throw :done) if t < @now
87
+ [midnight + half_day + @type + offset_fix, midnight + @type + offset_fix, yesterday_midnight + @type + half_day].each do |t|
88
+ (@current_time = t; throw :done) if t <= @now
79
89
  end
80
90
  else
81
- [midnight + @type, yesterday_midnight + @type].each do |t|
82
- (@current_time = t; throw :done) if t < @now
91
+ [midnight + @type + offset_fix, yesterday_midnight + @type].each do |t|
92
+ (@current_time = t; throw :done) if t <= @now
83
93
  end
84
94
  end
85
95
  end
86
96
  end
87
-
97
+
88
98
  @current_time || raise("Current time cannot be nil at this point")
89
99
  end
90
-
100
+
91
101
  unless first
92
102
  increment = @type.ambiguous? ? half_day : full_day
93
103
  @current_time += pointer == :future ? increment : -increment
94
104
  end
95
-
105
+
96
106
  Chronic::Span.new(@current_time, @current_time + width)
97
107
  end
98
-
108
+
99
109
  def this(context = :future)
100
110
  super
101
-
111
+
102
112
  context = :future if context == :none
103
-
113
+
104
114
  self.next(context)
105
115
  end
106
-
116
+
107
117
  def width
108
118
  1
109
119
  end
110
-
120
+
111
121
  def to_s
112
122
  super << '-time-' << @type.to_s
113
123
  end
114
- end
124
+ end
@@ -1,9 +1,14 @@
1
1
  class Chronic::RepeaterWeek < Chronic::Repeater #:nodoc:
2
2
  WEEK_SECONDS = 604800 # (7 * 24 * 60 * 60)
3
-
3
+
4
+ def initialize(type)
5
+ super
6
+ @current_week_start = nil
7
+ end
8
+
4
9
  def next(pointer)
5
10
  super
6
-
11
+
7
12
  if !@current_week_start
8
13
  case pointer
9
14
  when :future
@@ -22,23 +27,23 @@ class Chronic::RepeaterWeek < Chronic::Repeater #:nodoc:
22
27
  direction = pointer == :future ? 1 : -1
23
28
  @current_week_start += direction * WEEK_SECONDS
24
29
  end
25
-
30
+
26
31
  Chronic::Span.new(@current_week_start, @current_week_start + WEEK_SECONDS)
27
32
  end
28
-
33
+
29
34
  def this(pointer = :future)
30
35
  super
31
-
36
+
32
37
  case pointer
33
38
  when :future
34
- this_week_start = Time.local(@now.year, @now.month, @now.day, @now.hour) + Chronic::RepeaterHour::HOUR_SECONDS
39
+ this_week_start = Chronic.time_class.local(@now.year, @now.month, @now.day, @now.hour) + Chronic::RepeaterHour::HOUR_SECONDS
35
40
  sunday_repeater = Chronic::RepeaterDayName.new(:sunday)
36
41
  sunday_repeater.start = @now
37
42
  this_sunday_span = sunday_repeater.this(:future)
38
43
  this_week_end = this_sunday_span.begin
39
44
  Chronic::Span.new(this_week_start, this_week_end)
40
45
  when :past
41
- this_week_end = Time.local(@now.year, @now.month, @now.day, @now.hour)
46
+ this_week_end = Chronic.time_class.local(@now.year, @now.month, @now.day, @now.hour)
42
47
  sunday_repeater = Chronic::RepeaterDayName.new(:sunday)
43
48
  sunday_repeater.start = @now
44
49
  last_sunday_span = sunday_repeater.next(:past)
@@ -52,17 +57,17 @@ class Chronic::RepeaterWeek < Chronic::Repeater #:nodoc:
52
57
  Chronic::Span.new(this_week_start, this_week_start + WEEK_SECONDS)
53
58
  end
54
59
  end
55
-
60
+
56
61
  def offset(span, amount, pointer)
57
62
  direction = pointer == :future ? 1 : -1
58
63
  span + direction * amount * WEEK_SECONDS
59
64
  end
60
-
65
+
61
66
  def width
62
67
  WEEK_SECONDS
63
68
  end
64
-
69
+
65
70
  def to_s
66
71
  super << '-week'
67
72
  end
68
- end
73
+ end
@@ -0,0 +1,77 @@
1
+ class Chronic::RepeaterWeekday < Chronic::Repeater #:nodoc:
2
+ WEEK_WEEKDAYS = 5
3
+ DAY_SECONDS = 86400 # (24 * 60 * 60)
4
+
5
+ def initialize(type)
6
+ super
7
+ @current_weekday_start = nil
8
+ end
9
+
10
+ def next(pointer)
11
+ super
12
+
13
+ direction = pointer == :future ? 1 : -1
14
+
15
+ if !@current_weekday_start
16
+ @current_weekday_start = Time.construct(@now.year, @now.month, @now.day)
17
+ @current_weekday_start += direction * DAY_SECONDS
18
+
19
+ until is_weekday?(@current_weekday_start.wday)
20
+ @current_weekday_start += direction * DAY_SECONDS
21
+ end
22
+ else
23
+ loop do
24
+ @current_weekday_start += direction * DAY_SECONDS
25
+ break if is_weekday?(@current_weekday_start.wday)
26
+ end
27
+ end
28
+
29
+ Chronic::Span.new(@current_weekday_start, @current_weekday_start + DAY_SECONDS)
30
+ end
31
+
32
+ def this(pointer = :future)
33
+ super
34
+
35
+ case pointer
36
+ when :past
37
+ self.next(:past)
38
+ when :future, :none
39
+ self.next(:future)
40
+ end
41
+ end
42
+
43
+ def offset(span, amount, pointer)
44
+ direction = pointer == :future ? 1 : -1
45
+
46
+ num_weekdays_passed = 0; offset = 0
47
+ until num_weekdays_passed == amount
48
+ offset += direction * DAY_SECONDS
49
+ num_weekdays_passed += 1 if is_weekday?((span.begin+offset).wday)
50
+ end
51
+
52
+ span + offset
53
+ end
54
+
55
+ def width
56
+ DAY_SECONDS
57
+ end
58
+
59
+ def to_s
60
+ super << '-weekday'
61
+ end
62
+
63
+ private
64
+
65
+ def is_weekend?(day)
66
+ day == symbol_to_number(:saturday) || day == symbol_to_number(:sunday)
67
+ end
68
+
69
+ def is_weekday?(day)
70
+ !is_weekend?(day)
71
+ end
72
+
73
+ def symbol_to_number(sym)
74
+ lookup = {:sunday => 0, :monday => 1, :tuesday => 2, :wednesday => 3, :thursday => 4, :friday => 5, :saturday => 6}
75
+ lookup[sym] || raise("Invalid symbol specified")
76
+ end
77
+ end
@@ -1,9 +1,14 @@
1
1
  class Chronic::RepeaterWeekend < Chronic::Repeater #:nodoc:
2
2
  WEEKEND_SECONDS = 172_800 # (2 * 24 * 60 * 60)
3
-
3
+
4
+ def initialize(type)
5
+ super
6
+ @current_week_start = nil
7
+ end
8
+
4
9
  def next(pointer)
5
10
  super
6
-
11
+
7
12
  if !@current_week_start
8
13
  case pointer
9
14
  when :future
@@ -21,13 +26,13 @@ class Chronic::RepeaterWeekend < Chronic::Repeater #:nodoc:
21
26
  direction = pointer == :future ? 1 : -1
22
27
  @current_week_start += direction * Chronic::RepeaterWeek::WEEK_SECONDS
23
28
  end
24
-
29
+
25
30
  Chronic::Span.new(@current_week_start, @current_week_start + WEEKEND_SECONDS)
26
31
  end
27
-
32
+
28
33
  def this(pointer = :future)
29
34
  super
30
-
35
+
31
36
  case pointer
32
37
  when :future, :none
33
38
  saturday_repeater = Chronic::RepeaterDayName.new(:saturday)
@@ -41,7 +46,7 @@ class Chronic::RepeaterWeekend < Chronic::Repeater #:nodoc:
41
46
  Chronic::Span.new(last_saturday_span.begin, last_saturday_span.begin + WEEKEND_SECONDS)
42
47
  end
43
48
  end
44
-
49
+
45
50
  def offset(span, amount, pointer)
46
51
  direction = pointer == :future ? 1 : -1
47
52
  weekend = Chronic::RepeaterWeekend.new(:weekend)
@@ -49,12 +54,12 @@ class Chronic::RepeaterWeekend < Chronic::Repeater #:nodoc:
49
54
  start = weekend.next(pointer).begin + (amount - 1) * direction * Chronic::RepeaterWeek::WEEK_SECONDS
50
55
  Chronic::Span.new(start, start + (span.end - span.begin))
51
56
  end
52
-
57
+
53
58
  def width
54
59
  WEEKEND_SECONDS
55
60
  end
56
-
61
+
57
62
  def to_s
58
63
  super << '-weekend'
59
64
  end
60
- end
65
+ end