class Holidays::DateCalculator::LunarDate

Copied from github.com/sunsidew/ruby_lunardate Graciously allowed by JeeWoong Yang (github.com/sunsidew)

Constants

CALENDAR_YEAR_INFO_MAP

Given the region, CALENDAR_YEAR_INFO_MAP looks up the date table and uses it in the calculation

KOREAN_LUNAR_YEAR_INFO
LUNARDAYS_FOR_MONTHTYPE

Provides number of days per lunar month type. Lunar months can be either 29 or 30 days long (29.5 days, rounded up or down). Keys 3 - 6 provide data for intercalary (leap month) occurrences. Format: [TOTAL, NORMAL, LEAP]

MAX_YEAR_NUMBER
SOLAR_START_DATE

Provides the reference point for the Gregorian calendar and is used in all calculations

VIETNAMESE_LUNAR_YEAR_INFO

Attributes

day[RW]
month[RW]
year[RW]

Public Instance Methods

lunardays_for_type(month_type) click to toggle source
# File lib/holidays/date_calculator/lunar_date.rb, line 27
def lunardays_for_type(month_type)
  LUNARDAYS_FOR_MONTHTYPE[month_type]
end
to_s() click to toggle source
# File lib/holidays/date_calculator/lunar_date.rb, line 31
def to_s
  format('%4d%02d%02d', year, month, day)
end
to_solar(year, month, day, region) click to toggle source
# File lib/holidays/date_calculator/lunar_date.rb, line 8
def to_solar(year, month, day, region)
  days = 0
  year_diff = year - 1900
  year_info = CALENDAR_YEAR_INFO_MAP[region]

  year_diff.times do |year_idx|
    days += year_info[year_idx][0]
  end

  (month - 1).times do |month_idx|
    total, _normal, _leap = lunardays_for_type(year_info[year_diff][month_idx + 1])
    days += total
  end

  days += (day - 1)

  SOLAR_START_DATE + days
end