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

CommentFileSizeAuthor
#31 now_tz_fix.patch1.64 KBJohnAlbin
#15 calendar_api.patch1.66 KBmikey_p
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

KarenS’s picture

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).

mikey_p’s picture

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

mikey_p’s picture

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.

davidjmcq’s picture

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.

amanire’s picture

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

gordon’s picture

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

KarenS’s picture

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.

KarenS’s picture

Status: Active » Fixed
gordon’s picture

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

KarenS’s picture

All branches were updated.

gordon’s picture

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.

KarenS’s picture

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 :-(

chrissearle’s picture

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

lbn.kiev.ua’s picture

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

mikey_p’s picture

Status: Active » Needs review
FileSize
1.66 KB

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

appel’s picture

Seems to have worked for me. Thanks!

chrissearle’s picture

Yep - here too.

KarenS’s picture

Status: Needs review » Fixed

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

mikey_p’s picture

Status: Fixed » Needs work

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

KarenS’s picture

Status: 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?

mikey_p’s picture

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

Bud Wellington’s picture

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.

KarenS’s picture

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.

KarenS’s picture

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.

KarenS’s picture

jvalletto’s picture

Status: Active » 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:

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

To:

 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.

bkenro’s picture

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.

bkenro’s picture

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.

jvalletto’s picture

Priority: Normal » Critical
Status: Needs review » 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.

NewZeal’s picture

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

JohnAlbin’s picture

Title: today is always displayed one day later in the view using calendar » today is always displayed in GMT calendar
Status: Reviewed & tested by the community » Needs review
FileSize
1.64 KB

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.)

jvalletto’s picture

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.

james.t’s picture

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?

llslim’s picture

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.

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.

JohnAlbin’s picture

Version: 5.x-1.7 » 5.x-1.x-dev
Status: 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

KarenS’s picture

Status: Active » Fixed

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

WisTex’s picture

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.

WisTex’s picture

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.

JohnAlbin’s picture

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.

John Bickar’s picture

Subscribing

dgtlmoon’s picture

still active in 1.7x

nickco’s picture

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)
{
}

nickco’s picture

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!

Mukesh Dubey’s picture

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

KarenS’s picture

Status: Active » Fixed

I'm not making changes to the 5.1 version. I'm officially recommending you move to the 5.2 version now. If you have problems in that version you can check for existing issues or add new ones. Feature requests are now getting posted to the D6 version to be back-ported to 5.2.

Timezone handling is much improved in 5.2.

Anonymous’s picture

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for two weeks with no activity.