/** * Calculates the sidereal time for the given timestamp. * * @return float */ public function getSiderealTime() { $julianDay = new JulianDay($this->dateTime); $T = bcdiv(bcsub(strval($julianDay), '2451545.0'), '36525'); $T2 = bcpow($T, '2'); $T3 = bcpow($T, '3'); $term1 = '280.46061837'; $term2 = bcmul('360.98564736629', bcsub(strval($julianDay), '2451545.0')); $term3 = bcmul('0.000387933', $T2); $term4 = bcdiv($T3, '38710000'); $result = bcsub(bcadd(bcadd($term1, $term2), $term3), $term4); while (bccomp($result, 0) == -1) { $result = bcadd($result, '360'); } while (bccomp($result, '360') >= 1) { $result = bcsub($result, '360'); } $st = new Time(); $st->setHourAngle(floatval($result)); return $st->getValue(); }
public function testSetHourAngleWorksAsExpected() { $time = new Time(); $time->setHourAngle(100.596390417); $this->assertEquals(6.7064260278, $time->getValue()); }
/** * Create the DateTime object for the given Julian Day * * @link http://www.tondering.dk/claus/cal/julperiod.php * * @param float $julianDay * * @return \DateTime */ protected function julianDayToDatetime($julianDay) { $J = $julianDay + 0.5; $Z = intval($J); $F = $J - $Z; $A = $Z; if ($Z >= 2299161) { $a = $this->intDiv($Z - 1867216.25, 36524.25); $A = $Z + 1 + $a - $this->intDiv($a, 4); } $B = $A + 1524; $C = $this->intDiv($B - 122.1, 365.25); $D = intval(365.25 * $C); $E = $this->intDiv($B - $D, 30.6001); $day = $B - $D - intval(30.6001 * $E) + $F; if ($E < 14) { $month = $E - 1; } else { $month = $E - 13; } if ($month > 2) { $year = $C - 4716; } else { $year = $C - 4715; } $decimalDayTime = $day - intval($day); $time = new Time(24 * $decimalDayTime); $hour = $time->getHour(); $minute = $time->getMinute(); $second = $time->getSecond(); $dateTime = new \DateTime(sprintf('%04d-%02d-%02d %02d:%02d:%02d', $year, $month, $day, $hour, $minute, $second), new \DateTimeZone('UTC')); return $dateTime; }