2021-02-26 16:16:17 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Safe;
|
|
|
|
|
|
|
|
use Safe\Exceptions\CalendarException;
|
|
|
|
|
|
|
|
/**
|
2022-07-12 19:26:21 +00:00
|
|
|
* Return the Julian Day for a Unix timestamp
|
|
|
|
* (seconds since 1.1.1970), or for the current day if no
|
|
|
|
* timestamp is given. Either way, the time is regarded
|
|
|
|
* as local time (not UTC).
|
2021-02-26 16:16:17 +00:00
|
|
|
*
|
2022-07-12 19:26:21 +00:00
|
|
|
* @param int $timestamp A unix timestamp to convert.
|
|
|
|
* @return int A julian day number as integer.
|
2021-02-26 16:16:17 +00:00
|
|
|
* @throws CalendarException
|
|
|
|
*
|
|
|
|
*/
|
2022-07-12 19:26:21 +00:00
|
|
|
function unixtojd(int $timestamp = null): int
|
2021-02-26 16:16:17 +00:00
|
|
|
{
|
|
|
|
error_clear_last();
|
2022-07-12 19:26:21 +00:00
|
|
|
if ($timestamp !== null) {
|
|
|
|
$result = \unixtojd($timestamp);
|
|
|
|
} else {
|
|
|
|
$result = \unixtojd();
|
|
|
|
}
|
2021-02-26 16:16:17 +00:00
|
|
|
if ($result === false) {
|
|
|
|
throw CalendarException::createFromPhpError();
|
|
|
|
}
|
|
|
|
return $result;
|
|
|
|
}
|