Index: event.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/event/event.module,v
retrieving revision 1.212
diff -u -r1.212 event.module
--- event.module	14 Oct 2006 01:07:15 -0000	1.212
+++ event.module	13 Nov 2006 04:08:15 -0000
@@ -520,7 +520,7 @@
     for ($x = $start; $x < 7; $x++) {
       $cur_day = (($week * 7) + ($x + 1) - $offset);
       $row[$x] = array(
-        'class' => strtolower("$month_name ". $weekdays[$x]['day'] . ($curstamp == $today ? ' today' : '') . ($cur_day == $day ? ' selected' : '')),
+        'class' => strtolower("$month_name ". $weekdays[$x]['day'] . ($curstamp == $today ? ' today' : '') . ($cur_day == gmdate('j', $today) ? ' selected' : '')),
         'id' => strtolower($month_name . $cur_day),
         'data' => $callback($year, $month, $cur_day, $view, $types, $terms));
       $curstamp += 86400;
@@ -568,7 +568,7 @@
     $month_name = gmdate('M', $stamp);
 
     $row[$x] = array(
-      'class' => strtolower("$month_name ". $weekdays[$x]['day'] . ($stamp == $today ? ' today' : '') . ($cur_day == $day ? ' selected' : '')),
+      'class' => strtolower("$month_name ". $weekdays[$x]['day'] . ($stamp == $today ? ' today' : '') . ($cur_day == gmdate('j', $today) ? ' selected' : '')),
       'id' => strtolower($month_name . $cur_day),
       'data' => event_render_day($year, $month, $cur_day, 'week', $types, $terms));
     $stamp += 86400;
@@ -627,7 +627,7 @@
     $weekdays = event_week_days();
 
     $rows[][] = array('colspan' => 3,
-                      'class' => strtolower("$month_name ". $weekdays[$dow]['day'] . ($stamp == $today ? ' today' : '') . ($cur_day == $day ? ' selected' : '')),
+                      'class' => strtolower("$month_name ". $weekdays[$dow]['day'] . ($stamp == $today ? ' today' : '') . ($cur_day == gmdate('j', $today) ? ' selected' : '')),
                       'id' => strtolower($month_name . $cur_day),
                       'data' => event_render_day($year, $month, $cur_day, 'table', $types, $terms));
     $stamp += 86400;
@@ -1413,10 +1413,35 @@
  * @return integer timestamp
  */
 function _event_user_date() {
+  global $user;
   static $date;
   if (!$date) {
     $now = _event_user_time();
     $date = gmmktime(0, 0, 0, gmdate('m', $now), gmdate('j', $now), gmdate('Y', $now));
+  
+    // _event_user_date calculates the user's date at midnight GMT
+    // and is used to check for matches against daily midnight timestamps when creating calendars
+    // since the timestamp is always compared against a midnight GMT timestamp
+    // there will be periods of time when the user will be in a different day than GMT
+    // the length of that period of mismatch is the same as the user's offset in seconds
+    // for timezones with negative offsets, that will be late in the user's day
+    // for timezones with positive offsets, that will be early in the user's day
+    // calculate the times when there will be a discrepancy and add or subtract a day to adjust
+
+    $user_seconds = intval(date('h', $date) * 3600) + intval(date('i', $date) * 60);
+    
+    if (variable_get('configurable_timezones', 1) && $user->uid && strlen($user->timezone)) {
+      $user_offset = $user->timezone;
+    }
+    else {
+      $user_offset = variable_get('date_default_timezone', 0);
+    }
+    if ($user_offset < 0) {
+      $date = $user_seconds <= $user_offset ? $date : intval($date - 86400);
+    }
+    else {
+      $date = $user_seconds >= $user_offset ? $date : intval($date + 86400);
+    }
   }
   return $date;
 }
