php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #61171 Ambiguous 'timezone' parameter description causes hair-pulling
Submitted: 2012-02-23 18:54 UTC Modified: 2012-11-15 09:38 UTC
From: chichilatte at gmail dot com Assigned: krakjoe (profile)
Status: Closed Package: Date/time related
PHP Version: Irrelevant OS:
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: chichilatte at gmail dot com
New email:
PHP Version: OS:

 

 [2012-02-23 18:54 UTC] chichilatte at gmail dot com
Description:
------------
---
From manual page: 
http://www.php.net/datetime.construct#refsect1datetime.construct-parameters
---
The timezone parameter is described as "A DateTimeZone object representing the 
desired time zone". This is really ambiguous, since it depends on the user's 
motivation for creating the DateTime object. For instance, I wanted to display a 
UTC date string as a UK date string, so my "desired" timezone was 
"Europe/London". That's not how it works, but because it says "desired", that's 
how it sounds like it works. 

This sounds insignificant really, but I wasted an hour figuring out why it 
wasn't working (date problems are tough because dates are affected by absolutely 
everything in a system!), and I'm sure many other people have encountered the 
same problem.

I suggest the timezone parameter should be described as "A DateTimeZone object 
representing the timezone of the time parameter".

Thanks!





Test script:
---------------
// What someone would do who "desired" to convert a date from UTC to UK time...

$dateTime = new DateTime('2012-05-01 23:00:00UTC', 'Europe/London');
echo $dateTime->format("Y-m-d H:i:s e");
// produces...
// 2012-05-01 23:00:00 UTC

// The actual way to do it...
$dateTime = new DateTime('2012-05-01 23:00:00UTC');
$dateTime->setTimezone(new DateTimeZone('Europe/London'));
echo $dateTime->format("Y-m-d H:i:s e");
// produces...
// 2012-05-02 00:00:00 Europe/London



Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-11-15 09:38 UTC] krakjoe@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: krakjoe
 [2012-11-15 09:38 UTC] krakjoe@php.net
The fix for this bug has been committed.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.

 For Windows:

http://windows.php.net/snapshots/
 
Thank you for the report, and for helping us make PHP better.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 17:01:58 2024 UTC