Class: Chronic::RepeaterSeason

Inherits:
Repeater show all
Defined in:
lib/chronic/repeaters/repeater_season.rb

Overview

:nodoc:

Direct Known Subclasses

RepeaterSeasonName

Constant Summary collapse

SEASON_SECONDS =

91 * 24 * 60 * 60

7_862_400
SEASONS =
{
  :spring => Season.new(MiniDate.new(3,20), MiniDate.new(6,20)),
  :summer => Season.new(MiniDate.new(6,21), MiniDate.new(9,22)),
  :autumn => Season.new(MiniDate.new(9,23), MiniDate.new(12,21)),
  :winter => Season.new(MiniDate.new(12,22), MiniDate.new(3,19))
}

Instance Attribute Summary

Attributes inherited from Tag

#type

Instance Method Summary collapse

Methods inherited from Repeater

#<=>, scan, scan_for_day_names, scan_for_day_portions, scan_for_month_names, scan_for_season_names, scan_for_times, scan_for_units

Methods inherited from Tag

#start=

Constructor Details

#initialize(type, options = {}) ⇒ RepeaterSeason

Returns a new instance of RepeaterSeason.



11
12
13
14
15
# File 'lib/chronic/repeaters/repeater_season.rb', line 11

def initialize(type, options = {})
  super
  @next_season_start = nil
  @next_season_end = nil
end

Instance Method Details

#next(pointer) ⇒ Object



17
18
19
20
21
22
23
24
# File 'lib/chronic/repeaters/repeater_season.rb', line 17

def next(pointer)
  super

  direction = pointer == :future ? 1 : -1
  next_season = Season.find_next_season(find_current_season(MiniDate.from_time(@now)), direction)

  find_next_season_span(direction, next_season)
end

#offset(span, amount, pointer) ⇒ Object



48
49
50
# File 'lib/chronic/repeaters/repeater_season.rb', line 48

def offset(span, amount, pointer)
  Span.new(offset_by(span.begin, amount, pointer), offset_by(span.end, amount, pointer))
end

#offset_by(time, amount, pointer) ⇒ Object



52
53
54
55
# File 'lib/chronic/repeaters/repeater_season.rb', line 52

def offset_by(time, amount, pointer)
  direction = pointer == :future ? 1 : -1
  time + amount * direction * SEASON_SECONDS
end

#this(pointer = :future) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/chronic/repeaters/repeater_season.rb', line 26

def this(pointer = :future)
  super

  direction = pointer == :future ? 1 : -1

  today = Chronic.construct(@now.year, @now.month, @now.day)
  this_ssn = find_current_season(MiniDate.from_time(@now))
  case pointer
  when :past
    this_ssn_start = today + direction * num_seconds_til_start(this_ssn, direction)
    this_ssn_end = today
  when :future
    this_ssn_start = today + RepeaterDay::DAY_SECONDS
    this_ssn_end = today + direction * num_seconds_til_end(this_ssn, direction)
  when :none
    this_ssn_start = today + direction * num_seconds_til_start(this_ssn, direction)
    this_ssn_end = today + direction * num_seconds_til_end(this_ssn, direction)
  end

  construct_season(this_ssn_start, this_ssn_end)
end

#to_sObject



61
62
63
# File 'lib/chronic/repeaters/repeater_season.rb', line 61

def to_s
  super << '-season'
end

#widthObject



57
58
59
# File 'lib/chronic/repeaters/repeater_season.rb', line 57

def width
  SEASON_SECONDS
end