4

I'm trying to represent a UTC timestamp in different timezones using PHP's date_default_timezone_set function. Daylight saving has just kicked in here (NZ) and in Australia, and I'm getting mixed results...

Here's some test code...

date_default_timezone_set('NZ');
print '<p>NZ time is ' . date('Y-m-d H:i:s T (I)') . '</p>';

date_default_timezone_set('Australia/NSW');
print '<p>NSW time is ' . date('Y-m-d H:i:s T (I)') . '</p>';

date_default_timezone_set('Australia/North');
print '<p>NT time is ' . date('Y-m-d H:i:s T (I)') . '</p>';

date_default_timezone_set('Australia/South');
print '<p>SA time is ' . date('Y-m-d H:i:s T (I)') . '</p>';

From which I get this output...

NZ time is 2014-10-05 14:04:27 NZDT (1)

NSW time is 2014-10-05 12:04:27 EST (1)

NT time is 2014-10-05 10:34:27 CST (0)

SA time is 2014-10-05 11:34:27 CST (1)

Now, the NZ timezone abbreviation is correct (NZDT), and all the Australian times are correct, but the two Australian times where daylight saving is active (as indicated by the php date 'I' format character, which returns a '1' if daylight savings is in place) are still showing the non-DST abbreviation.

Any ideas?

noizy
  • 152
  • 2
  • 12
  • [List of supported Australia timezones](http://php.net/manual/en/timezones.australia.php) for the `date_default_timezone_set` function – 2pha Oct 05 '14 at 01:18
  • Thanks 2pha - I'm using supported timezones for the Australian states in question, and everything _but_ the timezone abbreviation is coming back correctly. – noizy Oct 05 '14 at 01:31
  • Ahh, ic, sorry, I just woke up. Are you sure that the abbreviations are meant to be different? I think they are correct. I don't think the abbreviations will be different just because 1 uses daylight saving time and one does not. – 2pha Oct 05 '14 at 01:57
  • The NZ timezone abbreviation is behaving how I'd expect. Before DST kicked in, it was displaying as NZST. Now it's (correctly) displaying as NZDT. I'd've assumed the Australian timezone abbreviations would behave the same (EST -> EDT), but they're not. Baffled. – noizy Oct 05 '14 at 02:57

1 Answers1

6

A few things:

  • You should prefer the canonical form of the time zone name whenever possible. The zones you mentioned are actually links (aka aliases). Refer to this chart for details. Specifically:

    NZ              => Pacific/Auckland
    Australia/NSW   => Australia/Sydney
    Australia/North => Australia/Darwin
    Australia/South => Australia/Adelaide
    
  • There are actually 5 major regions of Australia with differing time zone rules. You may wish to refer to this Wikipedia article for details.

  • Australia/Darwin (aka, Australia/North) does not observe daylight saving time at all.

  • The other two time zones (Sydney & Adelaide) would indeed be on daylight saving time at the date and time you specified. However, names and abbreviations for Australian time zones have not necessarily been absolutely clear. For example, Sydney's daylight name has been referred to by all of the following:

    • Eastern Summer Time (EST)
    • Australian Eastern Summer Time (AEST)
    • Eastern Daylight Time (EDT)
    • Australian Eastern Daylight Time (AEDT)

  • PHP pulls its time zones from the IANA time zone database. Time zone abbreviations are also taken from the same source. For a very long time, this data set used the ambiguous abbreviation of "EST" for both Eastern Standard Time and Eastern Summer Time.

  • This was changed recently, in version 2014f. You can read the details in the release notes. It now uses AEST for standard time, and AEDT for daylight time.

  • You can get this change by updating PHP's timezonedb to version 2014.6 or greater. You can find instructions for updating here or here.

  • Alternatively, you can just update to the latest version of PHP. Based on the release dates, I think PHP version 5.3.29 should have shipped with timezonedb 2014.6. Use that version or newer and you should get the new abbreviations.

  • You can also call timezone_version_get() to see what version of timezonedb you have. It should be 2014.6 or greater to receive the new abbreviations.

Matt Johnson-Pint
  • 230,703
  • 74
  • 448
  • 575
  • Brilliant. Thanks @Matt. My staging server is running 2013.9, and haven't been able to release files to the production server to check yet, bu I assume it's on a similar release. I'll get the server admins to get onto those timezonedb updates (and will give you a big tick once the issue is resolved!) Cheers. – noizy Oct 06 '14 at 00:18
  • (Incidentally, the staging server is running PHP 5.4.25, and _not_ reporting those DST timezones back correctly). – noizy Oct 06 '14 at 00:50
  • I'm not exactly certain which versions of timezonedb ship with which versions of PHP. I thought it was updated to the current with each build, but I could be mistaken. – Matt Johnson-Pint Oct 06 '14 at 00:52
  • 1
    Success! Used PECL to install the latest timezonedb package, and everything kicked in. Magic. Thanks again, @matt. – noizy Oct 06 '14 at 00:55