class DCal::Month

Constants

COMMON_YEAR_DAYS_IN_MONTH
MONTHNAMES

Attributes

month[R]
year[R]

Public Class Methods

new(month, year) click to toggle source
# File lib/dcal/month.rb, line 19
def initialize(month, year)
  @month = month.to_i
  @year  = DCal::Year.new(year.to_i)

  unless (1..12).cover? @month
    raise RangeError, "#{@month} is not a month number (1..12)"
  end
end

Public Instance Methods

days_in_month() click to toggle source
# File lib/dcal/month.rb, line 36
def days_in_month
  return 29 if @month == 2 && @year.leap?
  COMMON_YEAR_DAYS_IN_MONTH[@month]
end
days_since_1970() click to toggle source
# File lib/dcal/month.rb, line 32
def days_since_1970
  (@year - 1970) * 365 + @year.leap_years_since_1970 + passed_days_this_year
end
inspect() click to toggle source

For better output in console

# File lib/dcal/month.rb, line 52
def inspect
  "#<#{self.class.name} #{to_s}>"
end
name() click to toggle source
# File lib/dcal/month.rb, line 28
def name
  MONTHNAMES[@month]
end
to_s() click to toggle source

For inspect

# File lib/dcal/month.rb, line 47
def to_s
  "#{@year}-#{@month}"
end
wday_of_first_day() click to toggle source
# File lib/dcal/month.rb, line 41
def wday_of_first_day
  # 1970-01-01 is Thursday (4).
  (days_since_1970 + 4) % 7
end

Private Instance Methods

passed_days_this_year() click to toggle source
# File lib/dcal/month.rb, line 58
def passed_days_this_year
  return 0 if @month == 1
  (1...@month).reduce(0) { |sum, m| sum + DCal::Month.new(m, @year).days_in_month }
end