From edf7fe8c19aff6a5b0c6246ec1c14d7d87b6c06b Mon Sep 17 00:00:00 2001 From: martin Date: Mon, 10 Jun 2002 14:01:30 +0000 Subject: [PATCH] New usergetmidnight function and use in finding today's logs --- course/lib.php | 4 +--- lib/moodlelib.php | 16 ++++++++++++++++ user/index.php | 5 ++--- 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/course/lib.php b/course/lib.php index f84bb09550..2cd94ca288 100644 --- a/course/lib.php +++ b/course/lib.php @@ -38,9 +38,7 @@ function print_log_selector_form($course, $selecteduser=0, $selecteddate="today" $timenow = time(); // GMT // What day is it now for the user, and when is midnight that day (in GMT). - $date = usergetdate($timenow); - $timemidnight = gmmktime (0, 0, 0, $date["mon"], $date["mday"], $date["year"]); - $timemidnight = usertime($timemidnight); // Time of midnight of this user's day, in GMT + $timemidnight = usergetmidnight($timenow); // Put today up the top of the list $dates = array("$timemidnight" => "Today, ".userdate($timenow, "j F Y") ); diff --git a/lib/moodlelib.php b/lib/moodlelib.php index 8f8b41ae96..5c63b760a2 100644 --- a/lib/moodlelib.php +++ b/lib/moodlelib.php @@ -246,6 +246,22 @@ function usertime($date, $timezone=99) { return $date - (int)($timezone * 3600); } +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); + $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 + +} + function usertimezone($timezone=99) { // returns a string that prints the user's timezone global $USER; diff --git a/user/index.php b/user/index.php index 67b8b76f0c..9f2bb46cfb 100644 --- a/user/index.php +++ b/user/index.php @@ -75,10 +75,9 @@ function print_user($user, $course, $teacherlinks) { echo ""; if ($teacherlinks) { - $tt = usergetdate(time()); - $today = mktime (0, 0, 0, $tt["mon"], $tt["mday"], $tt["year"]); + $timemidnight = usergetmidnight(time()); echo "id&user=$user->id\">Contributions
"; - echo "id&user=$user->id&date=$today\">Today's logs
"; + echo "id&user=$user->id&date=$timemidnight\">Today's logs
"; echo "id&user=$user->id\">All logs
"; if (isstudent($course->id, $user->id)) { echo "id&user=$user->id\">Login as
"; -- 2.39.5