Doc #63415 [Opn->Csd]: Code example incorrect
| From: | mike at mikehoward dot com dot au | Date: | Sun, 04 Nov 2012 23:13:26 +0000 |
| Subject: | Doc #63415 [Opn->Csd]: Code example incorrect | ||
| References: | 1 | Groups: | php.doc.bugs |
| Request: | Send a blank email to doc-bugs+get-9055@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=63415&edit=1
ID: 63415
User updated by: mike at mikehoward dot com dot au
Reported by: mike at mikehoward dot com dot au
Summary: Code example incorrect
-Status: Open
+Status: Closed
Type: Documentation Problem
Package: Documentation problem
Operating System: not relevant
PHP Version: Irrelevant
Block user comment: N
Private report: N
New Comment:
I'm sorry - I was using the getOffset method of a DateTime object - thanks for the
quick response.
Previous Comments:
------------------------------------------------------------------------
[2012-11-03 00:44:30] mail+php at requinix dot net
I think you're confused. There are two getOffset() methods: one in DateTimeZone
which requires a DateTime argument, and another in DateTime which takes no
arguments.
The example you're quoting works fine for me (5.3.10).
------------------------------------------------------------------------
[2012-11-01 23:45:17] mike at mikehoward dot com dot au
Description:
------------
---
From manual page: http://www.php.net/datetimezone.getoffset#refsect1-
datetimezone.getoffset-examples
---
The example for getOffset says:
// Calculate the GMT offset for the date/time contained in the $dateTimeTaipei
// object, but using the timezone rules as defined for Tokyo
// ($dateTimeZoneJapan).
$timeOffset = $dateTimeZoneJapan->getOffset($dateTimeTaipei);
This is not correct. You can't pass a DateTime object when used this way.
Test script:
---------------
// This is not a test script - this is a suggestion to replace the current example
// Create a timezone object
$dateTimeZoneSyd = new DateTimeZone("Australia/Sydney");
// Create a DateTime object (it's daylight savings time now - 2012-11-02)
$dateTimeSydney = new DateTime("now", $dateTimeZoneSyd);
// Calculate the GMT offset for the date/time contained in the object
$timeOffset = $dateTimeSydney->getOffset();
// Should show int(39600).
var_dump($timeOffset);
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=63415&edit=1