Class: Chronic::RepeaterYear
Overview
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_times, scan_for_units
Methods inherited from Tag
#initialize, #start=
Constructor Details
This class inherits a constructor from Chronic::Tag
Instance Method Details
#next(pointer) ⇒ Object
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
# File 'lib/chronic/repeaters/repeater_year.rb', line 3
def next(pointer)
super
if !@current_year_start
case pointer
when :future
@current_year_start = Time.local(@now.year + 1)
when :past
@current_year_start = Time.local(@now.year - 1)
end
else
diff = pointer == :future ? 1 : -1
@current_year_start = Time.local(@current_year_start.year + diff)
end
Chronic::Span.new(@current_year_start, Time.local(@current_year_start.year + 1))
end
|
#offset(span, amount, pointer) ⇒ Object
39
40
41
42
43
44
45
46
47
48
49
|
# File 'lib/chronic/repeaters/repeater_year.rb', line 39
def offset(span, amount, pointer)
direction = pointer == :future ? 1 : -1
sb = span.begin
new_begin = Time.local(sb.year + (amount * direction), sb.month, sb.day, sb.hour, sb.min, sb.sec)
se = span.end
new_end = Time.local(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
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
# File 'lib/chronic/repeaters/repeater_year.rb', line 21
def this(pointer = :future)
super
case pointer
when :future
this_year_start = Time.local(@now.year, @now.month, @now.day) + Chronic::RepeaterDay::DAY_SECONDS
this_year_end = Time.local(@now.year + 1, 1, 1)
when :past
this_year_start = Time.local(@now.year, 1, 1)
this_year_end = Time.local(@now.year, @now.month, @now.day)
when :none
this_year_start = Time.local(@now.year, 1, 1)
this_year_end = Time.local(@now.year + 1, 1, 1)
end
Chronic::Span.new(this_year_start, this_year_end)
end
|
#to_s ⇒ Object
55
56
57
|
# File 'lib/chronic/repeaters/repeater_year.rb', line 55
def to_s
super << '-year'
end
|
#width ⇒ Object
51
52
53
|
# File 'lib/chronic/repeaters/repeater_year.rb', line 51
def width
(365 * 24 * 60 * 60)
end
|