From 102dc313ea0523b968617ff819ece249f815a30a Mon Sep 17 00:00:00 2001 From: moodler Date: Sat, 19 Feb 2005 02:49:31 +0000 Subject: [PATCH] Fixing bug 2588 when server dates are used. --- lib/moodlelib.php | 36 +++++++++++++++++++++--------------- 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/lib/moodlelib.php b/lib/moodlelib.php index 92e4fe39006..feceebd8e50 100644 --- a/lib/moodlelib.php +++ b/lib/moodlelib.php @@ -681,33 +681,39 @@ function make_timestamp($year, $month=1, $day=1, $hour=0, $minute=0, $second=0, */ function userdate($date, $format='', $timezone=99, $fixday = true) { + if ($format == '') { $format = get_string('strftimedaydatetime'); } - $timezone = get_user_timezone($timezone); - $formatnoday = str_replace('%d', 'DD', $format); if ($fixday) { $fixday = ($formatnoday != $format); } $date += dst_offset_on($date); - if (abs($timezone) > 13) { - $date += intval((float)date('O') * HOURSECS); - } - else { - $date += intval((float)$timezone * HOURSECS); + + $timezone = get_user_timezone($timezone); + + if (abs($timezone) > 13) { /// Server time + if ($fixday) { + $datestring = strftime($formatnoday, $date); + $daystring = str_replace(' 0', '', strftime(' %d', $date)); + $datestring = str_replace('DD', $daystring, $datestring); + } else { + $datestring = strftime($format, $date); + } + } else { + $date += (int)($timezone * 3600); + if ($fixday) { + $datestring = gmstrftime($formatnoday, $date); + $daystring = str_replace(' 0', '', gmstrftime(' %d', $date)); + $datestring = str_replace('DD', $daystring, $datestring); + } else { + $datestring = gmstrftime($format, $date); + } } - if ($fixday) { - $datestring = gmstrftime($formatnoday, $date); - $daystring = str_replace(' 0', '', gmstrftime(' %d', $date)); - $datestring = str_replace('DD', $daystring, $datestring); - } else { - $datestring = gmstrftime($format, $date); - } - return $datestring; }