function format_date($time) { if (($timezone_id = session::get_value('TIMEZONE')) === false) { $timezone_id = forum_get_setting('forum_timezone', null, 27); } if (($gmt_offset = session::get_value('GMT_OFFSET')) === false) { $gmt_offset = forum_get_setting('forum_gmt_offset', null, 0); } if (($dst_offset = session::get_value('DST_OFFSET')) === false) { $dst_offset = forum_get_setting('forum_dst_offset', null, 0); } if (($dl_saving = session::get_value('DL_SAVING')) === false) { $dl_saving = forum_get_setting('forum_dl_saving', null, 'N'); } // Calculate $time in user's timezone. $time = $time + $gmt_offset * HOUR_IN_SECONDS; // Calculate the current time in user's timezone. $current_time = time() + $gmt_offset * HOUR_IN_SECONDS; // Check for DST changes if ($dl_saving == 'Y' && timestamp_is_dst($timezone_id, $gmt_offset)) { // Ammend the $time to include DST $time = $time + $dst_offset * HOUR_IN_SECONDS; // Ammend the current time to include DST $current_time = $current_time + $dst_offset * HOUR_IN_SECONDS; } // Get the year of $time $time_year = gmdate("Y", $time); // Get the year for the current time $current_year = gmdate('Y', $current_time); // Only show the year if it is different to the current year if ($time_year != $current_year) { if (strtoupper(substr(PHP_OS, 0, 3)) == 'WIN') { $format = strftime('%#d %b %Y', $time); } else { $format = strftime('%e %b %Y', $time); } } else { if (strtoupper(substr(PHP_OS, 0, 3)) == 'WIN') { $format = strftime('%#d %b', $time); } else { $format = strftime('%e %b', $time); } } return $format; }
function user_format_local_time(&$user_prefs_array) { if (isset($user_prefs_array['TIMEZONE']) && is_numeric($user_prefs_array['TIMEZONE'])) { $timezone_id = $user_prefs_array['TIMEZONE']; } else { $timezone_id = forum_get_setting('forum_timezone', null, 27); } if (isset($user_prefs_array['GMT_OFFSET']) && is_numeric($user_prefs_array['GMT_OFFSET'])) { $gmt_offset = $user_prefs_array['GMT_OFFSET']; } else { $gmt_offset = forum_get_setting('forum_gmt_offset', null, 0); } if (isset($user_prefs_array['DST_OFFSET']) && is_numeric($user_prefs_array['DST_OFFSET'])) { $dst_offset = $user_prefs_array['DST_OFFSET']; } else { $dst_offset = forum_get_setting('forum_dst_offset', null, 0); } if (isset($user_prefs_array['DL_SAVING']) && user_check_pref('DL_SAVING', $user_prefs_array['DL_SAVING'])) { $dl_saving = $user_prefs_array['DL_SAVING']; } else { $dl_saving = forum_get_setting('forum_dl_saving', null, 'N'); } if ($dl_saving == "Y" && timestamp_is_dst($timezone_id, $gmt_offset)) { $local_time = time() + $gmt_offset * HOUR_IN_SECONDS + $dst_offset * HOUR_IN_SECONDS; } else { $local_time = time() + $gmt_offset * HOUR_IN_SECONDS; } $date_string = gmdate("i G j M Y", $local_time); list($min, $hour, $day, $month, $year) = explode(" ", $date_string); return sprintf(gettext("%s %s %s %s:%s"), $day, $month, $year, $hour, $min); // j M Y H:i }
function user_format_local_time(&$user_prefs_array) { if (isset($user_prefs_array['TIMEZONE']) && is_numeric($user_prefs_array['TIMEZONE'])) { $timezone_id = $user_prefs_array['TIMEZONE']; } else { $timezone_id = forum_get_setting('forum_timezone', null, 27); } if (isset($user_prefs_array['GMT_OFFSET']) && is_numeric($user_prefs_array['GMT_OFFSET'])) { $gmt_offset = $user_prefs_array['GMT_OFFSET']; } else { $gmt_offset = forum_get_setting('forum_gmt_offset', null, 0); } if (isset($user_prefs_array['DST_OFFSET']) && is_numeric($user_prefs_array['DST_OFFSET'])) { $dst_offset = $user_prefs_array['DST_OFFSET']; } else { $dst_offset = forum_get_setting('forum_dst_offset', null, 0); } if (isset($user_prefs_array['DL_SAVING']) && user_check_pref('DL_SAVING', $user_prefs_array['DL_SAVING'])) { $dl_saving = $user_prefs_array['DL_SAVING']; } else { $dl_saving = forum_get_setting('forum_dl_saving', null, 'N'); } if ($dl_saving == "Y" && timestamp_is_dst($timezone_id, $gmt_offset)) { $local_time = time() + $gmt_offset * HOUR_IN_SECONDS + $dst_offset * HOUR_IN_SECONDS; } else { $local_time = time() + $gmt_offset * HOUR_IN_SECONDS; } return strftime('%#d %b %Y %H:%M', $local_time); }
function format_date_time($time, $date_only = false) { if (isset($_SESSION['TIMEZONE']) && is_numeric($_SESSION['TIMEZONE'])) { $timezone_id = $_SESSION['TIMEZONE']; } else { $timezone_id = forum_get_setting('forum_timezone', 'is_numeric', 27); } if (isset($_SESSION['GMT_OFFSET']) && is_numeric($_SESSION['GMT_OFFSET'])) { $gmt_offset = $_SESSION['GMT_OFFSET']; } else { $gmt_offset = forum_get_setting('forum_gmt_offset', 'is_numeric', 0); } if (isset($_SESSION['DST_OFFSET']) && is_numeric($_SESSION['DST_OFFSET'])) { $dst_offset = $_SESSION['DST_OFFSET']; } else { $dst_offset = forum_get_setting('forum_dst_offset', 'is_numeric', 0); } if (isset($_SESSION['DL_SAVING']) && in_array($_SESSION['DL_SAVING'], array('Y', 'N'))) { $dl_saving = $_SESSION['DL_SAVING']; } else { $dl_saving = forum_get_setting('forum_dl_saving', 'strlen', 'N'); } // Calculate $time in user's timezone. $time = $time + $gmt_offset * HOUR_IN_SECONDS; // Calculate the current time in user's timezone. $current_time = time() + $gmt_offset * HOUR_IN_SECONDS; // Check for DST changes if ($dl_saving == 'Y' && timestamp_is_dst($timezone_id, $gmt_offset)) { // Amend the $time to include DST $time = $time + $dst_offset * HOUR_IN_SECONDS; // Amend the current time to include DST $current_time = $current_time + $dst_offset * HOUR_IN_SECONDS; } // Get the numerical parts for $time list($time_day, $time_month, $time_year) = explode(" ", gmdate("j M Y", $time)); // Get the numerical parts for the current month and year list($current_day, $current_month, $current_year) = explode(' ', gmdate('j M Y', $current_time)); // Decide on which format to display. if ($time_year == $current_year && $time_month == $current_month && $time_day == $current_day) { // Year, month and day are the same - show time only. $format = '%H:%M'; } else { if ($time_year == $current_year) { // Year is the same, show day, month and optional time. if ($date_only) { $format = '%e %b'; } else { $format = '%e %b %H:%M'; } } else { // Show full date and optional time. if ($date_only) { $format = '%e %b %Y'; } else { $format = '%e %b %Y %H:%M'; } } } // Replace %e with %#d on Windows. if (strtoupper(substr(PHP_OS, 0, 3)) == 'WIN') { $format = str_replace('%e', '%#d', $format); } return strftime($format, $time); }
function user_get_local_time() { if (isset($_SESSION['TIMEZONE']) && is_numeric($_SESSION['TIMEZONE'])) { $timezone_id = $_SESSION['TIMEZONE']; } else { $timezone_id = forum_get_setting('forum_timezone', 'is_numeric', 27); } if (isset($_SESSION['GMT_OFFSET']) && is_numeric($_SESSION['GMT_OFFSET'])) { $gmt_offset = $_SESSION['GMT_OFFSET']; } else { $gmt_offset = forum_get_setting('forum_gmt_offset', 'is_numeric', 0); } if (isset($_SESSION['DST_OFFSET']) && is_numeric($_SESSION['DST_OFFSET'])) { $dst_offset = $_SESSION['DST_OFFSET']; } else { $dst_offset = forum_get_setting('forum_dst_offset', 'is_numeric', 0); } if (isset($_SESSION['DL_SAVING']) && in_array($_SESSION['DL_SAVING'], array('Y', 'N'))) { $dl_saving = $_SESSION['DL_SAVING']; } else { $dl_saving = forum_get_setting('forum_dl_saving', 'strlen', 'N'); } if ($dl_saving == "Y" && timestamp_is_dst($timezone_id, $gmt_offset)) { $local_time = time() + $gmt_offset * HOUR_IN_SECONDS + $dst_offset * HOUR_IN_SECONDS; } else { $local_time = time() + $gmt_offset * HOUR_IN_SECONDS; } return $local_time; }
function user_get_local_time() { if (($timezone_id = session::get_value('TIMEZONE')) === false) { $timezone_id = forum_get_setting('forum_timezone', null, 27); } if (($gmt_offset = session::get_value('GMT_OFFSET')) === false) { $gmt_offset = forum_get_setting('forum_gmt_offset', null, 0); } if (($dst_offset = session::get_value('DST_OFFSET')) === false) { $dst_offset = forum_get_setting('forum_dst_offset', null, 0); } if (($dl_saving = session::get_value('DL_SAVING')) === false) { $dl_saving = forum_get_setting('forum_dl_saving', null, 'N'); } if ($dl_saving == "Y" && timestamp_is_dst($timezone_id, $gmt_offset)) { $local_time = time() + $gmt_offset * HOUR_IN_SECONDS + $dst_offset * HOUR_IN_SECONDS; } else { $local_time = time() + $gmt_offset * HOUR_IN_SECONDS; } return $local_time; }