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
/** * @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); } }
/** * Returns number of days between this date and another. * * @param Horde_Date $other The other day to diff with. * * @return integer The absolute number of days between the two dates. */ public function diff($other) { return abs($this->toDays() - $other->toDays()); }