/** * Returns a formatted string of the given timestamp * * @param integer $tstamp the timestamp to format * @param integer $format [optional] the format * @param boolean $skipusertimestamp ignore user timestamp * @param boolean $skiptimestamp ignore rebasing timestamp */ function tbg_formatTime($tstamp, $format = 0, $skipusertimestamp = false, $skiptimestamp = false) { $tzoffset = 0; // offset the timestamp properly if (!$skiptimestamp) { $tzoffset = tbg_get_timezone_offset($skipusertimestamp); $tstamp += $tzoffset; } switch ($format) { case 1: $tstring = strftime(\thebuggenie\core\framework\Context::getI18n()->getDateTimeFormat(1), $tstamp); break; case 2: $tstring = strftime(\thebuggenie\core\framework\Context::getI18n()->getDateTimeFormat(2), $tstamp); break; case 3: $tstring = strftime(\thebuggenie\core\framework\Context::getI18n()->getDateTimeFormat(3), $tstamp); break; case 4: $tstring = strftime(\thebuggenie\core\framework\Context::getI18n()->getDateTimeFormat(4), $tstamp); break; case 5: $tstring = strftime(\thebuggenie\core\framework\Context::getI18n()->getDateTimeFormat(5), $tstamp); break; case 6: $tstring = strftime(\thebuggenie\core\framework\Context::getI18n()->getDateTimeFormat(6), $tstamp); break; case 7: $tstring = strftime(\thebuggenie\core\framework\Context::getI18n()->getDateTimeFormat(7), $tstamp); break; case 8: $tstring = strftime(\thebuggenie\core\framework\Context::getI18n()->getDateTimeFormat(8), $tstamp); break; case 9: $tstring = strftime(\thebuggenie\core\framework\Context::getI18n()->getDateTimeFormat(9), $tstamp); break; case 10: $tstring = strftime(\thebuggenie\core\framework\Context::getI18n()->getDateTimeFormat(10), $tstamp); break; case 11: $tstring = strftime(\thebuggenie\core\framework\Context::getI18n()->getDateTimeFormat(9), $tstamp); break; case 12: $tstring = ''; $days = day_delta($tstamp, $tzoffset); if ($days == 0) { $tstring .= __('Today') . ', '; } elseif ($days == -1) { $tstring .= __('Yesterday') . ', '; } elseif ($days == 1) { $tstring .= __('Tomorrow') . ', '; } else { $tstring .= strftime(\thebuggenie\core\framework\Context::getI18n()->getDateTimeFormat(12) . ', ', $tstamp); } $tstring .= strftime(\thebuggenie\core\framework\Context::getI18n()->getDateTimeFormat(14), $tstamp); break; case 13: $tstring = ''; $days = day_delta($tstamp, $tzoffset); if ($days == 0) { //$tstring .= __('Today') . ', '; } elseif ($days == -1) { $tstring .= __('Yesterday') . ', '; } elseif ($days == 1) { $tstring .= __('Tomorrow') . ', '; } else { $tstring .= strftime(\thebuggenie\core\framework\Context::getI18n()->getDateTimeFormat(12) . ', ', $tstamp); } $tstring .= strftime(\thebuggenie\core\framework\Context::getI18n()->getDateTimeFormat(14), $tstamp); break; case 14: $tstring = ''; $days = day_delta($tstamp, $tzoffset); if ($days == 0) { $tstring .= __('Today'); } elseif ($days == -1) { $tstring .= __('Yesterday'); } elseif ($days == 1) { $tstring .= __('Tomorrow'); } else { $tstring .= strftime(\thebuggenie\core\framework\Context::getI18n()->getDateTimeFormat(12), $tstamp); } break; case 15: $tstring = strftime(\thebuggenie\core\framework\Context::getI18n()->getDateTimeFormat(11), $tstamp); break; case 16: $tstring = strftime(\thebuggenie\core\framework\Context::getI18n()->getDateTimeFormat(12), $tstamp); break; case 17: $tstring = strftime(\thebuggenie\core\framework\Context::getI18n()->getDateTimeFormat(13), $tstamp); break; case 18: $tstring = strftime(\thebuggenie\core\framework\Context::getI18n()->getDateTimeFormat(16), $tstamp); break; case 19: $tstring = strftime(\thebuggenie\core\framework\Context::getI18n()->getDateTimeFormat(14), $tstamp); break; case 20: $tstring = ''; $days = day_delta($tstamp, $tzoffset); if ($days == 0) { $tstring .= __('Today') . ' (' . strftime('%H:%M', $tstamp) . ')'; } elseif ($days == -1) { $tstring .= __('Yesterday') . ' (' . strftime('%H:%M', $tstamp) . ')'; } elseif ($days == 1) { $tstring .= __('Tomorrow') . ' (' . strftime('%H:%M', $tstamp) . ')'; } else { $tstring .= strftime(\thebuggenie\core\framework\Context::getI18n()->getDateTimeFormat(15), $tstamp); } break; case 21: $tstring = strftime('%a, %d %b %Y %H:%M:%S ', $tstamp); // if (!$skipusertimestamp && \thebuggenie\core\framework\Settings::getUserTimezone() != 'sys') // { // if (\thebuggenie\core\framework\Settings::getUserTimezone() != 0) // { // $offset = \thebuggenie\core\framework\Settings::getUserTimezone() * 100; // } // } // elseif (\thebuggenie\core\framework\Settings::getGMToffset() != 0) // { // $offset = \thebuggenie\core\framework\Settings::getGMToffset() * 100; // } // // if (!isset($offset)) // { // $offset = 'GMT'; // } // // if ($offset == 0) // { // $offset = 'GMT'; // } // elseif ($offset != 'GMT') // { // $negative = false; // if (strstr($offset, '-')) // { // $offset = trim($offset, '-'); // $negative = true; // } // // if ($offset < 1000) // { // $offset = '0'.$offset; // } // // if ($negative) // { // $offset = '-'.$offset; // } // else // { // $offset = '+'.$offset; // } // } // // $tstring .= $offset; return $tstring; break; case 22: $tstring = strftime(\thebuggenie\core\framework\Context::getI18n()->getDateTimeFormat(15), $tstamp); break; case 23: $tstring = ''; $days = day_delta($tstamp, $tzoffset); if ($days == 0) { $tstring .= __('Today'); } elseif ($days == -1) { $tstring .= __('Yesterday'); } elseif ($days == 1) { $tstring .= __('Tomorrow'); } else { $tstring .= strftime(\thebuggenie\core\framework\Context::getI18n()->getDateTimeFormat(15), $tstamp); } break; case 24: $tstring = strftime(\thebuggenie\core\framework\Context::getI18n()->getDateTimeFormat(18), $tstamp); break; default: return $tstamp; } return $tstring; }
/** * Returns a formatted string of the given timestamp * * @param integer $tstamp the timestamp to format * @param integer $format[optional] the format * @param integer $skipusertimestamp ignore user timestamp */ function tbg_formatTime($tstamp, $format = 0, $skipusertimestamp = false, $skiptimestamp = false) { // offset the timestamp properly if (!$skiptimestamp) { $tstamp += tbg_get_timezone_offset($skipusertimestamp); } switch ($format) { case 1: $tstring = strftime(TBGContext::getI18n()->getDateTimeFormat(1), $tstamp); break; case 2: $tstring = strftime(TBGContext::getI18n()->getDateTimeFormat(2), $tstamp); break; case 3: $tstring = strftime(TBGContext::getI18n()->getDateTimeFormat(3), $tstamp); break; case 4: $tstring = strftime(TBGContext::getI18n()->getDateTimeFormat(4), $tstamp); break; case 5: $tstring = strftime(TBGContext::getI18n()->getDateTimeFormat(5), $tstamp); break; case 6: $tstring = strftime(TBGContext::getI18n()->getDateTimeFormat(6), $tstamp); break; case 7: $tstring = strftime(TBGContext::getI18n()->getDateTimeFormat(7), $tstamp); break; case 8: $tstring = strftime(TBGContext::getI18n()->getDateTimeFormat(8), $tstamp); break; case 9: $tstring = strftime(TBGContext::getI18n()->getDateTimeFormat(9), $tstamp); break; case 10: $tstring = strftime(TBGContext::getI18n()->getDateTimeFormat(10), $tstamp); break; case 11: $tstring = strftime(TBGContext::getI18n()->getDateTimeFormat(9), $tstamp); break; case 12: $tstring = ''; if (date('dmY', $tstamp) == date('dmY')) { $tstring .= __('Today') . ', '; } elseif (date('dmY', $tstamp) == date('dmY', mktime(0, 0, 0, date('m'), date('d') - 1))) { $tstring .= __('Yesterday') . ', '; } elseif (date('dmY', $tstamp) == date('dmY', mktime(0, 0, 0, date('m'), date('d') + 1))) { $tstring .= __('Tomorrow') . ', '; } else { $tstring .= strftime(TBGContext::getI18n()->getDateTimeFormat(12) . ', ', $tstamp); } $tstring .= strftime(TBGContext::getI18n()->getDateTimeFormat(14), $tstamp); break; case 13: $tstring = ''; if (date('dmY', $tstamp) == date('dmY')) { //$tstring .= __('Today') . ', '; } elseif (date('dmY', $tstamp) == date('dmY', mktime(0, 0, 0, date('m'), date('d') - 1))) { $tstring .= __('Yesterday') . ', '; } elseif (date('dmY', $tstamp) == date('dmY', mktime(0, 0, 0, date('m'), date('d') + 1))) { $tstring .= __('Tomorrow') . ', '; } else { $tstring .= strftime(TBGContext::getI18n()->getDateTimeFormat(12) . ', ', $tstamp); } $tstring .= strftime(TBGContext::getI18n()->getDateTimeFormat(14), $tstamp); break; case 14: $tstring = ''; if (date('dmY', $tstamp) == date('dmY')) { $tstring .= __('Today'); } elseif (date('dmY', $tstamp) == date('dmY', mktime(0, 0, 0, date('m'), date('d') - 1))) { $tstring .= __('Yesterday'); } elseif (date('dmY', $tstamp) == date('dmY', mktime(0, 0, 0, date('m'), date('d') + 1))) { $tstring .= __('Tomorrow'); } else { $tstring .= strftime(TBGContext::getI18n()->getDateTimeFormat(12), $tstamp); } break; case 15: $tstring = strftime(TBGContext::getI18n()->getDateTimeFormat(11), $tstamp); break; case 16: $tstring = strftime(TBGContext::getI18n()->getDateTimeFormat(12), $tstamp); break; case 17: $tstring = strftime(TBGContext::getI18n()->getDateTimeFormat(13), $tstamp); break; case 18: $tstring = strftime(TBGContext::getI18n()->getDateTimeFormat(16), $tstamp); break; case 19: $tstring = strftime(TBGContext::getI18n()->getDateTimeFormat(14), $tstamp); break; case 20: $tstring = ''; if (date('dmY', $tstamp) == date('dmY')) { $tstring .= __('Today') . ' (' . strftime('%H:%M', $tstamp) . ')'; } elseif (date('dmY', $tstamp) == date('dmY', mktime(0, 0, 0, date('m'), date('d') - 1))) { $tstring .= __('Yesterday') . ' (' . strftime('%H:%M', $tstamp) . ')'; } elseif (date('dmY', $tstamp) == date('dmY', mktime(0, 0, 0, date('m'), date('d') + 1))) { $tstring .= __('Tomorrow') . ' (' . strftime('%H:%M', $tstamp) . ')'; } else { $tstring .= strftime(TBGContext::getI18n()->getDateTimeFormat(15), $tstamp); } break; case 21: $tstring = strftime('%a, %d %b %Y %H:%M:%S ', $tstamp); // if (!$skipusertimestamp && TBGSettings::getUserTimezone() != 'sys') // { // if (TBGSettings::getUserTimezone() != 0) // { // $offset = TBGSettings::getUserTimezone() * 100; // } // } // elseif (TBGSettings::getGMToffset() != 0) // { // $offset = TBGSettings::getGMToffset() * 100; // } // // if (!isset($offset)) // { // $offset = 'GMT'; // } // // if ($offset == 0) // { // $offset = 'GMT'; // } // elseif ($offset != 'GMT') // { // $negative = false; // if (strstr($offset, '-')) // { // $offset = trim($offset, '-'); // $negative = true; // } // // if ($offset < 1000) // { // $offset = '0'.$offset; // } // // if ($negative) // { // $offset = '-'.$offset; // } // else // { // $offset = '+'.$offset; // } // } // // $tstring .= $offset; return $tstring; break; case 22: $tstring = strftime(TBGContext::getI18n()->getDateTimeFormat(15), $tstamp); break; case 23: $tstring = ''; if (date('dmY', $tstamp) == date('dmY')) { $tstring .= __('Today'); } elseif (date('dmY', $tstamp) == date('dmY', mktime(0, 0, 0, date('m'), date('d') - 1))) { $tstring .= __('Yesterday'); } elseif (date('dmY', $tstamp) == date('dmY', mktime(0, 0, 0, date('m'), date('d') + 1))) { $tstring .= __('Tomorrow'); } else { $tstring .= strftime(TBGContext::getI18n()->getDateTimeFormat(15), $tstamp); } break; case 24: $tstring = strftime(TBGContext::getI18n()->getDateTimeFormat(18), $tstamp); break; default: return $tstamp; } return htmlentities($tstring, ENT_NOQUOTES + ENT_IGNORE, TBGContext::getI18n()->getCharset()); }