Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
My server and several others in the issue queue are showing the same value for UTC and local dates on the scheduler/timecheck page.
My system date appears to be set correctly according to the instructions...
# date
Fri Mar 12 10:46:35 MST 2010
# date -u
Fri Mar 12 17:47:08 UTC 2010
Following the code, I see this:
in _scheduler_timecheck, line 539
$now = time();
which gets passed to theme_scheduler_timecheck, and formatted on line 552
$t_options = array(
'%time' => date("Y-m-d H:i:s", $now),
'%lt' => $lt,
);
Looking at the php docs, time() returns the system time, but date() converts it to local time.
I believe this should be using gmdate() instead of date().
Comment | File | Size | Author |
---|---|---|---|
#9 | scheduler_module_1_50_2_36-0.txt | 968 bytes | Eric-Alexander Schaefer |
#5 | timecheck old and new.jpg | 210.12 KB | jonathan1055 |
Comments
Comment #1
Eric-Alexander Schaefer CreditAttribution: Eric-Alexander Schaefer commentedThis is what my server reports.
One of the servers is lying.
I need to think about this or a while. I have forgotten all about it (timezone issues are the reason for some if not most of my gray hair ;-)
Comment #2
Eric-Alexander Schaefer CreditAttribution: Eric-Alexander Schaefer commentedWhich instructions do you mean?
Comment #3
criznach CreditAttribution: criznach commentedSystem time is set to UTC, local time is set to MST, according to the instructions on the scheduler/timecheck page.
Comment #4
Eric-Alexander Schaefer CreditAttribution: Eric-Alexander Schaefer commentedThe code is correct. From http://www.php.net/manual/en/function.date.php (emphasis is mine):
Maybe there is something wrong with the PHP config?
Comment #5
jonathan1055 CreditAttribution: jonathan1055 commentedHi Eric,
Yes, I had noticed this problem too. Getting $now from time() is correct, but it is how it is formatted for display on the page where the error occurs. The UTC display uses the date() function which does convert the display to the local time, which is not what is required. If we used the drupal function format_date we could include a fourth parameter of zero, to make the display use no timezone offset and hence show UTC correctly. I used:
The local time I think is accurate but formatted just with the strings simply concatenated together. This means that hours, minutes
and seconds of single digit values look odd. The string can be read using strtotime and the same drupal format_date() called but this time without the 4th param of zero, so that local settings are taken into account:
The attached screen shot show the results. I am in the UK, and so local time is currently one hour ahead of GMT. I get the correct answers now, but I'd like to see what someone not in the UK gets, as I'm not sure of this. I can provide more code here if required.
Jonathan
Comment #6
jonathan1055 CreditAttribution: jonathan1055 commentedOh, and in case you notice the tabs, I was just working on a patch to add these tabs to the admin page. I'll post that as a separate suggestion, as I was going to submit it all together, but then noticed this timecheck issue already open.
Just after the screen grab was taken, the date functions gave:
Comment #7
Eric-Alexander Schaefer CreditAttribution: Eric-Alexander Schaefer commentedCheck #1. Why is my server reporting the correct times?
Comment #8
jonathan1055 CreditAttribution: jonathan1055 commentedI noticed that it seemed OK for you, and was slightly baffled by it.
Also your 'localtime' string was formatted "2010-03-15 20:52:40 +01:00" but the code in the current scheduler module does not append the +01:00, so this might seem like a dumb question but are we running different versions? I am using scheduler 1.7 and this timecheck code has not changed changed since 1.3 at least. I'm sure its not a version issue, but worth asking. Were there any patches for this bit of code?
There are two things which affect what we think of as 'local time' (1) the timezone we are in, (2) whether that timezone is in daylight saving mode or not. The localtime as shown on the timecheck page was not taking daylight saving into account, but maybe it is not intended to, in which case my suggestion above can be discarded.
This is curious, I'll do some more research into this.
Jonathan
Comment #9
Eric-Alexander Schaefer CreditAttribution: Eric-Alexander Schaefer commentedI found it. I just realized that I did not look up the timecheck result on a D6 site, but on a D5 site. The problem was already reported here: #221330: Timecheck function not reporting actual times and it was fixed. But that happend after the D6 version was branched off.
Please try the attached patch.
Comment #10
Eric-Alexander Schaefer CreditAttribution: Eric-Alexander Schaefer commentedhttp://drupal.org/cvs?commit=398534
Comment #11
jonathan1055 CreditAttribution: jonathan1055 commentedThanks Eric.