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, CommonWithRokuyo, CommonWithSovietFiveDay, CommonWithSovietSixDay, 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_delta, #event_eval, #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

日の暦注



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
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
# File 'lib/when_exe/region/japanese/notes.rb', line 967

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

  # 月食
  unless notes['月食'] && notes['神吉'] && notes['三寶吉'] && notes['小字注']
    level = (conditions[:lunar_eclipse]||0).to_i
    if level == -1
      note = nil
    else
      key  = dates.m_date.to_s[/\(.+\z/]
      if key
        note, = Japanese::Eclipse::Eclipses[key.gsub(/[()]/,'')]
      elsif dates.o_date.location &&
            dates.o_date.frame.kind_of?(When::CalendarTypes::Christian)
        info  = dates.o_date.location.lunar_eclipse(date..date)
        note  = '' + Japanese::Eclipse.eclipse_summary(info[0]) unless info.empty?
      end
      if note
        note.sub!(/\*.*\z/, '')
        note  = nil unless // =~ note
        note  = nil if level[0] == 1 && //  =~ note
        note  = nil if level[1] == 1 && /^\(/ =~ note
      end
    end
    notes['月食'] = note
  end

  notes
end