php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #32820 date_sunrise and date_sunset don't handle GMT offset well.
Submitted: 2005-04-25 06:24 UTC Modified: 2006-01-04 22:40 UTC
Votes:4
Avg. Score:5.0 ± 0.0
Reproduced:3 of 3 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: matt-dated-1114405650 dot e8a5a2 at codewalkers Assigned: derick (profile)
Status: Closed Package: Date/time related
PHP Version: 5CVS-2005-04-25 (dev) 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: matt-dated-1114405650 dot e8a5a2 at codewalkers
New email:
PHP Version: OS:

 

 [2005-04-25 06:24 UTC] matt-dated-1114405650 dot e8a5a2 at codewalkers
Description:
------------
There seems to be a bug in date_sunrise and date_sunset when the GMT offset is greater than the sunrise or sunset time.

For instance, if the date_sunset function returns '00:14' as the sunset time in GMT, trying to use the GMT offset of -4 would result in '-3:-4' being returned.

In sunfuncs.c there is a line:

ret = php_sunrise_sunset(N, latitude, longitude, zenith, calc_sunset) + gmt_offset;

It seems that it should check if gmt_offset is greater than the returned value from php_sunrise_sunset and if so, add 24 to the returned value before the addition of gmt_offset.


Reproduce code:
---------------
<?php
echo date("D M d Y"). ', sunset time : ' .date_sunset(time(), SUNFUNCS_RET_STRING, 40, -83, 90, -4);
?>


Expected result:
----------------
I would expect to see:

Sun Apr 24 2005, sunset time : 20:14


Actual result:
--------------
I actually see:

Sun Apr 24 2005, sunset time : -3:-4

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-04-25 06:35 UTC] matt-dated-1114405650 dot e8a5a2 at codewalkers
Sorry...

"There seems to be a bug in date_sunrise and date_sunset when the GMT offset is greater than the sunrise or sunset time."

should have read:

"There seems to be a bug in date_sunrise and date_sunset when the GMT offset is negative and the absolute value is greater than the sunrise or sunset time."
 [2005-10-09 00:04 UTC] filcab at gmail dot com
You should only need to do:

ret = php_sunrise_sunset(N, latitude, longitude, zenith, calc_sunset) + (gmt_offset + 24) % 24;

That should do it (no if's :D)... I can't checkout the source and patch it ATM.



Filipe Cabecinhas.
 [2006-01-04 22:40 UTC] derick@php.net
This bug has been fixed in CVS.

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/.
 
Thank you for the report, and for helping us make PHP better.

Fixed for 5.1.2 and later
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Nov 21 13:01:29 2024 UTC