From 9d567178e2f1ed6a8b6225c55f55569dc18952fa Mon Sep 17 00:00:00 2001 From: defacer Date: Wed, 2 Jun 2004 09:15:07 +0000 Subject: [PATCH] Fixed a bug: up till now, day boundaries were calculated modulo 86400, which 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 | 29 +++++++++++++---------------- calendar/view.php | 10 ++++++++++ 2 files changed, 23 insertions(+), 16 deletions(-) diff --git a/calendar/lib.php b/calendar/lib.php index 349ad27cd5..65c4315ec0 100644 --- a/calendar/lib.php +++ b/calendar/lib.php @@ -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); diff --git a/calendar/view.php b/calendar/view.php index 243eebdf3b..e0d5af8234 100644 --- a/calendar/view.php +++ b/calendar/view.php @@ -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.'&', $enddate['mday'], $enddate['mon'], $enddate['year']).' ('.$timeend.')'; +*/ unset($event->time); calendar_print_event($event); -- 2.39.5