Module: MkTime::Compute
- Included in:
- Calc
- Defined in:
- lib/mk_time/compute.rb
Class Method Summary collapse
-
.calc_dt(utc) ⇒ Object
ΔT の計算.
-
.calc_dt_after_2150(y) ⇒ Object
deltaT (2150 < year).
-
.calc_dt_before_1600(y) ⇒ Object
deltaT (500 <= year && year < 1600).
-
.calc_dt_before_1700(y) ⇒ Object
deltaT (1600 <= year && year < 1700).
-
.calc_dt_before_1800(y) ⇒ Object
deltaT (1700 <= year && year < 1800).
-
.calc_dt_before_1860(y) ⇒ Object
deltaT (1800 <= year && year < 1860).
-
.calc_dt_before_1900(y) ⇒ Object
deltaT (1860 <= year && year < 1900).
-
.calc_dt_before_1920(y) ⇒ Object
deltaT (1900 <= year && year < 1920).
-
.calc_dt_before_1941(y) ⇒ Object
deltaT (1920 <= year && year < 1941).
-
.calc_dt_before_1961(y) ⇒ Object
deltaT (1941 <= year && year < 1961).
-
.calc_dt_before_1986(y) ⇒ Object
deltaT (1961 <= year && year < 1986).
-
.calc_dt_before_2005(y) ⇒ Object
deltaT (1986 <= year && year < 2005).
-
.calc_dt_before_2050(y) ⇒ Object
deltaT (2005 <= year && year < 2050).
-
.calc_dt_before_500(y) ⇒ Object
deltaT (-500 <= year && year < 500).
-
.calc_dt_before_m500(y) ⇒ Object
deltaT (year < -500).
-
.calc_dt_until_2150(y) ⇒ Object
deltaT (2050 <= year && year <= 2150).
-
.gc2jd(t) ⇒ Object
年月日(グレゴリオ暦) -> JD(ユリウス日).
-
.get_dut1(utc) ⇒ Object
DUT1 (= UT1(世界時1) - UTC(協定世界時)) の取得.
-
.get_utc_tai(utc) ⇒ Object
UTC(協定世界時) - TAI(国際原子時) (= うるう秒総和) の取得.
-
.jd2t(jd) ⇒ Object
JD(ユリウス日) -> T(ユリウス世紀数).
-
.tai2tt(tai) ⇒ Object
TT(地球時).
-
.tcb2tdb(tcb) ⇒ Object
TCB(太陽系重心座標時) -> TDB(太陽系力学時).
-
.tt2tcb(tt) ⇒ Object
TCB(太陽系重心座標時).
-
.tt2tcg(tt) ⇒ Object
TCG(地球重心座標時).
-
.utc2jst(utc) ⇒ Object
UTC(協定世界時) -> JST(日本標準時).
-
.utc2tai(utc) ⇒ Object
UTC(協定世界時) -> TAI(国際原子時).
-
.utc2ut1(utc) ⇒ Object
UTC(協定世界時) -> UT1(世界時1).
Class Method Details
.calc_dt(utc) ⇒ Object
ΔT の計算
-
うるう秒調整が明確な場合は、うるう秒総和を使用した計算
-
そうでない場合は、NASA の計算式による計算
@param: utc (Time Object) @return: dt (sec)
167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 |
# 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) ⇒ Object
deltaT (2150 < year)
@param: y (Year coefficient for deltaT calculation) @return: dt (sec)
458 459 460 461 462 463 464 |
# File 'lib/mk_time/compute.rb', line 458 def calc_dt_after_2150(y) t = (y - 1820) / 100.0 dt = -20 + 32 * t ** 2 return dt rescue => e raise end |
.calc_dt_before_1600(y) ⇒ Object
deltaT (500 <= year && year < 1600)
@param: y (Year coefficient for deltaT calculation) @return: dt (sec)
233 234 235 236 237 238 239 240 241 242 243 244 245 246 |
# 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) ⇒ Object
deltaT (1600 <= year && year < 1700)
@param: y (Year coefficient for deltaT calculation) @return: dt (sec)
254 255 256 257 258 259 260 261 262 263 264 |
# 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) ⇒ Object
deltaT (1700 <= year && year < 1800)
@param: y (Year coefficient for deltaT calculation) @return: dt (sec)
272 273 274 275 276 277 278 279 280 281 282 283 |
# 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) ⇒ Object
deltaT (1800 <= year && year < 1860)
@param: y (Year coefficient for deltaT calculation) @return: dt (sec)
291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 |
# 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) ⇒ Object
deltaT (1860 <= year && year < 1900)
@param: y (Year coefficient for deltaT calculation) @return: dt (sec)
313 314 315 316 317 318 319 320 321 322 323 324 325 |
# 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) ⇒ Object
deltaT (1900 <= year && year < 1920)
@param: y (Year coefficient for deltaT calculation) @return: dt (sec)
333 334 335 336 337 338 339 340 341 342 343 344 |
# 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) ⇒ Object
deltaT (1920 <= year && year < 1941)
@param: y (Year coefficient for deltaT calculation) @return: dt (sec)
352 353 354 355 356 357 358 359 360 361 362 |
# File 'lib/mk_time/compute.rb', line 352 def calc_dt_before_1941(y) t = y - 1920 dt = 21.20 + \ ( 0.84493 + \ (-0.076100 + \ ( 0.0020936) \ * t) * t) * t return dt rescue => e raise end |
.calc_dt_before_1961(y) ⇒ Object
deltaT (1941 <= year && year < 1961)
@param: y (Year coefficient for deltaT calculation) @return: dt (sec)
370 371 372 373 374 375 376 377 378 379 380 |
# File 'lib/mk_time/compute.rb', line 370 def calc_dt_before_1961(y) t = y - 1950 dt = 29.07 + \ ( 0.407 + \ (-1 / 233.0 + \ ( 1 / 2547.0) \ * t) * t) * t return dt rescue => e raise end |
.calc_dt_before_1986(y) ⇒ Object
deltaT (1961 <= year && year < 1986)
@param: y (Year coefficient for deltaT calculation) @return: dt (sec)
388 389 390 391 392 393 394 395 396 397 398 |
# File 'lib/mk_time/compute.rb', line 388 def calc_dt_before_1986(y) t = y - 1975 dt = 45.45 + \ ( 1.067 + \ (-1 / 260.0 + \ (-1 / 718.0) \ * t) * t) * t return dt rescue => e raise end |
.calc_dt_before_2005(y) ⇒ Object
deltaT (1986 <= year && year < 2005)
@param: y (Year coefficient for deltaT calculation) @return: dt (sec)
406 407 408 409 410 411 412 413 414 415 416 417 418 |
# 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) ⇒ Object
deltaT (2005 <= year && year < 2050)
@param: y (Year coefficient for deltaT calculation) @return: dt (sec)
426 427 428 429 430 431 432 433 434 435 |
# File 'lib/mk_time/compute.rb', line 426 def calc_dt_before_2050(y) t = y - 2000 dt = 62.92 + \ ( 0.32217 + \ ( 0.005589) \ * t) * t return dt rescue => e raise end |
.calc_dt_before_500(y) ⇒ Object
deltaT (-500 <= year && year < 500)
@param: y (Year coefficient for deltaT calculation) @return: dt (sec)
212 213 214 215 216 217 218 219 220 221 222 223 224 225 |
# 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) ⇒ Object
deltaT (year < -500)
@param: y (Year coefficient for deltaT calculation) @return: dt (sec)
198 199 200 201 202 203 204 |
# File 'lib/mk_time/compute.rb', line 198 def calc_dt_before_m500(y) t = (y - 1820) / 100.0 dt = -20 + 32 * t ** 2 return dt rescue => e raise end |
.calc_dt_until_2150(y) ⇒ Object
deltaT (2050 <= year && year <= 2150)
@param: y (Year coefficient for deltaT calculation) @return: dt (sec)
443 444 445 446 447 448 449 450 |
# File 'lib/mk_time/compute.rb', line 443 def calc_dt_until_2150(y) dt = -20 \ + 32 * ((y - 1820) / 100.0) ** 2 \ - 0.5628 * (2150 - y) return dt rescue => e raise end |
.gc2jd(t) ⇒ Object
年月日(グレゴリオ暦) -> 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 (ユリウス日)
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# 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) ⇒ Object
DUT1 (= UT1(世界時1) - UTC(協定世界時)) の取得
@param: utc (Time Object) @return: dut1 (sec)
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
# 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) ⇒ Object
UTC(協定世界時) - TAI(国際原子時) (= うるう秒総和) の取得
@param: utc (Time Object) @return: utc_tai (sec)
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# 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) ⇒ Object
JD(ユリウス日) -> T(ユリウス世紀数)
-
t = (JD - 2451545) / 36525.0
@param: jd (ユリウス日) @return: t (ユリウス世紀数)
74 75 76 77 78 |
# File 'lib/mk_time/compute.rb', line 74 def jd2t(jd) return (jd - Const::J2000) / (Const::JY * 100) rescue => e raise end |
.tai2tt(tai) ⇒ Object
TT(地球時)
-
TT = TAI + TT_TAI
= UT1 +
472 473 474 475 476 |
# File 'lib/mk_time/compute.rb', line 472 def tai2tt(tai) return tai + Rational(Const::TT_TAI, 1000) rescue => e raise end |
.tcb2tdb(tcb) ⇒ Object
TCB(太陽系重心座標時) -> TDB(太陽系力学時)
-
TDB = TCB - L_B * (JD_TCB - T_0) * 86400 + TDB_0
@param: tcb (Time Object) @return: tdb (Time Object)
516 517 518 519 520 521 |
# 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) ⇒ Object
TCB(太陽系重心座標時)
-
TCB = TT + L_B * (JD - T_0) * 86400
@param: tt (Time Object) @return: tcb (Time Object)
502 503 504 505 506 |
# File 'lib/mk_time/compute.rb', line 502 def tt2tcb(tt) return tt + Const::L_B * (@jd - Const::T_0) * 86400 rescue => e raise end |
.tt2tcg(tt) ⇒ Object
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)
488 489 490 491 492 |
# 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) ⇒ Object
UTC(協定世界時) -> JST(日本標準時)
-
JST = UTC + 09:00
@param: utc (Time Object) @return: jst (Time Object)
13 14 15 16 17 18 19 20 21 22 |
# 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) ⇒ Object
UTC(協定世界時) -> TAI(国際原子時)
-
TAI = UTC - UTC_TAI
@param: utc (Time Object) @return: tai (Time Object)
152 153 154 155 156 |
# File 'lib/mk_time/compute.rb', line 152 def utc2tai(utc) return utc - @utc_tai rescue => e raise end |
.utc2ut1(utc) ⇒ Object
UTC(協定世界時) -> UT1(世界時1)
-
UT1 = UTC + DUT1
@param: utc (Time Object) @return: ut1 (Time Object)
138 139 140 141 142 |
# File 'lib/mk_time/compute.rb', line 138 def utc2ut1(utc) return utc + Rational(@dut1) rescue => e raise end |