views:

31

answers:

2

I'm having a look at the date_sunset function in PHP and have met an issue that I find a bit strange. I have this piece of code:

$sunset = date_sunset(mktime(0, 0, 0, 5, 14, 2010),
    $format,                // Format
    55.596041,              // Latitude
    12.992495,              // Longitude
    90,                     // Zenith
    2                       // GMT Offset
);

For the three different formats, that would give me:

SUNFUNCS_RET_STRING    21:05
SUNFUNCS_RET_DOUBLE    21.095732016315
SUNFUNCS_RET_TIMESTAMP 1273863944 // H:i:s O -> 19:05:44 +0000

Why is the timestamp format ignoring the gmt offset? Is is supposed to be like that? If so what is the reason behind that?

+3  A: 

Timestamps do not contain any timezone data. They are the seconds since Epoch, which is Jan 1st 1970, 00:00:00

ThiefMaster
A good way to see this is to do `date("F j, Y h:i:s", 0);`. If your timezone isn't GMT you'll get a time shifted from 1 Jan 1970 00:00:00
Michael Mrozek
+1  A: 

date_sunset(,SUNFUNCS_RET_TIMESTAMP,,,,) isn't ignoring the offset, the function you have used to format the timestamp value is (i.e. the timezone is set to utc+0), e.g.

$sunset = date_sunset(mktime(0, 0, 0, 5, 14, 2010),
    SUNFUNCS_RET_TIMESTAMP,                // Format
    55.596041,              // Latitude
    12.992495,              // Longitude
    90,                     // Zenith
    2                       // GMT Offset
);

date_default_timezone_set('UTC');
echo date('H:i:s O', $sunset), "\n";

date_default_timezone_set('Europe/Berlin');
echo date('H:i:s O', $sunset), "\n";

date_default_timezone_set('America/New_York');
echo date('H:i:s O', $sunset), "\n";

prints

19:06:07 +0000
21:06:07 +0200
15:06:07 -0400
VolkerK
That was the case! If I do `date_default_timezone_set('Europe/Stockholm')` first, then it is correct :) Thanks!
Svish