today is always displayed in GMT calendar

ec - November 22, 2006 - 20:35
Project:Calendar
Version:5.x-1.x-dev
Component:Code
Category:bug report
Priority:critical
Assigned:Unassigned
Status:active
Description

whatever settings I choose my today is always displayed one day later in a view using the calendar display. for example nov 22 -> nov 23. I guess that we shouldn't add 86400 here :

             if ($user_offset < 0) {
         $date = ($date - $now) <= $user_offset ? $date : intval($date - 86400);
       }
       else {
         $date = ($date - $now) >= $user_offset ? $date : intval($date + 86400);
       }

but I don't quite understant why !

regards,
eric

#1

KarenS - November 24, 2006 - 13:09

This is related to a long-standing bug in the event module that displays dates one day off in the calendar. I tried to compensate for that problem but haven't yet found quite the right solution. I need to know the following:

1) What timezone is your site set to?
2) What timezone is set in your user profile?
3) What timezone is your server using? (if you host your own web site, it's probably the same as your site. If you are on a shared host, it will be the timezone where your host is located).

#2

mikey_p - January 8, 2007 - 08:07
Version:4.7.x-1.x-dev» 5.x-1.x-dev

I'm getting the same error, but only in the EVENT view such as drupal/event or the calendar event block. The view at drupal/calendar is fine.

My timezone is set to GMT -0800 and date_default_timezone is set to '-28800'.
User timezones is disabled.
This is off my localhost which is set to the same timezone (GMT -0800).

I don't know if the version of Event I'm using is relevant, but it's the latest head, v 1.215 2006/12/17.

-Mike

#3

mikey_p - January 10, 2007 - 07:22

Further, I've noticed that it's only part of the day, seemingly the first half. I haven't noticed exactly when the it changes to being a day ahead in the event views, but at say 0800 hours, it's fine, and when i've checked it at 1800 or 2200, the event calendar view is highlighting the next day, while the regular calendar view does not.

#4

davidjmcq - January 10, 2007 - 07:56

Same problem: V.5, calendar 5.x-1.0-beta downloaded a couple of hours ago,
Calendar page view
timezone: Wednesday, 10 January, 2007 - 18:49 +1100
server host clock: 18:49 timezone Sydney (+1100)
client is also server.
calendar shows 11th.

#5

amanire - January 11, 2007 - 00:12

I have the same problem and I'm not using the event module. It's two days ahead for me, though.

#6

gordon - January 11, 2007 - 03:49

I am having the same issue at a site, but in the morning it is correct, and the afternoon, it is ahead 1 day.

Check http://homemods.info/training/calendar

Thanks

#7

KarenS - January 12, 2007 - 12:53

I just made some commits that I hope will fix this. You can reopen if not. You can get the commit from the cvs repository or wait for the nightly snapshot to update tonight.

#8

KarenS - January 12, 2007 - 12:55
Status:active» fixed

#9

gordon - January 13, 2007 - 05:01

Thanks for this, Can you backport the changes to 4.7?

#10

KarenS - January 13, 2007 - 12:07

All branches were updated.

#11

gordon - January 13, 2007 - 23:47

Thanks, but I am still having the issue on the 4.7 branch in the afternoon (Australian EST +10:00) where the calendar will list the date as being tomorrow.

#12

KarenS - January 14, 2007 - 20:09
Status:fixed» active

Dang it. The event module has the same problem, and there is an issue there that has gone on forever with various solutions that ended up not working. I tried my own solution here which fixed some problems, but apparently not all.

So I guess this is still an open issue :-(

#13

chrissearle - January 18, 2007 - 12:07

If you want another example :) - same issue here - (5.x) all timezones are GMT+1 (that is site and node date fields) - the server is running on GMT. Events not installed - this is on calendar view

#14

lbn.kiev.ua - January 18, 2007 - 12:19

well, looks like I solve this problem... try this:

replace function calendar_user_date (in modules/calendar/calendar_api.inc) to this one:

function calendar_user_date($part = 'timestamp') {
  global $user;
  static $date;
  if (!$date) {
    $now = calendar_user_time();

    if (variable_get('configurable_timezones', 1) && $user->uid && strlen($user->timezone)) {
      $user_offset = $user->timezone;
    }
    else {
      $user_offset = variable_get('date_default_timezone', 0);
    }

    $now += $user_offset;
    $date = gmmktime(0, 0, 0, gmdate('m', $now), gmdate('j', $now), gmdate('Y', $now));
  }
  switch ($part) {
  case ('year'):
    return gmdate('Y', $date);
  case ('month'):
    return gmdate('m', $date);
  case ('day'):
    return gmdate('j', $date);
  case ('hour'):
    return gmdate('H', $date);
  case ('minute'):
    return gmdate('i', $date);
  case ('week'):
    return gmdate('W', $date);
  default:
    return $date;
  }
}

at least, for my timezone (+2:00) it works correctly

#15

mikey_p - January 21, 2007 - 10:19
Status:active» patch (code needs review)

here's the previous follow up in patch form. I'll have to wait until tomorrow afternoon to fully test it.

AttachmentSize
calendar_api.patch1.66 KB

#16

appel - January 24, 2007 - 10:56

Seems to have worked for me. Thanks!

#17

chrissearle - January 24, 2007 - 11:12

Yep - here too.

#18

KarenS - January 29, 2007 - 01:00
Status:patch (code needs review)» fixed

Well my solution wasn't working, so we'll give it a try. Thanks! Patch committed to all branches.

#19

mikey_p - January 30, 2007 - 03:25
Status:fixed» patch (code needs work)

sorry to be away for so long, but patch from #14 has no change for me

#20

KarenS - January 30, 2007 - 12:35
Status:patch (code needs work)» active

This has been committed, it is no longer a patch. Did you try this on the latest version after the patch was committed? If so and it still does not work, more info is needed since this is working for other people, including me.

What timzone are you (the user) set to? Double check your user record to be sure. I thought I had not set up a timezone for myself but it got set to GMT when I made another change to my user record, which screwed me up until I figured it out.

What timezone is the server set to?

What timezone have you set up your drupal site to use as the site timezone?

#21

mikey_p - February 1, 2007 - 02:59

Timezone is set to GMT -800, date_default_timezone is "-28800" Configurable time zones is disabled, and enabling it and setting it to the same value for the user results in no change.

From the server date, echos the correct time labeled as PST, which correleates to the -800 setting in drupal and "-28800" as in date_default_timezone. Result is same when tested from localhost.

Site is at http://mikeyp.net/drupal-5.1/ see blocks in left hand column for example. Current site code can be found at http://svn.mikeyp.net/public/mikeyp.net/trunk/drupal-5.1/ and you can login as admin/admin at site and devel is enabled to check the various timeone variables if you wish.

Hope this helps, I've grabbed the latest HEAD of calendar and event, and this is still occuring. Is there anything else you need to know to check this out?

-Mike

#22

Bud Wellington - February 1, 2007 - 05:04

I'm in the -6:00 timezone. The date seems to be changing about 10:00 pm... but it may be happening earlier. I'll try to catch the moment if I can. If there's any information I can provide that would be helpful, please let me know. Thanks.

#23

KarenS - September 15, 2007 - 10:58

Reported again at http://drupal.org/node/175787. This is probably not going to go away until I get the new Date API completely functional since this is a timezone conversion issue and the new API is designed to address that.

#24

KarenS - September 15, 2007 - 11:14

Another report at http://drupal.org/node/147386 has some useful research into reasons why, but the ultimate fix for this will be the new Date API.

#25

KarenS - October 5, 2007 - 13:52

Also reported at http://drupal.org/node/138397.

#26

jvalletto - November 16, 2007 - 04:37
Status:active» patch (code needs review)

Karen,

I'm wondering if a temporary fix could be applied for the current dev version. I was searching myself for a way to fix it temporarily, and seemed to have found a good fix.

Change:

<?php
function calendar_user_date($part = 'timestamp') {
  global
$user;
  static
$date;
 
calendar_load_date_api();
  if (!
$date) {
   
$now = date_time();
?>

To:

<?php
function calendar_user_date($part = 'timestamp') {
  global
$user;
  static
$date;

// Use user's timezone if set, if not default to site timezone
$timezone = $user->timezone ? $user->timezone : variable_get('date_default_timezone', 0);

 
calendar_load_date_api();
  if (!
$date) {
   
$now = date_time() + $timezone;
?>

Sorry it's not in a patch, have no experience with creating those.

Again, it seems to work for me, whether configurable user timezones are on or off.

Thanks,
Jeremy.

#27

bkenro - November 30, 2007 - 17:28

I also encountered a similar behavior (node's date and today's highlighing being off) when I created a simple calendar view without creating any date field.
I used:
Drupal 5.3
Views 5.x-1.6
Calendar 5.x-1.7
Date 5.x-1.7.
xampplite 1.6.2 for Windows (Apache 2.2.4, MySQL 5.0.45, PHP 5.2.3)

In this situation, variable_get() in line 227 of calendar.module seems to fail to get the value of 'date_default_timezone_name' because there's no corresponding record in the 'variable' table.

$timezone = variable_get('date_default_timezone_name', 'UTC');

As a result, $timezone varible always get to be 'UTC' and the calendar displays the dates on the assumption of GMT.

After adding a date field to any data type (for example, Page or Story) and setting the "Site timezone:" parameter to my own in the setting page of the date field, it was reflected on the $timezone value and the problem was solved.

In addition, when I added another date field somewhere and set its "Site timezone" parameter to a different value, the new value was also reflected on the first date field's setting. It seems that the default timezone is only based on the 'date_default_timezone_name' record in the variable table, and it has no relation to the site's timezone (set in /admin/settings/date-time) nor the date.timezone value in php.ini.

I think this behavior is somewhat confusing and I guess it may be one of the causes of the problem if similar situation.

#28

bkenro - December 1, 2007 - 13:06

Correction
Previous post did not have direct relation to the today's highlighting problem.
I could finely solve the problem by #26 (thanks!), but not by above operation.
It only solves the display of node's dates in the same situation (not today's highlighting).

Sorry for confusion.

#29

jvalletto - December 3, 2007 - 03:15
Priority:normal» critical
Status:patch (code needs review)» patch (reviewed & tested by the community)

I'm going to mark this RTBC, as it seems to work pretty well for the above issue, without causing any noticeable problems.

#30

New Zeal - December 10, 2007 - 02:21
Version:5.x-1.x-dev» 5.x-1.7

I solved the problem using the code from #14 but with time() instead of calendar_user_time() since that is the server time and calendar_user_time() does not exist in this version.

Thanks ibn.kiev

#31

JohnAlbin - December 10, 2007 - 02:53
Title:today is always displayed one day later in the view using calendar» today is always displayed in GMT calendar
Status:patch (reviewed & tested by the community)» patch (code needs review)

Jeremy, thanks for pointing us in the right direction! That's definitely a working solution.

However, it's bad form to mark your own patches as RTBC. Let someone else review it and mark it RTBC. Especially since there was a bug in your code. ;-)

I borrowed the timezone offset code from calendar_event_date(), so this should work with the various tz options.

(Also, I changed 3 tabs into spaces.)

AttachmentSize
now_tz_fix.patch1.64 KB

#32

jvalletto - December 10, 2007 - 04:45

Sorry. My bad. Never done this type of thing before, but I'm glad I could at least point you in the right direction.

Jeremy.

#33

james.t - December 14, 2007 - 18:14

i kind of have a similar problem as this but it's not only the "Today" date but it's also when i setup an all day event from ical it spans over two days

If something is happening on the 13th and marked an all day event it goes from the 13th to the 14th and is marked as all day for both days.
Is there any fix for that?

#34

llslim - December 28, 2007 - 05:14

I had the same problem and solved it with the following 2 lines of code which does the same as the patch of johnAlbin in #31 but in a more compact way without the redundant user uid check. Whole calendar_user_date function to follow.

<?php
function calendar_user_date($part = 'timestamp') {
  global
$user;
  static
$date;
 
calendar_load_date_api();
  if (!
$date) {
   
$now = date_time();
   
   
/*
     * use the user configured timezone as time offset if user timezone is not empty and
     * configurable_timezone is enabled, otherwize use the default timezone from the site.
     */
   
$now += (variable_get('configurable_timezone',0) && !empty($user->timezone)) ?
            
$user->timezone : variable_get('date_default_timezone',0);
            
   
$date = date_gmmktime(array(
     
'mon' => date_format_date('m', $now),
     
'mday' => date_format_date('j', $now),
     
'year' => date_format_date('Y', $now),
      ));
  }
  switch (
$part) {
  case (
'year'):
    return
date_format_date('Y', $date);
  case (
'month'):
    return
date_format_date('m', $date);
  case (
'day'):
    return
date_format_date('j', $date);
  case (
'hour'):
    return
date_format_date('H', $date);
  case (
'minute'):
    return
date_format_date('i', $date);
  case (
'week'):
    return
date_format_date('W', $date);
  default:
    return
$date;
  }
}
?>

Hope this helps.

#35

JohnAlbin - January 3, 2008 - 18:00
Version:5.x-1.7» 5.x-1.x-dev
Status:patch (code needs review)» active

I believe the patch to the date_time() function in date module's issue queue will fix this issue: http://drupal.org/node/206009

#36

KarenS - January 31, 2008 - 11:05
Status:active» fixed

This is fixed (I think) in the 5.2 versions of Date and Calendar.

#37

WisTex - February 5, 2008 - 14:38

I have the latest stable releases for calendar, date, etc., and it is not fixed. Calendar still thinks the time of day is GMT, despite settings in Drupal otherwise. A perfect example of the problem is after 6 p.m., the calender says it is tomorrow, because we are GMT -6 and 6 p.m. is midnight GMT.

This also effects Views as well. And the documentation is not clear on how to specify "Now minus 6 hours" or "Now GMT - 6" to rectify the problem without recoding the module.

A patch for the Date module has been submitted (http://drupal.org/node/206009) but that appears to be pending inclusion as of this posting.

#38

WisTex - February 5, 2008 - 14:52

I kind of have a similar problem as this but it's not only the "Today" date but it's also when i setup an all day event from ical it spans over two days

If something is happening on the 13th and marked an all day event it goes from the 13th to the 14th and is marked as all day for both days.
Is there any fix for that?

I had a similar problem. What that turned out to be is the time zone in your profile was not the same time zone you were in. So the calendar was nice enough to adjust the times to your time zone, which I am not sure is how it should work, especially since events are typically at a specific location with a local time zone (unless they are virtual events).

How I solved that particular problem was by going into my user profile while logged in and changing my time zone (My Account | Edit). Also, make sure Drupal's time zone is set to the correct time zone as well (Administer | Date and Time).

Now that won't fix the problem of the Calendar using GMT, but that will fix the problem of the events having the wrong times for events that you added yourself. iCal events appear to always use GMT, which means they are always 6 hours off in my case. I cannot use the iCal module as a result. Not sure if that is related to the same problem that causes the calendar to display in GMT only.

#39

JohnAlbin - February 5, 2008 - 16:05
Status:fixed» active

Karen, I’m hoping this is fixed in 5.x-2.x as well.

But since that is un-released (not even a beta release), you should leave this issue open. And, in my opinion, if its going to be a while before 5.x-2.x is released, this issue should get fixed in the 5.x-1.x branch.

#40

cubbtech - March 7, 2008 - 18:22

Subscribing

#41

dgtlmoon - April 3, 2008 - 07:54

still active in 1.7x

#42

ttttttttt08 - April 11, 2008 - 23:00

Has anyone looked at themeing this in template.php? For my calendar, The dates display properly on the node or in the list/ teaser views but not on the calendar. This theme gets called what about just setting the date by refrence?

function mytheme_date_display_combination($field, &$dates, $node=null)
{
}

#43

ttttttttt08 - April 11, 2008 - 23:02

Has anyone looked at themeing this in template.php? For my calendar, The dates display properly on the node or in the list/ teaser views but not on the calendar. This theme gets called what about just setting the date by refrence?

function mytheme_date_display_combination($field, &$dates, $node=null)
{
if(arg(0) == 'calendar') {}
}
Thanks!

#44

Mukesh Dubey - July 17, 2008 - 08:24

Hi,

I am using application based on struts. In this, display time block 8:00AM to 5:30 PM in which we take appointment.I have to implement Time Zone(GMT) .

When any body working late (9pm, 10pm, etc), then available time blocks on the search page for earlier times in the day (6pm, 7pm, etc), times that have actually already passed. We want to make sure we correctly display available time blocks.

I am in Asia/Calcutta Time Zone Id.

Waiting for reply.

Thanks,
Mukesh

 
 

Drupal is a registered trademark of Dries Buytaert.