]> git.mjollnir.org Git - moodle.git/commitdiff
Fixed a bug: up till now, day boundaries were calculated modulo 86400, which
authordefacer <defacer>
Wed, 2 Jun 2004 09:15:07 +0000 (09:15 +0000)
committerdefacer <defacer>
Wed, 2 Jun 2004 09:15:07 +0000 (09:15 +0000)
is correct only for GMT+0 timezones. Fixed it in upcoming events displays to
separate days as they are in the user's timezone, will continue to pursue this.

calendar/lib.php
calendar/view.php

index 349ad27cd5e8941f57ab7eb2a1a75c326f0d1983..65c4315ec0139fa34d4e41c0e3011503d4b20192 100644 (file)
@@ -278,13 +278,12 @@ function calendar_get_upcoming($courses, $groups, $users, $daysinfuture, $maxeve
 
     $processed = 0;
     $now = time(); // We 'll need this later
-    $nowsecs = $now % SECS_IN_DAY; // this too
-    $nowdays = $now - $nowsecs; // and this
+    $usermidnighttoday = usergetmidnight($now);
 
     if ($fromtime) {
         $display->tstart = $fromtime;
     } else {
-        $display->tstart = usergetmidnight(time());
+        $display->tstart = $usermidnighttoday;
     }
 
     // This effectively adds as many days as needed, and the final SECS_IN_DAY - 1
@@ -316,29 +315,27 @@ function calendar_get_upcoming($courses, $groups, $users, $daysinfuture, $maxeve
 
     if($events !== false) {
         foreach($events as $event) {
-            if($processed >= $display->maxevents) break;
+
+            if($processed >= $display->maxevents) {
+                break;
+            }
 
             $startdate = usergetdate($event->timestart);
             $enddate = usergetdate($event->timestart + $event->timeduration);
-
-            $starttimesecs = $event->timestart % SECS_IN_DAY; // Seconds after that day's midnight
-            $starttimedays = $event->timestart - $starttimesecs; // Timestamp of midnight of that day
+            $usermidnightstart = usergetmidnight($event->timestart);
 
             if($event->timeduration) {
                 // To avoid doing the math if one IF is enough :)
-                $endtimesecs = ($event->timestart + $event->timeduration) % SECS_IN_DAY; // Seconds after that day's midnight
-                $endtimedays = ($event->timestart + $event->timeduration) - $endtimesecs; // Timestamp of midnight of that day
+                $usermidnightend = usergetmidnight($event->timestart + $event->timeduration);
             }
             else {
-                $endtimesecs = $starttimesecs;
-                $endtimedays = $starttimedays;
+                $usermidnightend = $usermidnightstart;
             }
 
-            // Keep in mind: $starttimeXXX, $endtimeXXX and $nowXXX are all in GMT-based
             // OK, now to get a meaningful display...
-
             // First of all we have to construct a human-readable date/time representation
-            if($endtimedays < $nowdays || $endtimedays == $nowdays && $endtimesecs <= $nowsecs) {
+
+            if($event->timestart + $event->timeduration < $now) {
                 // It has expired, so we don't care about duration
                 $day = calendar_day_representation($event->timestart + $event->timeduration, $now);
                 $time = calendar_time_representation($event->timestart + $event->timeduration);
@@ -349,8 +346,8 @@ function calendar_get_upcoming($courses, $groups, $users, $daysinfuture, $maxeve
             }
             else if($event->timeduration) {
                 // It has a duration
-                if($starttimedays == $endtimedays) {
-                    // But it's all on one day
+                if($usermidnightstart == $usermidnightend) {
+                    // But it's all on the same day
                     $day = calendar_day_representation($event->timestart, $now);
                     $timestart = calendar_time_representation($event->timestart);
                     $timeend = calendar_time_representation($event->timestart + $event->timeduration);
index 243eebdf3b5d8615b5b179bd75606821931c3719..e0d5af82348a2a93b343fa4edc41ed6641ccb726 100644 (file)
@@ -227,6 +227,16 @@ function calendar_show_day($d, $m, $y, $courses, $groups, $users) {
         // First, print details about events that start today
         foreach ($events as $event) {
             if ($event->timestart >= $starttime && $event->timestart <= $endtime) {  // Print it now
+
+/*
+                print_object($event->time);
+
+                $dayend = calendar_day_representation($event->timestart + $event->timeduration);
+                $timeend = calendar_time_representation($event->timestart + $event->timeduration);
+                $enddate = usergetdate($event->timestart + $event->timeduration);
+                // Set printable representation
+                echo calendar_get_link_tag($dayend, CALENDAR_URL.'view.php?view=day'.$morehref.'&amp;', $enddate['mday'], $enddate['mon'], $enddate['year']).' ('.$timeend.')';
+*/
                 unset($event->time);
                 calendar_print_event($event);