Horde_Date::toDays PHP Method

toDays() public method

Returns the no of days since Monday, 24th November, 4714 B.C. in the proleptic Gregorian calendar (which is 24th November, -4713 using 'Astronomical' year numbering, and 1st January, 4713 B.C. in the proleptic Julian calendar). This is also the first day of the 'Julian Period' proposed by Joseph Scaliger in 1583, and the number of days since this date is known as the 'Julian Day'. (It is not directly to do with the Julian calendar, although this is where the name is derived from.) The algorithm is valid for all years (positive and negative), and also for years preceding 4714 B.C. 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 toDays ( ) : integer
return integer The number of days since 24th November, 4714 B.C.
    public function toDays()
    {
        if (function_exists('GregorianToJD')) {
            return gregoriantojd($this->_month, $this->_mday, $this->_year);
        }
        $day = $this->_mday;
        $month = $this->_month;
        $year = $this->_year;
        if ($month > 2) {
            // March = 0, April = 1, ..., December = 9,
            // January = 10, February = 11
            $month -= 3;
        } else {
            $month += 9;
            --$year;
        }
        $hb_negativeyear = $year < 0;
        $century = intval($year / 100);
        $year = $year % 100;
        if ($hb_negativeyear) {
            // Subtract 1 because year 0 is a leap year;
            // And N.B. that we must treat the leap years as occurring
            // one year earlier than they do, because for the purposes
            // of calculation, the year starts on 1st March:
            //
            return intval((14609700 * $century + ($year == 0 ? 1 : 0)) / 400) + intval((1461 * $year + 1) / 4) + intval((153 * $month + 2) / 5) + $day + 1721118;
        } else {
            return intval(146097 * $century / 4) + intval(1461 * $year / 4) + intval((153 * $month + 2) / 5) + $day + 1721119;
        }
    }

Usage Example

Ejemplo n.º 1
0
 /**
  * @static
  *
  * @param mixed $date  The date to calculate the difference from. Can be
  *                     either a timestamp integer value, or an array
  *                     with date parts: 'day', 'month', 'year'.
  *
  * @return string
  */
 function getAgo($date)
 {
     if ($date === null) {
         return '';
     }
     try {
         $today = new Horde_Date(time());
         $date = new Horde_Date($date);
         $ago = $date->toDays() - $today->toDays();
     } catch (Horde_Date_Exception $e) {
         return '';
     }
     if ($ago < -1) {
         return sprintf(Horde_Form_Translation::t(" (%s days ago)"), abs($ago));
     } elseif ($ago == -1) {
         return Horde_Form_Translation::t(" (yesterday)");
     } elseif ($ago == 0) {
         return Horde_Form_Translation::t(" (today)");
     } elseif ($ago == 1) {
         return Horde_Form_Translation::t(" (tomorrow)");
     } else {
         return sprintf(Horde_Form_Translation::t(" (in %s days)"), $ago);
     }
 }
All Usage Examples Of Horde_Date::toDays