pangel-chronic 0.3.0.3 → 0.3.10

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. data/{README.rdoc → README.txt} +7 -22
  2. data/lib/chronic.rb +89 -12
  3. data/lib/chronic/chronic.rb +260 -301
  4. data/lib/chronic/grabber.rb +23 -23
  5. data/lib/chronic/handlers.rb +538 -557
  6. data/lib/chronic/ordinal.rb +36 -35
  7. data/lib/chronic/pointer.rb +24 -26
  8. data/lib/chronic/repeater.rb +128 -138
  9. data/lib/chronic/repeaters/repeater_day.rb +51 -51
  10. data/lib/chronic/repeaters/repeater_day_name.rb +50 -52
  11. data/lib/chronic/repeaters/repeater_day_portion.rb +93 -93
  12. data/lib/chronic/repeaters/repeater_fortnight.rb +66 -66
  13. data/lib/chronic/repeaters/repeater_hour.rb +56 -57
  14. data/lib/chronic/repeaters/repeater_minute.rb +56 -56
  15. data/lib/chronic/repeaters/repeater_month.rb +71 -62
  16. data/lib/chronic/repeaters/repeater_month_name.rb +95 -95
  17. data/lib/chronic/repeaters/repeater_season.rb +142 -142
  18. data/lib/chronic/repeaters/repeater_season_name.rb +42 -42
  19. data/lib/chronic/repeaters/repeater_second.rb +40 -40
  20. data/lib/chronic/repeaters/repeater_time.rb +124 -123
  21. data/lib/chronic/repeaters/repeater_week.rb +70 -70
  22. data/lib/chronic/repeaters/repeater_weekday.rb +76 -76
  23. data/lib/chronic/repeaters/repeater_weekend.rb +63 -63
  24. data/lib/chronic/repeaters/repeater_year.rb +63 -63
  25. data/lib/chronic/scalar.rb +89 -70
  26. data/lib/chronic/separator.rb +88 -88
  27. data/lib/chronic/time_zone.rb +23 -20
  28. data/lib/numerizer/numerizer.rb +93 -94
  29. data/test/suite.rb +2 -2
  30. data/test/test_Chronic.rb +47 -47
  31. data/test/test_Handler.rb +106 -106
  32. data/test/test_Numerizer.rb +47 -49
  33. data/test/test_RepeaterDayName.rb +48 -48
  34. data/test/test_RepeaterFortnight.rb +59 -59
  35. data/test/test_RepeaterHour.rb +61 -64
  36. data/test/test_RepeaterMonth.rb +43 -43
  37. data/test/test_RepeaterMonthName.rb +53 -53
  38. data/test/test_RepeaterTime.rb +68 -68
  39. data/test/test_RepeaterWeek.rb +59 -59
  40. data/test/test_RepeaterWeekday.rb +53 -53
  41. data/test/test_RepeaterWeekend.rb +71 -71
  42. data/test/test_RepeaterYear.rb +59 -59
  43. data/test/test_Span.rb +19 -28
  44. data/test/test_Time.rb +46 -46
  45. data/test/test_Token.rb +22 -22
  46. data/test/test_parsing.rb +726 -792
  47. metadata +6 -10
@@ -1,57 +1,57 @@
1
1
  class Chronic::RepeaterMinute < Chronic::Repeater #:nodoc:
2
- MINUTE_SECONDS = 60
3
-
4
- def initialize(type)
5
- super
6
- @current_minute_start = nil
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 = Time.construct(@now.year, @now.month, @now.day, @now.hour, @now.min + 1)
16
- when :past
17
- @current_minute_start = Time.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
- Chronic::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 = Time.construct(@now.year, @now.month, @now.day, @now.hour, @now.min)
34
- when :past
35
- minute_begin = Time.construct(@now.year, @now.month, @now.day, @now.hour, @now.min)
36
- minute_end = @now
37
- when :none
38
- minute_begin = Time.construct(@now.year, @now.month, @now.day, @now.hour, @now.min)
39
- minute_end = Time.construct(@now.year, @now.month, @now.day, @now.hour, @now.min) + MINUTE_SECONDS
40
- end
41
-
42
- Chronic::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'
56
- end
57
- end
2
+ MINUTE_SECONDS = 60
3
+
4
+ def initialize(type)
5
+ super
6
+ @current_minute_start = nil
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 = Time.construct(@now.year, @now.month, @now.day, @now.hour, @now.min + 1)
16
+ when :past
17
+ @current_minute_start = Time.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
+ Chronic::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 = Time.construct(@now.year, @now.month, @now.day, @now.hour, @now.min)
34
+ when :past
35
+ minute_begin = Time.construct(@now.year, @now.month, @now.day, @now.hour, @now.min)
36
+ minute_end = @now
37
+ when :none
38
+ minute_begin = Time.construct(@now.year, @now.month, @now.day, @now.hour, @now.min)
39
+ minute_end = Time.construct(@now.year, @now.month, @now.day, @now.hour, @now.min) + MINUTE_SECONDS
40
+ end
41
+
42
+ Chronic::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'
56
+ end
57
+ end
@@ -1,66 +1,75 @@
1
- class Chronic::RepeaterMonth < Chronic::Repeater #:nodoc:
2
- MONTH_SECONDS = 2_592_000 # 30 * 24 * 60 * 60
3
- YEAR_MONTHS = 12
4
-
5
- def initialize(type)
6
- super
7
- @current_month_start = nil
8
- end
9
-
10
- def next(pointer)
11
- super
12
-
13
- if !@current_month_start
14
- @current_month_start = offset_by(Time.construct(@now.year, @now.month), 1, pointer)
15
- else
16
- @current_month_start = offset_by(Time.construct(@current_month_start.year, @current_month_start.month), 1, pointer)
17
- end
18
-
19
- Chronic::Span.new(@current_month_start, Time.construct(@current_month_start.year, @current_month_start.month + 1))
20
- end
21
-
22
- def this(pointer = :future)
23
- super
1
+ require 'date'
24
2
 
