From: Jan Schneider Date: Thu, 29 Oct 2009 13:52:19 +0000 (+0100) Subject: Use calendar extension if available. X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=ab429f57413e71263453c0d5d97dd0359145fd5e;p=horde.git Use calendar extension if available. --- diff --git a/framework/Date/lib/Horde/Date.php b/framework/Date/lib/Horde/Date.php index 5bec3a8ba..d342d82c2 100644 --- a/framework/Date/lib/Horde/Date.php +++ b/framework/Date/lib/Horde/Date.php @@ -306,6 +306,10 @@ class Horde_Date */ public function toDays() { + if (function_exists('GregorianToJD')) { + return GregorianToJD($this->_month, $this->_mday, $this->_year); + } + $day = $this->_mday; $month = $this->_month; $year = $this->_year; @@ -370,27 +374,31 @@ class Horde_Date */ public static function fromDays($days) { - $days = intval($days); + if (function_exists('JDToGregorian')) { + list($month, $day, $year) = explode('/', JDToGregorian($days)); + } else { + $days = intval($days); - $days -= 1721119; - $century = floor((4 * $days - 1) / 146097); - $days = floor(4 * $days - 1 - 146097 * $century); - $day = floor($days / 4); + $days -= 1721119; + $century = floor((4 * $days - 1) / 146097); + $days = floor(4 * $days - 1 - 146097 * $century); + $day = floor($days / 4); - $year = floor((4 * $day + 3) / 1461); - $day = floor(4 * $day + 3 - 1461 * $year); - $day = floor(($day + 4) / 4); + $year = floor((4 * $day + 3) / 1461); + $day = floor(4 * $day + 3 - 1461 * $year); + $day = floor(($day + 4) / 4); - $month = floor((5 * $day - 3) / 153); - $day = floor(5 * $day - 3 - 153 * $month); - $day = floor(($day + 5) / 5); + $month = floor((5 * $day - 3) / 153); + $day = floor(5 * $day - 3 - 153 * $month); + $day = floor(($day + 5) / 5); - $year = $century * 100 + $year; - if ($month < 10) { - $month +=3; - } else { - $month -=9; - ++$year; + $year = $century * 100 + $year; + if ($month < 10) { + $month +=3; + } else { + $month -=9; + ++$year; + } } return new Horde_Date($year, $month, $day);