Horde_Date::fromDays PHP Method

fromDays() public static method

Returned date belongs to the proleptic Gregorian calendar, using 'Astronomical' year numbering. The algorithm is valid for all years (positive and negative), and also for years preceding 4714 B.C. (i.e. for negative 'Julian Days'), and so the only limitation is platform-dependent (for 32-bit systems the maximum year would be something like about 1,465,190 A.D.). N.B. Monday, 24th November, 4714 B.C. is Julian Day '0'. Algorithm is from PEAR::Date_Calc
Author: Monte Ohrt ([email protected])
Author: Pierre-Alain Joye ([email protected])
Author: Daniel Convissor ([email protected])
Author: C.A. Woodcock ([email protected])
public static fromDays ( integer $days ) : Horde_Date
$days integer the number of days since 24th November, 4714 B.C.
return Horde_Date A Horde_Date object representing the date.
    public static function fromDays($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);
            $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);
            $year = $century * 100 + $year;
            if ($month < 10) {
                $month += 3;
            } else {
                $month -= 9;
                ++$year;
            }
        }
        return new Horde_Date($year, $month, $day);
    }