Class: When::CalendarNote::Japanese::LunarPhases

Inherits:
LunarPhases show all
Defined in:
lib/when_exe/region/japanese/notes.rb

Overview

月の位相による暦注

Constant Summary

Constants inherited from When::CalendarNote

Bahai, CalendarDepend, Chinese, Default, When::CalendarNote::Javanese, When::CalendarNote::JulianDay, Mayan, Tibetan, Yis

Constants included from Parts::Resource

Parts::Resource::ConstList, Parts::Resource::ConstTypes, Parts::Resource::IRIHeader, Parts::Resource::LabelProperty

Instance Attribute Summary

Attributes inherited from LuniSolarPositions

#delta, #den, #formula, #margin, #num

Attributes inherited from When::CalendarNote

#event

Attributes inherited from TM::ReferenceSystem

#domain_of_validity, #position

Attributes inherited from BasicTypes::Object

#label

Attributes included from Parts::Resource

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

Class Method Summary collapse

Methods inherited from LuniSolarPositions

#event, #event_delta, #event_time, #position

Methods inherited from When::CalendarNote

#copy, #day, #duration, #enum_for, #include?, #month, #note?, #notes, #year

Methods inherited from TM::ReferenceSystem

#domain, #name

Methods included from Parts::Resource

#[], #^, _abbreviation_to_iri, _decode, _encode, _extract_prefix, _instance, _instantiate, _parse, _path_with_prefix, _replace_tags, _setup_, _setup_info, _simplify_path, base_uri, #each, #enum_for, #hierarchy, #include?, #included?, #iri, #leaf?, #m17n, #map, #next, #parent, #prev, #registered?, root_dir

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

Class Method Details

._day_notes(notes, dates, conditions = {}) ⇒ Object

日の暦注



947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
# File 'lib/when_exe/region/japanese/notes.rb', line 947

def self._day_notes(notes, dates, conditions={})
  date = When.when?(dates.o_date.to_cal_date.to_s,
           {:frame=>dates.o_date.frame,
            :clock=>dates.l_date.frame.time_basis})
  phase, metsu = dates.cal4note.l_phases.position(date)

  # 滅
  notes[''] =  metsu == 2 && dates.range < 11 ? '' : nil

  # 月相
  unless notes['月相']
    # イベントの判定
    formula = dates.cal4note.l_phases.formula
    clock   = formula.kind_of?(When::Ephemeris::ChineseTrueLunation) &&
      (5..25).include?(dates.l_date.cal_date[2]) ?
        When.Clock(-21600) :               # 唐代暦法の望弦は午前6時を日の境界とする
        dates.l_date.frame._time_basis[-1] # その他(進朔も考慮した時刻)
    odate   = When.when?(dates.o_date.to_cal_date.to_s, {:frame=>dates.o_date.frame, :clock=>clock})
    phases  = formula.phase_range(odate)
    thitis  = phases.map {|phase| (phase % 1) * 30.0}
    note    = if thitis[0] >= thitis[1]
      dates.o_date.frame.kind_of?(When::CalendarTypes::Christian) || conditions[:shoyo] ? '' : nil
    else
      range = thitis[0]...thitis[1]
      range.include?( 7.5) ? '上弦' :
      range.include?(15.0) ? ''   :
      range.include?(22.5) ? '下弦' : nil
    end

    # 結果の反映
    if conditions[:shoyo]
      # :shoyo が true ならイベント時刻も返す
      notes['月相'] = if note
        etime = formula._to_seed_type(formula.cn_to_time((phases[1] * 4).floor / 4.0), odate)
        if formula.respond_to?(:lunation_length) && formula.lunation_length.kind_of?(Rational)
          shoyo  =  etime.clk_time.universal_time
          shoyo +=  When::TM::Duration::DAY if (0...clock.universal_time).include?(shoyo)
          shoyo  = (shoyo  / When::TM::Duration::DAY * formula.denominator * 1000 + 0.5).floor / 1000.0
          shoyo  =  shoyo.to_i if shoyo == shoyo.to_i
          "#{note}(#{shoyo}/#{formula.denominator})"
        else
          etime.events = [note]
          etime
        end
      else
        nil
      end
    else
      # :shoyo が false ならイベン名のみ返す
      notes['月相'] = note
    end
  end

  # 月食
  notes['月食']        = nil # 計算できないので、偽としておく
  notes
end