3

I was trying to make my own php mktime(); using my default timezone *(America/Sao_Paulo)*. It was working ok, but I noticed that some timestamps had one hour more than it should be. So I tracked down and find out this date where the script starts to miss: 03/November/1985 I ran some tests and for some weird reason (that's what I'm trying to understand), this day have only 23 hours! Check it:

<?php

date_default_timezone_set('America/Sao_Paulo');

//shows 23
echo (mktime(0,0,0,11,03,1985)- mktime(0,0,0,11,02,1985))/3600; 

//any other date, shows 24
echo '<br/>'.(mktime(0,0,0,11,3,2000)-mktime(0,0,0,11,2,2000))/3600; 

?>

Notice that it doesn't occurs with timezone UTC. It's a possible bug?

PS: Sorry for english mistakes.

Ravan Scafi
  • 6,382
  • 2
  • 24
  • 32

2 Answers2

4

You happened to pick the date that represents the start of daylight savings in Brazil for 1985. See http://tldp.org/HOWTO/TimePrecision-HOWTO/tz.html.

So, because of the time change on that specific date, the difference between midnight on the two days is only 23 hours.

Trott
  • 66,479
  • 23
  • 173
  • 212
3

Sounds like a day light savings time issue. Probably only has 23 hours because DST pushes the clock ahead, skipping 1 hour.

There's an extra argument to mktime called is_dst. Try setting it to 0 or 1 and see if that fixes your problem, although the output you're getting might very well be correct.

mpen
  • 272,448
  • 266
  • 850
  • 1,236