Class: When::CalendarNote::JapaneseNote::LunarPhases

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

Overview

月の位相による暦注

Constant Summary

Constants inherited from When::CalendarNote

BahaiNotes, ChineseNotes, DefaultNotes, When::CalendarNote::JavaneseNotes, When::CalendarNote::JulianDayNotes, MayanNotes, TibetanNotes, YiNotes

Constants included from Parts::Resource

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, #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

#[], #^, _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

日の暦注



930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
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
# File 'lib/when_exe/region/japanese_notes.rb', line 930

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