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, options = {}) ⇒ RepeaterYear

Returns a new instance of RepeaterYear.



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

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

Instance Method Details

#next(pointer) ⇒ Object



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

def next(pointer)
  super

  unless @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



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

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



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

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



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

def to_s
  super << '-year'
end

#widthObject



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

def width
  YEAR_SECONDS
end