1 class Chronic::RepeaterMonth < Chronic::Repeater #:nodoc:
2 MONTH_SECONDS = 2_592_000 # 30 * 24 * 60 * 60
8 if !@current_month_start
9 @current_month_start = offset_by(Time.construct(@now.year, @now.month), 1, pointer)
11 @current_month_start = offset_by(Time.construct(@current_month_start.year, @current_month_start.month), 1, pointer)
14 Chronic::Span.new(@current_month_start, Time.construct(@current_month_start.year, @current_month_start.month + 1))
17 def this(pointer = :future)
22 month_start = Time.construct(@now.year, @now.month, @now.day + 1)
23 month_end = self.offset_by(Time.construct(@now.year, @now.month), 1, :future)
25 month_start = Time.construct(@now.year, @now.month)
26 month_end = Time.construct(@now.year, @now.month, @now.day)
28 month_start = Time.construct(@now.year, @now.month)
29 month_end = self.offset_by(Time.construct(@now.year, @now.month), 1, :future)
32 Chronic::Span.new(month_start, month_end)
35 def offset(span, amount, pointer)
36 Chronic::Span.new(offset_by(span.begin, amount, pointer), offset_by(span.end, amount, pointer))
39 def offset_by(time, amount, pointer)
40 direction = pointer == :future ? 1 : -1
42 amount_years = direction * amount / YEAR_MONTHS
43 amount_months = direction * amount % YEAR_MONTHS
45 new_year = time.year + amount_years
46 new_month = time.month + amount_months
47 if new_month > YEAR_MONTHS
49 new_month -= YEAR_MONTHS
51 Time.construct(new_year, new_month, time.day, time.hour, time.min, time.sec)