Class: When::CalendarTypes::TableBased

Inherits:
TM::Calendar show all
Defined in:
lib/when_exe/calendartypes.rb

Overview

月日の配当パターンの種類が限定されている暦の抽象基底クラス

Calendar which has some fixed arrangement rules for under year

新年の日付が専用メソッドで与えられ、月日の配当が1年の日数等
で決まる暦。いわゆる Rule-Based な暦はほとんど該当します。

Constant Summary

Constants included from When::Coordinates

When::Coordinates::Bahai, When::Coordinates::CommonResidue, When::Coordinates::DefaultDateIndex, When::Coordinates::DefaultTimeIndex, When::Coordinates::IndianCities, When::Coordinates::Javanese, When::Coordinates::MATCH, When::Coordinates::Mayan, When::Coordinates::PERIOD, When::Coordinates::PERIOD_NAME, When::Coordinates::PRECISION, When::Coordinates::PRECISION_NAME, When::Coordinates::VALUE, When::Coordinates::Yi

Constants included from Parts::Resource

Parts::Resource::LabelProperty, Parts::Resource::Prefix, Parts::Resource::PrefixIndex, Parts::Resource::PrefixKeys, Parts::Resource::PrefixValues

Instance Attribute Summary

Attributes inherited from TM::Calendar

#reference_frame, #time_basis

Attributes inherited from TM::ReferenceSystem

#domain, #domain_of_validity, #position

Attributes inherited from BasicTypes::Object

#label

Attributes included from Parts::Resource

#_pool, #child, #keys, #locale, #namespace

Instance Method Summary collapse

Methods inherited from TM::Calendar

#_new_month_, _setup_, #_to_month_number_, #date_trans, #jul_trans, #rate_of_clock, #time_standard, #to_cal_date, #to_julian_date

Methods included from When::Coordinates

to_deg, to_dms

Methods inherited from TM::ReferenceSystem

#name

Methods inherited from BasicTypes::Object

#tap

Methods included from Parts::Resource

#[], #^, _extract_prefix, _instance, _parse, _path_with_prefix, #each, #enum_for, #hierarchy, #include?, #included?, #iri, #leaf?, #m17n, #map, #next, #parent, #prev, #registered?

Methods included from Parts::Resource::Pool

#[], #[]=, #_pool, #_setup_, #pool_keys

Methods included from Parts::Resource::Synchronize

#synchronize

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class When::Parts::Resource

Instance Method Details

#_coordinates_to_number(y, m, d) ⇒ Integer

年月日 -> 通日

Parameters:

  • y (Numeric)

  • m (Integer)

    月 (0 始まり)

  • d (Integer)

    日 (0 始まり)

Returns:

  • (Integer)

    通日



131
132
133
134
135
136
137
# File 'lib/when_exe/calendartypes.rb', line 131

def _coordinates_to_number(y, m, d)
  sdn  = _sdn([+y])
  rule = _rule(_key([+y]))
  sdn += d + rule['Offset'][m]
  return sdn if d >= 0
  return sdn + rule['Length'][m % rule['Length'].length]
end

#_length(date) ⇒ Integer #_length(date) ⇒ Integer

暦要素数

Overloads:

  • #_length(date) ⇒ Integer

    Returns その年の月数.

    Parameters:

    • date (Array<Integer>)

      ( y )

      y 年

    Returns:

    • (Integer)

      その年の月数

  • #_length(date) ⇒ Integer

    Returns その年月の日数.

    Parameters:

    • date (Array<Integer>)

      ( y, m )

      y 年

      m 月 (0 始まり)

    Returns:

    • (Integer)

      その年月の日数



178
179
180
181
182
183
184
185
186
187
188
189
190
# File 'lib/when_exe/calendartypes.rb', line 178

def _length(date)
  y, m = date
  if (m)
    #  指定した月に含まれる日の数を返します。
    return @unit[2] if @unit[2]
    rule = _rule(_key([y]))
    return rule['Length'][m % rule['Length'].length]
  else
    #  指定した年に含まれる月の数を返します。
    return @unit[1] if @unit[1]
    return _rule(_key([y]))['Months']
  end
end

#_number_to_coordinates(sdn) ⇒ Array<Integer>

通日 - > 年月日

Parameters:

  • sdn (Integer)

    通日

Returns:

  • (Array<Integer>)
    y, m, d

    y 年 m 月 (0 始まり) d 日 (0 始まり)



148
149
150
151
152
153
154
155
156
157
158
# File 'lib/when_exe/calendartypes.rb', line 148

def _number_to_coordinates(sdn)
  y, d = Residue.mod(sdn) {|n| _sdn([n])}
  rule = _rule(_key([y]))
  (rule['Months']-1).downto(0) do |m|
    if d >=rule['Offset'][m]
      d -= rule['Offset'][m]
      return [y, m, d]
    end
  end
  return nil
end