public static function addDateUnitToTimestamp($timestamp, $units, $unitType, $returnDate = true) { $d = $timestamp; switch ($unitType) { case Gpf_Common_DateUtils::DAY: if (self::belowMinTimestamp($timestamp + Gpf_DateTime::daysToSeconds($units))) { $time = Gpf_DateTime::MIN_TIMESTAMP; break; } if (self::overMaxTimestamp($timestamp + Gpf_DateTime::daysToSeconds($units))) { $time = Gpf_DateTime::MAX_TIMESTAMP; break; } $time = mktime(0, 0, 0, date("m", $d), date("d", $d) + $units, date("Y", $d)); break; case Gpf_Common_DateUtils::WEEK: if (self::belowMinTimestamp($timestamp + Gpf_DateTime::weeksToSeconds($units))) { $time = Gpf_DateTime::MIN_TIMESTAMP; break; } if (self::overMaxTimestamp($timestamp + Gpf_DateTime::weeksToSeconds($units))) { $time = Gpf_DateTime::MAX_TIMESTAMP; break; } $time = mktime(0, 0, 0, date("m", $d), date("d", $d) + 7 * $units, date("Y", $d)); break; case Gpf_Common_DateUtils::MONTH: if (self::belowMinTimestamp($timestamp + Gpf_DateTime::monthsToSeconds($units))) { $time = Gpf_DateTime::MIN_TIMESTAMP; break; } if (self::overMaxTimestamp($timestamp + Gpf_DateTime::monthsToSeconds($units))) { $time = Gpf_DateTime::MAX_TIMESTAMP; break; } $month = date("m", $d) + $units; $day = self::daysInMonth($month, date("d", $d), date("Y", $d)); $time = mktime(0, 0, 0, $month, $day, date("Y", $d)); break; case Gpf_Common_DateUtils::YEAR: if (self::belowMinTimestamp($timestamp + Gpf_DateTime::yearsToSeconds($units))) { $time = Gpf_DateTime::MIN_TIMESTAMP; break; } if (self::overMaxTimestamp($timestamp + Gpf_DateTime::yearsToSeconds($units))) { $time = Gpf_DateTime::MAX_TIMESTAMP; break; } $time = mktime(0, 0, 0, date("m", $d), date("d", $d), date("Y", $d) + $units); break; } if ($returnDate) { return Gpf_Common_DateUtils::getDate($time); } return Gpf_Common_DateUtils::getDateTime($time); }