php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #39805 DateTimeZone::getOffset($object) result strange
Submitted: 2006-12-12 07:30 UTC Modified: 2007-07-11 18:28 UTC
Votes:2
Avg. Score:3.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: liber at iproom dot com Assigned:
Status: Closed Package: Documentation problem
PHP Version: 5.2.0 OS: Windows XP
Private report: No CVE-ID: None
 [2006-12-12 07:30 UTC] liber at iproom dot com
Description:
------------
DateTime class already has a getOffset to returns DST offset. But DateTimeZone has a parameter of DateTime, the result still returns only the DateTimeZone DST offset itself ? Should not it returns the offset between the DateTimeZone and the given parameter of DateTime ?

Reproduce code:
---------------
$dateTimeZoneTaipei = new DateTimeZone("Asia/Taipei");
$dateTimeZoneJapan = new DateTimeZone("Asia/Tokyo");

$dateTimeTaipei = new DateTime("now", $dateTimeZoneTaipei);
$dateTimeJapan = new DateTime("now", $dateTimeZoneJapan);

$timeOffset = $dateTimeZoneJapan->getOffset($dateTimeTaipei);
var_dump($timeOffset);


Expected result:
----------------
int(3600)

Actual result:
--------------
int(32400)

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-12-12 07:34 UTC] liber at iproom dot com
timezone_offset_get() has the same problem.
 [2006-12-12 12:22 UTC] derick@php.net
This is expected behavior, but the documention on this function is vague. I updated the documentation in the online manual which should be online somewhere during this week.
 [2006-12-12 15:51 UTC] liber at iproom dot com
It should not be a documention error,
because DateTime already has a getOffset function, and it does not need any parameter.
But why DateTimeZone also provide a getOffset and it NEEDs a parameter, but returns the same result as DateTime::getOffset ?
It does not make sense.
 [2007-07-11 18:28 UTC] derick@php.net
It's not a bug, as the ->getOffset() does not calculate the office between the two timezones, but the offset to GMT. This is also mentioned in the documentation:

http://no2.php.net/manual/en/function.timezone-offset-get.php
 [2020-02-07 06:10 UTC] phpdocbot@php.net
Automatic comment on behalf of derick
Revision: http://git.php.net/?p=doc/en.git;a=commit;h=5101df15151e3a083509856fef661f0fa2f3d706
Log: - Fixed bug #39805: Make these docs less vague.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Sat Jul 19 23:00:03 2025 UTC