3

the following code:

    // settings 1st alternative
    $season = 2011;
    $startweek = 36;

    // calculation, 1st alternative
    // in any case Jan 1st is in 1. week
    $firstweekuniversal = mktime(0,0,0,1,4,$season);
    // I'd like to calculate monday 0:00 of the given week.
    // date(...) computes to monday of the calculated week.
    $startday1 = $firstweekuniversal + 86400 * (7*($startweek-1) - date('w', $firstweekuniversal)+1);

    // settings 2nd alternative
    $StartingDate = "KW36 - 5.09.2011 (Mo)";

    // calculation, 2nd alternative
    $firstparts = explode(" ", $StartingDate);
    $secparts = explode(".", $firstparts[2]);
    $startday2 = mktime(0,0,0,intval($secparts[1]),intval($secparts[0]),intval($secparts[2]));

    // Output
    echo "Start: \$startday1=".$startday1.", Timestamp=\"".date("d.m.Y - H:i:s", $startday1)."\"<br>\n";
    echo "Start: \$startday2=".$startday2.", Timestamp=\"".date("d.m.Y - H:i:s", $startday2)."\"<br>\n";

leads to this output:

Start: $startday1=1315177200, Timestamp="05.09.2011 - 01:00:00"
Start: $startday2=1315173600, Timestamp="05.09.2011 - 00:00:00"

where is the 1h difference coming from? It can't be summertime issues, in that case the 1h had to be the other way round, or am I wrong? There's no difference, when I'm trying with my environment (localhost), but on the server of my prvider there is.

Can anyone explain this to me? I'm totally puzzled here. Thanks in advance,

  • what timezones are your localhost and your server in? – Jan Prieser Aug 30 '12 at 10:12
  • timezones are both Europe/Berlin, but shouldn't that be irrelevant, since the script runs both alternatives? – Markus Last Aug 30 '12 at 11:50
  • What OS are you running on localhost and provider? I ran it on my Ubuntu VM and got the same behaviour you observed, same on Ubuntu EC2 instances. It is probably related to some weird DST settings but can't find which/where would it be. – Mikushi Aug 30 '12 at 14:40
  • Are you using the same date to test locally and on your provider machine? Because if you use an earlier date (i.e. : week 10 2011) located before the DST change -end of March-, you'll find no difference. I would presume that because you calculate the time difference between first week and D-Date manually you would probably need to compensate for DST if the interval crosses a DST change. – Mikushi Aug 30 '12 at 15:24

1 Answers1

0

My understanding of daylight savings is that at a certain point between winter and summer the sun is starting to rise earlier, so at 8am it would feel like it should be 9am ... and that's exactly what the clock does, it moves forward making it later (by one hour typically). This is also why it's such a good excuse for being late at school :)

In any case, the timezone setting of your local php is probably UTC (or some other "neutral" timezone) but the server timezone setting honors daylight savings.

Ja͢ck
  • 170,779
  • 38
  • 263
  • 309