Class: Holidays::DateCalculator::LunarDate
- Inherits:
-
Object
- Object
- Holidays::DateCalculator::LunarDate
- Defined in:
- lib/holidays/date_calculator/lunar_date.rb
Overview
Copied from github.com/sunsidew/ruby_lunardate Graciously allowed by JeeWoong Yang (github.com/sunsidew)
Instance Attribute Summary collapse
-
#day ⇒ Object
Returns the value of attribute day.
-
#month ⇒ Object
Returns the value of attribute month.
-
#year ⇒ Object
Returns the value of attribute year.
Instance Method Summary collapse
- #lunardays_for_type(month_type) ⇒ Object
- #to_s ⇒ Object
- #to_solar(year, month, day, region) ⇒ Object
Instance Attribute Details
#day ⇒ Object
Returns the value of attribute day.
6 7 8 |
# File 'lib/holidays/date_calculator/lunar_date.rb', line 6 def day @day end |
#month ⇒ Object
Returns the value of attribute month.
6 7 8 |
# File 'lib/holidays/date_calculator/lunar_date.rb', line 6 def month @month end |
#year ⇒ Object
Returns the value of attribute year.
6 7 8 |
# File 'lib/holidays/date_calculator/lunar_date.rb', line 6 def year @year end |
Instance Method Details
#lunardays_for_type(month_type) ⇒ Object
27 28 29 |
# File 'lib/holidays/date_calculator/lunar_date.rb', line 27 def lunardays_for_type(month_type) LUNARDAYS_FOR_MONTHTYPE[month_type] end |
#to_s ⇒ Object
31 32 33 |
# 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) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# 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 |