3600 * 24 * 3) { if (date('Y') === date('Y', $timestamp)) { return ($includePrefix ? t('since') . ' ' : '') . date('d.m.', $timestamp); } return ($includePrefix ? t('since') . ' ' : '') . date('m.Y', $timestamp); } return $prefix . self::showHourMin(abs($diff), $includePrefix); } public static function timeSince($timestamp) { return self::smartTimeDiff(time() - $timestamp, $timestamp); } public static function prefixedTimeSince($timestamp, $ucfirst = false) { $result = self::smartTimeDiff(time() - $timestamp, $timestamp, true); if ($ucfirst) { $result = ucfirst($result); } return $result; } public static function timeUntil($timestamp) { return self::smartTimeDiff($timestamp - time(), $timestamp); } public static function prefixedTimeUntil($timestamp, $ucfirst) { $result = self::smartTimeDiff($timestamp - time(), $timestamp, true); if ($ucfirst) { $result = ucfirst($result); } return $result; } protected static function formatForUnits($value, & $units, $base) { $sign = ''; if ($value < 0) { $value = abs($value); $sign = '-'; } if ($value == 0) { $pow = $result = 0; } else { $pow = floor(log($value, $base)); $result = $value / pow($base, $pow); } // 1034.23 looks better than 1.03, but 2.03 is fine: if ($pow > 0 && $result < 2) { $result = $value / pow($base, --$pow); } return sprintf( '%s%0.2f %s', $sign, $result, $units[abs($pow)] ); } /** * Return the amount of seconds based on the given month * * @param DateTime|int $dateTimeOrTimestamp The date and time to use * * @return int */ public static function secondsByMonth($dateTimeOrTimestamp) { if (!($dt = $dateTimeOrTimestamp) instanceof DateTime) { $dt = new DateTime(); $dt->setTimestamp($dateTimeOrTimestamp); } return (int) $dt->format('t') * 24 * 3600; } /** * Return the amount of seconds based on the given year * * @param DateTime|int $dateTimeOrTimestamp The date and time to use * * @return int */ public static function secondsByYear($dateTimeOrTimestamp) { return (self::isLeapYear($dateTimeOrTimestamp) ? 366 : 365) * 24 * 3600; } /** * Return whether the given year is a leap year * * @param DateTime|int $dateTimeOrTimestamp The date and time to use * * @return bool */ public static function isLeapYear($dateTimeOrTimestamp) { if (!($dt = $dateTimeOrTimestamp) instanceof DateTime) { $dt = new DateTime(); $dt->setTimestamp($dateTimeOrTimestamp); } return $dt->format('L') == 1; } }