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) ⇒ RepeaterSeason

Returns a new instance of RepeaterSeason.



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

def initialize(type)
  super
end

Instance Method Details

#next(pointer) ⇒ Object



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

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



46
47
48
# File 'lib/chronic/repeaters/repeater_season.rb', line 46

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



50
51
52
53
# File 'lib/chronic/repeaters/repeater_season.rb', line 50

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

#this(pointer = :future) ⇒ Object



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

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



59
60
61
# File 'lib/chronic/repeaters/repeater_season.rb', line 59

def to_s
  super << '-season'
end

#widthObject



55
56
57
# File 'lib/chronic/repeaters/repeater_season.rb', line 55

def width
  SEASON_SECONDS
end