public static function getHowLongAgo(Zend_Date $date, $ago = 'ago') { $howLongAgo = ""; $locale = Zmz_Culture::getLocale(); $unitArray = Zend_Locale::getTranslationList('Unit'); $display = array(0 => $unitArray['duration-year'], 1 => $unitArray['duration-month'], 2 => $unitArray['duration-day'], 3 => $unitArray['duration-hour'], 4 => $unitArray['duration-minute'], 5 => $unitArray['duration-second']); $eventTimestamp = $date->getTimestamp(); $totaldelay = time() - $eventTimestamp; $value = 0; $unit = null; if ($totaldelay <= 0) { return ''; } $array = array(0 => 31536000, 1 => 2678400, 2 => 86400, 3 => 3600, 4 => 60, 5 => 1); foreach ($array as $k => $v) { $value = floor($totaldelay / $v); if ($value) { $totaldelay = $totaldelay % $v; $unit = $k; break; } } if ($value && $unit !== null) { $baseString = $value > 1 ? @$display[$unit]['other'] : @$display[$unit]['one']; if ($ago) { $ago = ' ' . $ago; } $howLongAgo = Zmz_String::format($baseString, $value) . $ago; } return $howLongAgo; }
public static function getLocaleList() { if (!self::$localeList) { $locale = Zmz_Culture::getLocale(); $enLocale = new Zend_Locale('en'); $locales = Zend_Locale::getLocaleList(); unset($locales['in']); unset($locales['iw']); $countries = array(); foreach ($locales as $k => $v) { $tmpLocale = new Zend_Locale($k); $region = $tmpLocale->getRegion(); if ($region) { $countries[(string) $tmpLocale] = Zend_Locale::getTranslation($tmpLocale->getLanguage(), 'language', $enLocale) . ' (' . Zend_Locale::getTranslation($region, 'Territory', $enLocale) . ')'; } else { $countries[(string) $tmpLocale] = Zend_Locale::getTranslation($tmpLocale->getLanguage(), 'language', $enLocale); } $countries[(string) $tmpLocale] .= ' [' . (string) $tmpLocale . ']'; } asort($countries); self::$localeList = $countries; } return self::$localeList; }
public static function getHowLongAgo($date, $ago = 'ago') { $locale = Zmz_Culture::getLocale(); $unit = Zend_Locale::getTranslationList('Unit'); $display = array(0 => $unit['year'], 1 => $unit['month'], 2 => $unit['day'], 3 => $unit['hour'], 4 => $unit['minute'], 5 => $unit['second']); $givenDate = clone $date; $givenDate = self::toUTC($givenDate); $now = self::toUTC(); if ($givenDate->isLater($now)) { return ''; } $dateCompare = getdate($givenDate->getTimestamp()); $current = getdate($now->getTimestamp()); $p = array('year', 'mon', 'mday', 'hours', 'minutes', 'seconds'); $factor = array(0, 12, 30, 24, 60, 60); for ($i = 0; $i < 6; $i++) { if ($i > 0) { $current[$p[$i]] += $current[$p[$i - 1]] * $factor[$i]; $dateCompare[$p[$i]] += $dateCompare[$p[$i - 1]] * $factor[$i]; } if ($current[$p[$i]] - $dateCompare[$p[$i]] >= 1) { $value = $current[$p[$i]] - $dateCompare[$p[$i]]; $string = str_replace('{0}', $value, $value != 1 ? $display[$i]['other'] : $display[$i]['one']) . ' ' . $ago; return $string; } } $diffDates = $now->sub($givenDate); $value = (int) $diffDates->get(Zend_Date::SECOND_SHORT); return str_replace('{0}', $value, $value != 1 ? $display[5]['other'] : $display[5]['one']) . ' ' . $ago; }