The "current day" for the event calendar is off by a day.
Vanhail - April 17, 2008 - 04:44
| Project: | Event |
| Version: | 5.x-1.0 |
| Component: | Code |
| Category: | support request |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | active |
Description
The event calendar somehow picks up what the current day is and uses it to display todays events by default and to style today differently with CSS. The "current day" shown on my calendar is always a day ahead of what it really is supposed to be. To be more exact around late afternoon the day switches to the next day.
I've checked the time my server is set to and it is correct for the region it resides in, I have also checked the Drupal system time and it is correct, and I even have the Event Module set to use the sitewide time zone.
Anyone know what could be causing this?

#1
subscribe
#2
Check your site's timezone setting. If you have not set your site's timezone setting but your server (out of your control) has a timezone setting, then the day will change at the wrong time. Either set your site's timezone or change this function in event.module to the following so it ignores your server's timezone (remove the date("Z") stuff):
<?php
function _event_user_time() {
global $user;
if (variable_get('configurable_timezones', 1) && $user->uid && strlen($user->timezone)) {
return (time()) + $user->timezone;
}
else {
return (time()) + variable_get('date_default_timezone', 0);
}
}
?>
#3
This is a bug in the event module for version: 5.x-1.0. I assume it's been around for earlier versions. Pretty big bug in my opinion, dates need to be correct for an event module to be valid.
I have attached the patch, I just manually added the code and it worked for me. This thing drove me nuts.
BTW, I've seen this in multiple threads with no answer, so I'm posting this message in all of them. Blasted bug.
#4
I applied the patch (actually I edited the code manually), but it made no change. My calendar still shows the wrong day.
If I go to administer date and time, the little previews show the wrong information as well. I checked my server and it is set to the correct date. So the question is where is the date being pulled from? Where can I set it?
Thanks.
#5
Hello,
I have tried the solutions outlined in the above posts from Vanhail and Lynn and both seem to work for me... Kind of.
My timezone is GMT + 10 hours. Checked the server time, and the site wide Drupal time, both are correct.
Before applying either of these proposed patches, my event calendar was showing yesterday as the current day, highlighted in red.
If I apply either of these patches, it seems to start highlighting today as the current day in red, BUT still highlights yesterday in blue (when looking at the month view).
Can anyone comment on why it's highlighting yesterday in blue, and how I could stop this from happening?
I see that it is adding a 'selected' CSS class to yesterday, which I assume is the CSS class that makes yesterdays box blue... I guess I could always just mess with this style, or stop it from being applied somehow, but I don't know if this is a good solution... What does this 'selected' style usually signify?
Also, this is probably a really n00b question, but I see people posting "subscribe" in this thread... Is there some way to subscribe to this thread? Is that what this means?
Any assistance much appreciated.
EDIT: Found the subscribe feature... yay.
#6
Subscribing...
#7
I suggest to try the 5.x-2.x-dev version. Don't forget to backup your data.
#8
Thanks Vanhail! - worked for me.
#9
...
#10
I went with Lynn's suggestion and that worked for me.
What I found was for this line:
return (time() - date("Z")) + variable_get('date_default_timezone', 0);time() -- returns seconds since epoch
date("Z") -- returns -18000 for me or -5 hours for US Central time
variable_get('date_default_timezone', 0) -- returns -18000 also.
So essentially it is subtracting -18000 (same as adding 18000) to time(), then it adds -18000 (same as subtracting it), so what I end up with is the original value of time() anyways, which is UTC time not counting for my TZ offset.
I'm not sure if this is an issue with the math or TZ settings or just bad logic...
Any thoughts? Either way, removing the date("Z") returns the correct value, so thanks Lynn.
I am now using this line:
return (time() + variable_get('date_default_timezone', 0));#11
Thanks jasonsbytes, that worked for me :)
Even though my server was set to the right timezone, user TS, and even enabling/disabling configurable timezones didn't fix it... calendar was always showing the current day 1 day behind.
Sack
#12
Turns out my calendar had user definable time zones enabled. This was causing all sorts of wonkyness. I took that settings off and then was able to set the system time correctly.
#13
Is active development taking place on the events module? It seems very buggy - I've never gotten it working properly and now if I so much as enable the events module my whole site goes down. I've dumped the tables (the module had mangled all of the dates on every event anyway) and I still can't even get it to enable.
I've lost a year's worth of events on a production site now and have no way of getting things working again...
#14
I did something similar, so if jasonsbytes' didn't work for you then try this. Its a little more work. My problem was that everyday at 9pm, the event calendar display would go to the next day. So this meant the event system thought my time was +3 hours ahead of what it actually was. So what I did was:
1. looked in event_timezones.inc (function event_get_timezones) for a timezone that is 3 hours ahead of mine (I'm on the east coast, so I chose Los Angeles). The offset for LA is -28800.
2. used the -28800 offset in the code change below in event.module:
<?php
function _event_user_time() {
global $user;
if (variable_get('configurable_timezones', 1) && $user->uid && strlen($user->timezone)) {
return (time() - date("Z")) + $user->timezone; // i don't allow users to configure timezones, so I didn't change this piece
}
else {
//return (time() - date("Z")) + variable_get('date_default_timezone', 0); // original code
return (time() - date("Z")) - 28800; // my hardcoded timezone offset
}
}
?>
Everything works great now. Someone proposed a similar idea in another issue, but I can't find it or else I'd link it here. I'll try jasonsbytes' idea later when I get a dev site set up.
#15
Just wanted to also report that jasonsbytes solution worked for me.
Thanks!
#16
One thing I have noticed with the timezone issues (US Eastern) is that there is an issue with the DST (daylight savings time). I have a list of events with dates/times and everything is great until you get to november, then everything is off by an hour. This is after i've added the code to compensate for the date_default_timezone. Anyone have any ideas how to go about correcting this? It seems to me that most of the issues are with the fact that event is doing timezones and date is doing timezone.
Thanks,
Shane