25
- case pointer
26
- when :future
27
- month_start = Time.construct(@now.year, @now.month, @now.day + 1)
28
- month_end = self.offset_by(Time.construct(@now.year, @now.month), 1, :future)
29
- when :past
30
- month_start = Time.construct(@now.year, @now.month)
31
- month_end = Time.construct(@now.year, @now.month, @now.day)
32
- when :none
33
- month_start = Time.construct(@now.year, @now.month)
34
- month_end = self.offset_by(Time.construct(@now.year, @now.month), 1, :future)
35
- end
36
-
37
- Chronic::Span.new(month_start, month_end)
38
- end
39
-
40
- def offset(span, amount, pointer)
41
- Chronic::Span.new(offset_by(span.begin, amount, pointer), offset_by(span.end, amount, pointer))
42
- end
43
-
44
- def offset_by(time, amount, pointer)
45
- direction = pointer == :future ? 1 : -1
46
-
47
- amount_years = direction * amount / YEAR_MONTHS
48
- amount_months = direction * amount % YEAR_MONTHS
49
-
50
- new_year = time.year + amount_years
51
- new_month = time.month + amount_months
52
- if new_month > YEAR_MONTHS
53
- new_year += 1
54
- new_month -= YEAR_MONTHS
55
- end
56
- Time.construct(new_year, new_month, time.day, time.hour, time.min, time.sec)
57
- end
3
+ class Chronic::RepeaterMonth < Chronic::Repeater #:nodoc:
4
+ MONTH_SECONDS = 2_592_000 # 30 * 24 * 60 * 60
5
+ YEAR_MONTHS = 12
58
6
 
59
- def width
60
- MONTH_SECONDS
61
- end
7
+ def initialize(type)
8
+ super
9
+ @current_month_start = nil
10
+ end
62
11
 
63
- def to_s
64
- super << '-month'
65
- end
12
+ def next(pointer)
13
+ super
14
+
15
+ if !@current_month_start
16
+ @current_month_start = offset_by(Time.construct(@now.year, @now.month), 1, pointer)
17
+ else
18
+ @current_month_start = offset_by(Time.construct(@current_month_start.year, @current_month_start.month), 1, pointer)
19
+ end
20
+
21
+ Chronic::Span.new(@current_month_start, Time.construct(@current_month_start.year, @current_month_start.month + 1))
22
+ end
23
+
24
+ def this(pointer = :future)
25
+ super
26
+
27
+ case pointer
28
+ when :future
29
+ month_start = Time.construct(@now.year, @now.month, @now.day + 1)
30
+ month_end = self.offset_by(Time.construct(@now.year, @now.month), 1, :future)
31
+ when :past
32
+ month_start = Time.construct(@now.year, @now.month)
33
+ month_end = Time.construct(@now.year, @now.month, @now.day)
34
+ when :none
35
+ month_start = Time.construct(@now.year, @now.month)
36
+ month_end = self.offset_by(Time.construct(@now.year, @now.month), 1, :future)
37
+ end
38
+
39
+ Chronic::Span.new(month_start, month_end)
40
+ end
41
+
42
+ def offset(span, amount, pointer)
43
+ Chronic::Span.new(offset_by(span.begin, amount, pointer), offset_by(span.end, amount, pointer))
44
+ end
45
+
46
+ def offset_by(time, amount, pointer)
47
+ direction = pointer == :future ? 1 : -1
48
+
49
+ amount_years = direction * amount / YEAR_MONTHS
50
+ amount_months = direction * amount % YEAR_MONTHS
51
+
52
+ new_year = time.year + amount_years
53
+ new_month = time.month + amount_months
54
+ if new_month > YEAR_MONTHS
55
+ new_year += 1
56
+ new_month -= YEAR_MONTHS
57
+ end
58
+
59
+ new_time = Time.construct(new_year, new_month, time.day, time.hour, time.min, time.sec)
60
+ if new_time.month > new_month
61
+ d = Date.new(new_year, new_month, -1)
62
+ Time.construct(new_year, d.month, d.day, time.hour, time.min, time.sec)
63
+ else
64
+ new_time
65
+ end
66
+ end
67
+
68
+ def width
69
+ MONTH_SECONDS
70
+ end
71
+
72
+ def to_s
73
+ super << '-month'
74
+ end
66
75
  end
