/** * * @param JDate $date * */ public static function timeLapse($date) { $now = new JDate(); $dateDiff = CTimeHelper::timeDifference($date->toUnix(), $now->toUnix()); if ($dateDiff['days'] > 0) { $lapse = JText::sprintf(CStringHelper::isPlural($dateDiff['days']) ? 'CC LAPSED DAY MANY' : 'CC LAPSED DAY', $dateDiff['days']); } elseif ($dateDiff['hours'] > 0) { $lapse = JText::sprintf(CStringHelper::isPlural($dateDiff['hours']) ? 'CC LAPSED HOUR MANY' : 'CC LAPSED HOUR', $dateDiff['hours']); } elseif ($dateDiff['minutes'] > 0) { $lapse = JText::sprintf(CStringHelper::isPlural($dateDiff['minutes']) ? 'CC LAPSED MINUTE MANY' : 'CC LAPSED MINUTE', $dateDiff['minutes']); } else { $lapse = JText::sprintf(CStringHelper::isPlural($dateDiff['seconds']) ? 'CC LAPSED SECOND MANY' : 'CC LAPSED SECOND', $dateDiff['seconds']); } return $lapse; }
/** * * @param JDate $date * */ public static function timeLapse($date) { $now = new JDate(); $dateDiff = CTimeHelper::timeDifference($date->toUnix(), $now->toUnix()); if ($dateDiff['days'] > 0) { $lapse = JText::sprintf(CStringHelper::isPlural($dateDiff['days']) ? 'COM_COMMUNITY_LAPSED_DAY_MANY' : 'COM_COMMUNITY_LAPSED_DAY', $dateDiff['days']); } elseif ($dateDiff['hours'] > 0) { $lapse = JText::sprintf(CStringHelper::isPlural($dateDiff['hours']) ? 'COM_COMMUNITY_LAPSED_HOUR_MANY' : 'COM_COMMUNITY_LAPSED_HOUR', $dateDiff['hours']); } elseif ($dateDiff['minutes'] > 0) { $lapse = JText::sprintf(CStringHelper::isPlural($dateDiff['minutes']) ? 'COM_COMMUNITY_LAPSED_MINUTE_MANY' : 'COM_COMMUNITY_LAPSED_MINUTE', $dateDiff['minutes']); } else { if ($dateDiff['seconds'] == 0) { $lapse = JText::_("COM_COMMUNITY_ACTIVITIES_MOMENT_AGO"); } else { $lapse = JText::sprintf(CStringHelper::isPlural($dateDiff['seconds']) ? 'COM_COMMUNITY_LAPSED_SECOND_MANY' : 'COM_COMMUNITY_LAPSED_SECOND', $dateDiff['seconds']); } } return $lapse; }
/** * * @param JDate $date * */ public static function timeLapse($date, $showFull = true) { $now = JFactory::getDate(); $html = ''; $diff = CTimeHelper::timeDifference($date->toUnix(), $now->toUnix()); if (!empty($diff['days'])) { $days = $diff['days']; $months = ceil($days / 30); switch ($days) { case $days == 1: // @rule: Something that happened yesterday $html .= JText::_('COM_COMMUNITY_LAPSED_YESTERDAY'); break; case $days > 1 && $days <= 7 && $days < 30: // @rule: Something that happened within the past 7 days $html .= JText::sprintf('COM_COMMUNITY_LAPSED_DAYS', $days) . ' '; break; case $days > 1 && $days > 7 && $days < 30: // @rule: Something that happened within the month but after a week $weeks = round($days / 7); $html .= JText::sprintf(CStringHelper::isPlural($weeks) ? 'COM_COMMUNITY_LAPSED_WEEK_MANY' : 'COM_COMMUNITY_LAPSED_WEEK', $weeks) . ' '; break; case $days >= 30 && $days < 365: // @rule: Something that happened months ago $months = round($days / 30); $html .= JText::sprintf(CStringHelper::isPlural($months) ? 'COM_COMMUNITY_LAPSED_MONTH_MANY' : 'COM_COMMUNITY_LAPSED_MONTH', $months) . ' '; break; case $days > 365: // @rule: Something that happened years ago $years = round($days / 365); $html .= JText::sprintf(CStringHelper::isPlural($years) ? 'COM_COMMUNITY_LAPSED_YEAR_MANY' : 'COM_COMMUNITY_LAPSED_YEAR', $years) . ' '; break; } } else { // We only show he hours if it is less than 1 day if (!empty($diff['hours'])) { if (!empty($diff['minutes'])) { if ($diff['hours'] == 1) { $html .= JText::sprintf('COM_COMMUNITY_LAPSED_HOUR', $diff['hours']) . ' '; } else { $html .= JText::sprintf('COM_COMMUNITY_LAPSED_HOURS', $diff['hours']) . ' '; } } else { $html .= JText::sprintf('COM_COMMUNITY_LAPSED_HOURS_AGO', $diff['hours']) . ' '; } } if ($showFull && !empty($diff['hours']) || empty($diff['hours'])) { if (!empty($diff['minutes'])) { if ($diff['minutes'] == 1) { $html .= JText::sprintf('COM_COMMUNITY_LAPSED_MINUTE', $diff['minutes']) . ' '; } else { $html .= JText::sprintf('COM_COMMUNITY_LAPSED_MINUTES', $diff['minutes']) . ' '; } } } } if (empty($html)) { $html .= JText::_('COM_COMMUNITY_LAPSED_LESS_THAN_A_MINUTE'); } return $html; }
/** * Return html formatted lapse time * @param JDate date The date you want to compare * @access private */ function _createdLapse(&$date) { CFactory::load('helpers', 'time'); $now =& JFactory::getDate(); $html = ''; $diff = CTimeHelper::timeDifference($date->toUnix(), $now->toUnix()); if (!empty($diff['days'])) { $days = $diff['days']; $months = ceil($days / 30); if ($days == 1) { } switch ($days) { case $days == 1: // @rule: Something that happened yesterday $html .= JText::_('CC LAPSED YESTERDAY'); break; case $days > 1 && $days < 7 && $days < 30: // @rule: Something that happened within the past 7 days $html .= JText::sprintf('CC LAPSED DAYS', $days) . ' '; break; case $days > 1 && $days > 7 && $days < 30: // @rule: Something that happened within the month but after a week $weeks = round($days / 7); $html .= JText::sprintf(CStringHelper::isPlural($weeks) ? 'CC LAPSED WEEK MANY' : 'CC LAPSED WEEK', $weeks) . ' '; break; case $days > 30 && $days < 365: // @rule: Something that happened months ago $months = round($days / 30); $html .= JText::sprintf(CStringHelper::isPlural($months) ? 'CC LAPSED MONTH MANY' : 'CC LAPSED MONTH', $months) . ' '; break; case $days > 365: // @rule: Something that happened years ago $years = round($days / 365); $html .= JText::sprintf(CStringHelper::isPlural($years) ? 'CC LAPSED YEAR MANY' : 'CC LAPSED YEAR', $years) . ' '; break; } } else { // We only show he hours if it is less than 1 day if (!empty($diff['hours'])) { $html .= JText::sprintf('CC LAPSED HOURS', $diff['hours']) . ' '; } if (!empty($diff['minutes'])) { $html .= JText::sprintf('CC LAPSED MINUTES', $diff['minutes']) . ' '; } } if (empty($html)) { $html .= JText::_('CC LAPSED LESS THAN A MINUTE'); } if ($html != JText::_('CC LAPSED YESTERDAY')) { $html .= JText::_('CC LAPSED AGO'); } return $html; }