From: martin Date: Thu, 8 Aug 2002 17:28:30 +0000 (+0000) Subject: Fixed a tricky little bug with usergetmidnight() when no timezone was defined. X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=4606d9bb9f5ffd88b2e5a96ad887465464c5bd0d;p=moodle.git Fixed a tricky little bug with usergetmidnight() when no timezone was defined. --- diff --git a/lib/moodlelib.php b/lib/moodlelib.php index 10fffe5919..9672f48204 100644 --- a/lib/moodlelib.php +++ b/lib/moodlelib.php @@ -352,10 +352,18 @@ function usertime($date, $timezone=99) { function usergetmidnight($date, $timezone=99) { // Given a time, return the GMT timestamp of the most recent midnight // for the current user. - global $USER; + if ($timezone == 99) { + $timezone = (float)$USER->timezone; + } + $userdate = usergetdate($date, $timezone); + + if (abs($timezone) > 12) { + return mktime(0, 0, 0, $userdate["mon"], $userdate["mday"], $userdate["year"]); + } + $timemidnight = gmmktime (0, 0, 0, $userdate["mon"], $userdate["mday"], $userdate["year"]); return usertime($timemidnight, $timezone); // Time of midnight of this user's day, in GMT