@@ -1,98 +1,98 @@
1
1
  class Chronic::RepeaterMonthName < Chronic::Repeater #:nodoc:
2
- MONTH_SECONDS = 2_592_000 # 30 * 24 * 60 * 60
2
+ MONTH_SECONDS = 2_592_000 # 30 * 24 * 60 * 60
3
3
 
4
- def initialize(type)
5
- super
6
- @current_month_begin = nil
7
- end
4
+ def initialize(type)
5
+ super
6
+ @current_month_begin = nil
7
+ end
8
8
 
9
- def next(pointer)
10
- super
11
-
12
- if !@current_month_begin
13
- target_month = symbol_to_number(@type)
14
- case pointer
15
- when :future
16
- if @now.month < target_month
17
- @current_month_begin = Time.construct(@now.year, target_month)
18
- elsif @now.month > target_month
19
- @current_month_begin = Time.construct(@now.year + 1, target_month)
20
- end
21
- when :none
22
- if @now.month <= target_month
23
- @current_month_begin = Time.construct(@now.year, target_month)
24
- elsif @now.month > target_month
25
- @current_month_begin = Time.construct(@now.year + 1, target_month)
26
- end
27
- when :past
28
- if @now.month > target_month
29
- @current_month_begin = Time.construct(@now.year, target_month)
30
- elsif @now.month < target_month
31
- @current_month_begin = Time.construct(@now.year - 1, target_month)
32
- end
33
- end
34
- @current_month_begin || raise("Current month should be set by now")
35
- else
36
- case pointer
37
- when :future
38
- @current_month_begin = Time.construct(@current_month_begin.year + 1, @current_month_begin.month)
39
- when :past
40
- @current_month_begin = Time.construct(@current_month_begin.year - 1, @current_month_begin.month)
41
- end
42
- end
43
-
44
- cur_month_year = @current_month_begin.year
45
- cur_month_month = @current_month_begin.month
46
-
47
- if cur_month_month == 12
48
- next_month_year = cur_month_year + 1
49
- next_month_month = 1
50
- else
51
- next_month_year = cur_month_year
52
- next_month_month = cur_month_month + 1
53
- end
54
-
55
- Chronic::Span.new(@current_month_begin, Time.construct(next_month_year, next_month_month))
56
- end
57
-
58
- def this(pointer = :future)
59
- super
60
-
61
- case pointer
62
- when :past
63
- self.next(pointer)
64
- when :future, :none
65
- self.next(:none)
66
- end
67
- end
68
-
69
- def width
70
- MONTH_SECONDS
71
- end
72
-
73
- def index
74
- symbol_to_number(@type)
75
- end
76
-
77
- def to_s
78
- super << '-monthname-' << @type.to_s
79
- end
80
-
81
- private
82
-
83
- def symbol_to_number(sym)
84
- lookup = {:january => 1,
85
- :february => 2,
86
- :march => 3,
87
- :april => 4,
88
- :may => 5,
89
- :june => 6,
90
- :july => 7,
91
- :august => 8,
92
- :september => 9,
93
- :october => 10,
94
- :november => 11,
95
- :december => 12}
96
- lookup[sym] || raise("Invalid symbol specified")
97
- end
98
- end
9
+ def next(pointer)
10
+ super
11
+
12
+ if !@current_month_begin
13
+ target_month = symbol_to_number(@type)
14
+ case pointer
15
+ when :future
16
+ if @now.month < target_month
17
+ @current_month_begin = Time.construct(@now.year, target_month)
18
+ elsif @now.month > target_month
19
+ @current_month_begin = Time.construct(@now.year + 1, target_month)
20
+ end
21
+ when :none
22
+ if @now.month <= target_month
23
+ @current_month_begin = Time.construct(@now.year, target_month)
24
+ elsif @now.month > target_month
25
+ @current_month_begin = Time.construct(@now.year + 1, target_month)
26
+ end
27
+ when :past
28
+ if @now.month > target_month
29
+ @current_month_begin = Time.construct(@now.year, target_month)
30
+ elsif @now.month < target_month
31
+ @current_month_begin = Time.construct(@now.year - 1, target_month)
32
+ end
33
+ end
34
+ @current_month_begin || raise("Current month should be set by now")
35
+ else
36
+ case pointer
37
+ when :future
38
+ @current_month_begin = Time.construct(@current_month_begin.year + 1, @current_month_begin.month)
39
+ when :past
40
+ @current_month_begin = Time.construct(@current_month_begin.year - 1, @current_month_begin.month)
41
+ end
42
+ end
43
+
44
+ cur_month_year = @current_month_begin.year
45
+ cur_month_month = @current_month_begin.month
46
+
47
+ if cur_month_month == 12
48
+ next_month_year = cur_month_year + 1
49
+ next_month_month = 1
50
+ else
51
+ next_month_year = cur_month_year
52
+ next_month_month = cur_month_month + 1
53
+ end
54
+
55
+ Chronic::Span.new(@current_month_begin, Time.construct(next_month_year, next_month_month))
56
+ end
57
+
58
+ def this(pointer = :future)
59
+ super
60
+
61
+ case pointer
62
+ when :past
63
+ self.next(pointer)
64
+ when :future, :none
65
+ self.next(:none)
66
+ end
67
+ end
68
+
69
+ def width
70
+ MONTH_SECONDS
71
+ end
72
+
73
+ def index
74
+ symbol_to_number(@type)
75
+ end
76
+
77
+ def to_s
78
+ super << '-monthname-' << @type.to_s
79
+ end
80
+
81
+ private
82
+
83
+ def symbol_to_number(sym)
84
+ lookup = {:january => 1,
85
+ :february => 2,
86
+ :march => 3,
87
+ :april => 4,
88
+ :may => 5,
89
+ :june => 6,
90
+ :july => 7,
91
+ :august => 8,
92
+ :september => 9,
93
+ :october => 10,
94
+ :november => 11,
95
+ :december => 12}
96
+ lookup[sym] || raise("Invalid symbol specified")
97
+ end
98
+ end
@@ -1,150 +1,150 @@
1
1
  class Time
