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

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Eric-Alexander Schaefer’s picture

This is what my server reports.

> date
Mon Mar 15 20:51:59 CET 2010
> date -u
Mon Mar 15 19:52:03 UTC 2010

Your server reports the UTC time as 2010-03-15 19:52:40 and "localtime" as 2010-03-15 20:52:40 +01:00.

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

Eric-Alexander Schaefer’s picture

Which instructions do you mean?

My system date appears to be set correctly according to the instructions...

criznach’s picture

System time is set to UTC, local time is set to MST, according to the instructions on the scheduler/timecheck page.

Eric-Alexander Schaefer’s picture

The code is correct. From http://www.php.net/manual/en/function.date.php (emphasis is mine):

The optional timestamp parameter is an integer Unix timestamp that defaults to the current local time if a timestamp is not given. In other words, it defaults to the value of time().

Maybe there is something wrong with the PHP config?

jonathan1055’s picture

FileSize
210.12 KB

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

    '%utc' => format_date($now, 'custom', 'l jS F Y, H:i:s', 0), // Use zero offset to return UTC/GMT.

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:

    '%localtime' => format_date(strtotime($lt), 'custom', 'l jS F Y, H:i:s'), // Do not use zero so that any local offset is included.

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

jonathan1055’s picture

Oh, 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:

$ date
Sat Jun  5 09:08:42 BST 2010
$ date -u
Sat Jun  5 08:08:48 GMT 2010
Eric-Alexander Schaefer’s picture

Check #1. Why is my server reporting the correct times?

jonathan1055’s picture

I 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

Eric-Alexander Schaefer’s picture

Status: Active » Needs review
FileSize
968 bytes

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

Eric-Alexander Schaefer’s picture

Status: Needs review » Fixed
jonathan1055’s picture

Thanks Eric.

Status: Fixed » Closed (fixed)

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