module MkTime::Compute
Public Instance Methods
calc_dt(utc)
click to toggle source
¶ ↑
ΔT の計算 * うるう秒調整が明確な場合は、うるう秒総和を使用した計算 * そうでない場合は、NASA の計算式による計算 @param: utc (Time Object) @return: dt (sec)
¶ ↑
# File lib/mk_time/compute.rb, line 167 def calc_dt(utc) return Rational(Const::TT_TAI, 1000) - @utc_tai - @dut1 unless @utc_tai == 0 y = utc.year + (utc.month - 0.5) / 12 case when utc.year < -500; dt = calc_dt_before_m500(y) when -500 <= utc.year && utc.year < 500; dt = calc_dt_before_500(y) when 500 <= utc.year && utc.year < 1600; dt = calc_dt_before_1600(y) when 1600 <= utc.year && utc.year < 1700; dt = calc_dt_before_1700(y) when 1700 <= utc.year && utc.year < 1800; dt = calc_dt_before_1800(y) when 1800 <= utc.year && utc.year < 1860; dt = calc_dt_before_1860(y) when 1860 <= utc.year && utc.year < 1900; dt = calc_dt_before_1900(y) when 1900 <= utc.year && utc.year < 1920; dt = calc_dt_before_1920(y) when 1920 <= utc.year && utc.year < 1941; dt = calc_dt_before_1941(y) when 1941 <= utc.year && utc.year < 1961; dt = calc_dt_before_1961(y) when 1961 <= utc.year && utc.year < 1986; dt = calc_dt_before_1986(y) when 1986 <= utc.year && utc.year < 2005; dt = calc_dt_before_2005(y) when 2005 <= utc.year && utc.year < 2050; dt = calc_dt_before_2050(y) when 2050 <= utc.year && utc.year <= 2150; dt = calc_dt_until_2150(y) when 2150 < utc.year ; dt = calc_dt_after_2150(y) end return dt rescue => e raise end
calc_dt_after_2150(y)
click to toggle source
calc_dt_before_1600(y)
click to toggle source
¶ ↑
deltaT (500 <= year && year < 1600) @param: y (Year coefficient for deltaT calculation) @return: dt (sec)
¶ ↑
# File lib/mk_time/compute.rb, line 233 def calc_dt_before_1600(y) t = (y - 1000) / 100.0 dt = 1574.2 + \ (-556.01 + \ ( 71.23472 + \ ( 0.319781 + \ ( -0.8503463 + \ ( -0.005050998 + \ ( 0.0083572073) \ * t) * t) * t) * t) * t) * t return dt rescue => e raise end
calc_dt_before_1700(y)
click to toggle source
¶ ↑
deltaT (1600 <= year && year < 1700) @param: y (Year coefficient for deltaT calculation) @return: dt (sec)
¶ ↑
# File lib/mk_time/compute.rb, line 254 def calc_dt_before_1700(y) t = y - 1600 dt = 120 + \ ( -0.9808 + \ ( -0.01532 + \ ( 1.0 / 7129.0) \ * t) * t) * t return dt rescue => e raise end
calc_dt_before_1800(y)
click to toggle source
¶ ↑
deltaT (1700 <= year && year < 1800) @param: y (Year coefficient for deltaT calculation) @return: dt (sec)
¶ ↑
# File lib/mk_time/compute.rb, line 272 def calc_dt_before_1800(y) t = y - 1700 dt = 8.83 + \ ( 0.1603 + \ (-0.0059285 + \ ( 0.00013336 + \ (-1.0 / 1174000.0) \ * t) * t) * t) * t return dt rescue => e raise end
calc_dt_before_1860(y)
click to toggle source
¶ ↑
deltaT (1800 <= year && year < 1860) @param: y (Year coefficient for deltaT calculation) @return: dt (sec)
¶ ↑
# File lib/mk_time/compute.rb, line 291 def calc_dt_before_1860(y) t = y - 1800 dt = 13.72 + \ (-0.332447 + \ ( 0.0068612 + \ ( 0.0041116 + \ (-0.00037436 + \ ( 0.0000121272 + \ (-0.0000001699 + \ ( 0.000000000875) \ * t) * t) * t) * t) * t) * t) * t return dt rescue => e raise end
calc_dt_before_1900(y)
click to toggle source
¶ ↑
deltaT (1860 <= year && year < 1900) @param: y (Year coefficient for deltaT calculation) @return: dt (sec)
¶ ↑
# File lib/mk_time/compute.rb, line 313 def calc_dt_before_1900(y) t = y - 1860 dt = 7.62 + \ ( 0.5737 + \ (-0.251754 + \ ( 0.01680668 + \ (-0.0004473624 + \ ( 1.0 / 233174.0) \ * t) * t) * t) * t) * t return dt rescue => e raise end
calc_dt_before_1920(y)
click to toggle source
¶ ↑
deltaT (1900 <= year && year < 1920) @param: y (Year coefficient for deltaT calculation) @return: dt (sec)
¶ ↑
# File lib/mk_time/compute.rb, line 333 def calc_dt_before_1920(y) t = y - 1900 dt = -2.79 + \ ( 1.494119 + \ (-0.0598939 + \ ( 0.0061966 + \ (-0.000197 ) \ * t) * t) * t) * t return dt rescue => e raise end
calc_dt_before_1941(y)
click to toggle source
calc_dt_before_1961(y)
click to toggle source
calc_dt_before_1986(y)
click to toggle source
calc_dt_before_2005(y)
click to toggle source
¶ ↑
deltaT (1986 <= year && year < 2005) @param: y (Year coefficient for deltaT calculation) @return: dt (sec)
¶ ↑
# File lib/mk_time/compute.rb, line 406 def calc_dt_before_2005(y) t = y - 2000 dt = 63.86 + \ ( 0.3345 + \ (-0.060374 + \ ( 0.0017275 + \ ( 0.000651814 + \ ( 0.00002373599) \ * t) * t) * t) * t) * t return dt rescue => e raise end
calc_dt_before_2050(y)
click to toggle source
calc_dt_before_500(y)
click to toggle source
¶ ↑
deltaT (-500 <= year && year < 500) @param: y (Year coefficient for deltaT calculation) @return: dt (sec)
¶ ↑
# File lib/mk_time/compute.rb, line 212 def calc_dt_before_500(y) t = y / 100.0 dt = 10583.6 + \ (-1014.41 + \ ( 33.78311 + \ ( -5.952053 + \ ( -0.1798452 + \ ( 0.022174192 + \ ( 0.0090316521) \ * t) * t) * t) * t) * t) * t return dt rescue => e raise end
calc_dt_before_m500(y)
click to toggle source
calc_dt_until_2150(y)
click to toggle source
gc2jd(t)
click to toggle source
¶ ↑
年月日(グレゴリオ暦) -> JD(ユリウス日) * フリーゲルの公式を使用する JD = int(365.25 * year) + int(year / 400) - int(year / 100) + int(30.59 (month - 2)) + day + 1721088 * 上記の int(x) は厳密には、 x を超えない最大の整数 * 「ユリウス日」でなく「準ユリウス日」を求めるなら、 `+ 1721088` を `- 678912` とする。 @param: t (Time Object) @return: jd (ユリウス日)
¶ ↑
# File lib/mk_time/compute.rb, line 41 def gc2jd(t) year, month, day = t.year, t.month, t.day hour, min, sec = t.hour, t.min, t.sec + (t.usec * 10 ** (-6)).to_f begin # 1月,2月は前年の13月,14月とする if month < 3 year -= 1 month += 12 end # 日付(整数)部分計算 jd = (365.25 * year).floor \ + (year / 400.0).floor \ - (year / 100.0).floor \ + (30.59 * (month - 2)).floor \ + day \ + 1721088.5 # 時間(小数)部分計算 t = (sec / 3600.0 + min / 60.0 + hour) / 24.0 return jd + t rescue => e raise end end
get_dut1(utc)
click to toggle source
¶ ↑
DUT1 (= UT1(世界時1) - UTC(協定世界時)) の取得 * Ref: http://jjy.nict.go.jp/QandA/data/dut1.html @param: utc (Time Object) @return: dut1 (sec)
¶ ↑
# File lib/mk_time/compute.rb, line 113 def get_dut1(utc) dut1 = 0 target = utc.strftime("%Y%m%d") begin Const::DUT1S.reverse.each do |date, sec| if date <= target dut1 = sec break end end return dut1 rescue => e raise end end
get_utc_tai(utc)
click to toggle source
¶ ↑
UTC(協定世界時) - TAI(国際原子時) (= うるう秒総和) の取得 * Ref: http://jjy.nict.go.jp/QandA/data/leapsec.html @param: utc (Time Object) @return: utc_tai (sec)
¶ ↑
# File lib/mk_time/compute.rb, line 88 def get_utc_tai(utc) utc_tai = 0 target = utc.strftime("%Y%m%d") begin Const::LEAP_SECS.reverse.each do |date, sec| if date <= target utc_tai = sec break end end return utc_tai rescue => e raise end end
jd2t(jd)
click to toggle source
tai2tt(tai)
click to toggle source
tcb2tdb(tcb)
click to toggle source
¶ ↑
TCB(太陽系重心座標時) -> TDB(太陽系力学時) * TDB = TCB - L_B * (JD_TCB - T_0) * 86400 + TDB_0 @param: tcb (Time Object) @return: tdb (Time Object)
¶ ↑
# File lib/mk_time/compute.rb, line 516 def tcb2tdb(tcb) jd_tcb = gc2jd(tcb) return tcb - Const::L_B * (jd_tcb - Const::T_0) * 86400 + Const::TDB_0 rescue => e raise end
tt2tcb(tt)
click to toggle source
tt2tcg(tt)
click to toggle source
¶ ↑
TCG(地球重心座標時) * TCG = TT + L_G * (JD - T_0) * 86,400 (JD: ユリウス日, L_G = 6.969290134 * 10^(-10), T_0 = 2,443,144.5003725) @param: tt (Time Object) @return: tcg (Time Object)
¶ ↑
# File lib/mk_time/compute.rb, line 488 def tt2tcg(tt) return tt + Const::L_G * (@jd - Const::T_0) * 86400 rescue => e raise end
utc2jst(utc)
click to toggle source
¶ ↑
UTC(協定世界時) -> JST(日本標準時) * JST = UTC + 09:00 @param: utc (Time Object) @return: jst (Time Object)
¶ ↑
# File lib/mk_time/compute.rb, line 13 def utc2jst(utc) jst = utc + Const::JST_OFFSET * 60 * 60 return Time.new( jst.year, jst.month, jst.day, jst.hour, jst.min, jst.sec + Rational(jst.usec, 10 ** 6), sprintf("+%02d:00", Const::JST_OFFSET) ) rescue => e raise end
utc2tai(utc)
click to toggle source