public function testGetSecondsAsIntegerWorksAsExpected() { $time = new Time(6.7064260278); $this->assertEquals(6, $time->getHour()); $this->assertEquals(42, $time->getMinute()); $this->assertEquals(23, $time->getSecond(true)); }
/** * 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; }