2
- def to_minidate
3
- Chronic::MiniDate.new(self.month, self.day)
4
- end
2
+ def to_minidate
3
+ MiniDate.new(self.month, self.day)
4
+ end
5
5
  end
6
6
 
7
- class Chronic::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
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
23
  end
24
24
 
25
- class Chronic::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 ==(other)
47
- @month == other.month and day == other.day
48
- end
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
49
  end
50
50
 
51
51
  class Chronic::RepeaterSeason < Chronic::Repeater #:nodoc:
52
- YEAR_SEASONS = 4
53
- SEASON_SECONDS = 7_862_400 # 91 * 24 * 60 * 60
54
- SEASONS = { :spring => Chronic::Season.new( Chronic::MiniDate.new(3,20), Chronic::MiniDate.new(6,20) ),
55
- :summer => Chronic::Season.new( Chronic::MiniDate.new(6,21), Chronic::MiniDate.new(9,22) ),
56
- :autumn => Chronic::Season.new( Chronic::MiniDate.new(9,23), Chronic::MiniDate.new(12,21) ),
57
- :winter => Chronic::Season.new( Chronic::MiniDate.new(12,22), Chronic::MiniDate.new(3,19) ) }
58
-
59
- def initialize(type)
60
- super
61
- @next_season_start = nil
62
- end
63
-
64
- def next(pointer)
65
- super
66
-
67
- direction = pointer == :future ? 1 : -1
68
- next_season = Chronic::Season.find_next_season(find_current_season(@now.to_minidate), direction)
69
-
70
- find_next_season_span(direction, next_season)
71
- end
72
-
73
- def this(pointer = :future)
74
- super
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)
93
- end
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
-
104
- def width
105
- SEASON_SECONDS
106
- end
107
-
108
- def to_s
109
- super << '-season'
110
- 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 == 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
52
+ YEAR_SEASONS = 4
53
+ SEASON_SECONDS = 7_862_400 # 91 * 24 * 60 * 60
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
+
64
+ def next(pointer)
65
+ super
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)
71
+ end
72
+
73
+ def this(pointer = :future)
74
+ super
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)
93
+ end
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
+
104
+ def width
105
+ SEASON_SECONDS
106
+ end
107
+
108
+ def to_s
109
+ super << '-season'
110
+ 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