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, HashProperty, When::CalendarNote::Javanese, When::CalendarNote::JulianDay, Mayan, Tibetan, Yis

Constants included from Parts::Resource

Parts::Resource::ConstList, Parts::Resource::ConstTypes, Parts::Resource::IRIDecode, Parts::Resource::IRIDecodeTable, Parts::Resource::IRIEncode, Parts::Resource::IRIEncodeTable, Parts::Resource::IRIHeader, Parts::Resource::LabelProperty

Constants included from Namespace

Namespace::DC, Namespace::DCQ, Namespace::DCT, Namespace::FOAF, Namespace::OWL, Namespace::RDF, Namespace::RDFC, Namespace::RDFS, Namespace::RSS, Namespace::XSD

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

_setup_, _setup_info, #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, #parent, #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

日の暦注



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
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
# File 'lib/when_exe/region/japanese/notes.rb', line 1015

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, dates.range >= 14 ? When::PT0H : When::PT6H)
        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