Class: Chronic::RepeaterYear

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

Overview

:nodoc:

Constant Summary collapse

YEAR_SECONDS =

365 * 24 * 60 * 60

31536000

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

Returns a new instance of RepeaterYear.



5
6
7
# File 'lib/chronic/repeaters/repeater_year.rb', line 5

def initialize(type)
  super
end

Instance Method Details

#next(pointer) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/chronic/repeaters/repeater_year.rb', line 9

def next(pointer)
  super

  if !@current_year_start
    case pointer
    when :future
      @current_year_start = Chronic.construct(@now.year + 1)
    when :past
      @current_year_start = Chronic.construct(@now.year - 1)
    end
  else
    diff = pointer == :future ? 1 : -1
    @current_year_start = Chronic.construct(@current_year_start.year + diff)
  end

  Span.new(@current_year_start, Chronic.construct(@current_year_start.year + 1))
end

#offset(span, amount, pointer) ⇒ Object



45
46
47
48
49
50
# File 'lib/chronic/repeaters/repeater_year.rb', line 45

def offset(span, amount, pointer)
  direction = pointer == :future ? 1 : -1
  new_begin = build_offset_time(span.begin, amount, direction)
  new_end   = build_offset_time(span.end, amount, direction)
  Span.new(new_begin, new_end)
end

#this(pointer = :future) ⇒ Object



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

def this(pointer = :future)
  super

  case pointer
  when :future
    this_year_start = Chronic.construct(@now.year, @now.month, @now.day + 1)
    this_year_end = Chronic.construct(@now.year + 1, 1, 1)
  when :past
    this_year_start = Chronic.construct(@now.year, 1, 1)
    this_year_end = Chronic.construct(@now.year, @now.month, @now.day)
  when :none
    this_year_start = Chronic.construct(@now.year, 1, 1)
    this_year_end = Chronic.construct(@now.year + 1, 1, 1)
  end

  Span.new(this_year_start, this_year_end)
end

#to_sObject



56
57
58
# File 'lib/chronic/repeaters/repeater_year.rb', line 56

def to_s
  super << '-year'
end

#widthObject



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

def width
  YEAR_SECONDS
end