Sha256: 4348e98f0dd230c8b4d4dc4dbe5f939b9804d36fe9bc8620dfb209d3814cd1ec
Contents?: true
Size: 1.53 KB
Versions: 10
Compression:
Stored size: 1.53 KB
Contents
require 'hiccup/enumerable/schedule_enumerator' module Hiccup module Enumerable class AnnuallyEnumerator < ScheduleEnumerator def initialize(*args) super @month, @day = start_date.month, start_date.day if month == 2 and day == 29 def self.current_date Date.new(year, 2, leap_year?(year) ? 29 : 28) end end end attr_reader :month, :day protected attr_reader :year def advance! @year += skip current_date rescue advance! end def rewind! @year -= skip current_date rescue rewind! end def first_occurrence_on_or_after(date) @year = date.year @year += 1 if (date.month > month) or (date.month == month and date.day > day) remainder = (@year - start_date.year) % skip @year += (skip - remainder) if remainder > 0 current_date rescue advance! end def first_occurrence_on_or_before(date) @year = date.year @year -= 1 if (date.month < month) or (date.month == month and date.day < day) remainder = (@year - start_date.year) % skip @year -= remainder if remainder > 0 current_date rescue rewind! end def current_date Date.new(year, month, day) end end end end
Version data entries
10 entries across 10 versions & 1 rubygems