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_decades, 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.



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

def initialize(type)
	super
	@current_year_start = nil
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 = Time.construct(@now.year + 1)
		when :past
			@current_year_start = Time.construct(@now.year - 1)
		end
	else
		diff = pointer == :future ? 1 : -1
		@current_year_start = Time.construct(@current_year_start.year + diff)
	end

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

#offset(span, amount, pointer) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
# File 'lib/chronic/repeaters/repeater_year.rb', line 45

def offset(span, amount, pointer)
	direction = pointer == :future ? 1 : -1

	sb = span.begin
	new_begin = Time.construct(sb.year + (amount * direction), sb.month, sb.day, sb.hour, sb.min, sb.sec)

	se = span.end
	new_end = Time.construct(se.year + (amount * direction), se.month, se.day, se.hour, se.min, se.sec)

	Chronic::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 = Time.construct(@now.year, @now.month, @now.day) + Chronic::RepeaterDay::DAY_SECONDS
		this_year_end = Time.construct(@now.year + 1, 1, 1)
	when :past
		this_year_start = Time.construct(@now.year, 1, 1)
		this_year_end = Time.construct(@now.year, @now.month, @now.day)
	when :none
		this_year_start = Time.construct(@now.year, 1, 1)
		this_year_end = Time.construct(@now.year + 1, 1, 1)
	end

	Chronic::Span.new(this_year_start, this_year_end)
end

#to_sObject



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

def to_s
	super << '-year'
end

#widthObject



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

def width
	(365 * 24 * 60 * 60)
end