Module: LunarCalendar::Utils

Defined in:
lib/lunar_calendar/utils.rb

Overview

The calculate utils

Class Method Summary collapse

Class Method Details

.decode(data, length, shift) ⇒ Number

Extract packed informactio

Parameters:

  • data (Number)

    packed data

  • length (Number)

    total bit to read

  • shift (Number)

    the shift position

Returns:

  • (Number)

    value

Since:

  • 0.1.0



17
18
19
# File 'lib/lunar_calendar/utils.rb', line 17

def self.decode(data, length, shift)
  (data & (((1 << length) - 1) << shift)) >> shift
end

.new_year_at(offset) ⇒ LunarCalendar::Solar

Extract lunar new year in solar date

Parameters:

  • offset (Number)

    the offset of table

Returns:

Since:

  • 0.1.0



28
29
30
31
32
33
34
35
# File 'lib/lunar_calendar/utils.rb', line 28

def self.new_year_at(offset)
  solar = LunarCalendar::Data::NEW_YEARS[offset]
  year = decode(solar, 12, 9)
  month = decode(solar, 4, 5)
  day = decode(solar, 5, 0)

  Solar.new(year, month, day)
end