Ejemplo n.º 1
0
    <?php 
DateTimeUtils::addDate('2012-12-01', 1, 'y');
DateTimeUtils::getWeekDay('2012/10/01', '/');
DateTimeUtils::isLeapYear('2012');
DateTimeUtils::timeFromNow(strtotime("2012-10-26 14:15:13"));
class DateTimeUtils
{
    /**
     * Checks for leap year, returns true if it is. No 2-digit year check. Also
     * handles julian calendar correctly.
     * @param integer $year year to check
     * @return boolean true if is leap year
     */
    public static function isLeapYear($year)
    {
        $year = self::digitCheck($year);
        if ($year % 4 != 0) {
            return false;
        }
        if ($year % 400 == 0) {
            return true;
        } else {
            if ($year > 1582 && $year % 100 == 0) {
                return false;
            }
        }
        return true;
    }
    /**
     * Fix 2-digit years. Works for any century.
     * Assumes that if 2-digit is more than 30 years in future, then previous century.