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
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
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: Thu Nov 07 04:01:28 2024 UTC