Class: Chronic::RepeaterSeason

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

Overview

:nodoc:

Direct Known Subclasses

RepeaterSeasonName

Constant Summary collapse

YEAR_SEASONS =
4
SEASON_SECONDS =

91 * 24 * 60 * 60

7_862_400
SEASONS =
{ :spring => Chronic::Season.new( Chronic::MiniDate.new(3,20), Chronic::MiniDate.new(6,20) ),
:summer => Chronic::Season.new( Chronic::MiniDate.new(6,21), Chronic::MiniDate.new(9,22) ),
:autumn => Chronic::Season.new( Chronic::MiniDate.new(9,23), Chronic::MiniDate.new(12,21) ),
:winter => Chronic::Season.new( Chronic::MiniDate.new(12,22), Chronic::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_decades, 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.



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

def initialize(type)
	super
	@next_season_start = nil
end

Instance Method Details

#next(pointer) ⇒ Object



64
65
66
67
68
69
70
71
# File 'lib/chronic/repeaters/repeater_season.rb', line 64

def next(pointer)
	super

	direction = pointer == :future ? 1 : -1
	next_season = Chronic::Season.find_next_season(find_current_season(@now.to_minidate), direction)

	find_next_season_span(direction, next_season)
end

#offset(span, amount, pointer) ⇒ Object



95
96
97
# File 'lib/chronic/repeaters/repeater_season.rb', line 95

def offset(span, amount, pointer)
	Chronic::Span.new(offset_by(span.begin, amount, pointer), offset_by(span.end, amount, pointer))
end

#offset_by(time, amount, pointer) ⇒ Object



99
100
101
102
# File 'lib/chronic/repeaters/repeater_season.rb', line 99

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

#this(pointer = :future) ⇒ Object



73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/chronic/repeaters/repeater_season.rb', line 73

def this(pointer = :future)
	super

	direction = pointer == :future ? 1 : -1

	today = Time.construct(@now.year, @now.month, @now.day)
	this_ssn = find_current_season(@now.to_minidate)
	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 + Chronic::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

	Chronic::Span.new(this_ssn_start, this_ssn_end)
end

#to_sObject



108
109
110
# File 'lib/chronic/repeaters/repeater_season.rb', line 108

def to_s
	super << '-season'
end

#widthObject



104
105
106
# File 'lib/chronic/repeaters/repeater_season.rb', line 104

def width
	SEASON_SECONDS
end