Welcome to WebmasterWorld Guest from 54.159.214.250

Forum Moderators: coopster & jatar k

Timestamp glitch?

   
10:01 pm on Jan 5, 2007 (gmt 0)

10+ Year Member



I was putting together a calendar in PHP, when I came across a strange glitch : days in March 2007 after 3/11/07 are shifted by a day.

Here's my code:


$date = unixtojd(mktime(0, 0, 0, $month, $day, $year));
$datearray = cal_from_jd($date, CAL_GREGORIAN);
print_r($datearray);

Here's the output when $month=3, $day=11, and $year=2007:


Array
(
[date] => 3/11/2007
[month] => 3
[day] => 11
[year] => 2007
[dow] => 0
[abbrevdayname] => Sun
[dayname] => Sunday
[abbrevmonth] => Mar
[monthname] => March
)


Here's the output when $month=3, $day=12, and $year=2007:


Array
(
[date] => 3/11/2007
[month] => 3
[day] => 11
[year] => 2007
[dow] => 0
[abbrevdayname] => Sun
[dayname] => Sunday
[abbrevmonth] => Mar
[monthname] => March
)

Here's the output when $month=3, $day=13, and $year=2007:


Array
(
[date] => 3/12/2007
[month] => 3
[day] => 12
[year] => 2007
[dow] => 1
[abbrevdayname] => Mon
[dayname] => Monday
[abbrevmonth] => Mar
[monthname] => March
)

Is there something I'm missing?

11:02 pm on Jan 5, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I'm getting the same result. The problem seems to be in mktime(). It's saying that March 11 occurs 86,400 seconds later than March 10, which is correct, but that March 12 occurs only 82,400 seconds after March 11.
11:14 pm on Jan 5, 2007 (gmt 0)

WebmasterWorld Senior Member eelixduppy is a WebmasterWorld Top Contributor of All Time 5+ Year Member



What version of PHP are you both running?
11:17 pm on Jan 5, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



PHP 5.2.0 under Fedora 4 here.

MySQL gives the correct result, which means that C should also, so it seems to be a PHP issue rather than Linux.

11:50 pm on Jan 5, 2007 (gmt 0)

10+ Year Member



I'm running PHP 5.2.0 on Windows XP.

I guess that means it's not a Windows-specific bug.

12:02 am on Jan 6, 2007 (gmt 0)

WebmasterWorld Senior Member encyclo is a WebmasterWorld Top Contributor of All Time 10+ Year Member



It's saying that March 11 occurs 86,400 seconds later than March 10, which is correct, but that March 12 occurs only 82,400 seconds after March 11.

In North America, Daylight Savings Time in 2007 starts on March 11th. This may well have a bearing on the problem. :) Shouldn't shift things by a day, though, only by an hour.

12:08 am on Jan 6, 2007 (gmt 0)

WebmasterWorld Senior Member eelixduppy is a WebmasterWorld Top Contributor of All Time 5+ Year Member



Second Sunday in March! haha...wow...don't I feel stupid... And yes, it only differs by an hour :)

Thanks!

2:38 am on Jan 6, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



On August 8, 2005, President George W. Bush signed the Energy Policy Act of 2005. This Act changed the time change dates for Daylight Saving Time in the U.S. Beginning in 2007, DST will begin on the second Sunday in March and end the first Sunday in November.

Well okay, the unixtojd() function isn't figuring DST properly.

$now = mktime(0, 0, 0, 3, 11, 2007);
$date = unixtojd($now);
print "Mar 11 Julian Date = $date\n";

$now = mktime(0, 0, 0, 3, 12, 2007);
$date = unixtojd($now);
print "Mar 12 Julian Date = $date\n";

Mar 11 Julian Date = 2454171
Mar 12 Julian Date = 2454171

I'd find a way to do it without Julian dates.

3:45 am on Jan 6, 2007 (gmt 0)

WebmasterWorld Senior Member eelixduppy is a WebmasterWorld Top Contributor of All Time 5+ Year Member



Ok I just found this out.

Julian Days start at noon, not at midnight. If you shift to
13:00 you'll see that it works fine.

I'll try to find the official documentation on this :)

[edit]
I guess this [en.wikipedia.org] will do.
[/edit]

3:52 am on Jan 6, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Aha, I never knew that. Even if shifting by 12 hours works, it would probably be more reliable without any Julian functions.
7:34 pm on Jan 6, 2007 (gmt 0)

WebmasterWorld Administrator coopster is a WebmasterWorld Top Contributor of All Time 10+ Year Member



Do you folks have your date.timezone [webmasterworld.com] set in your configuration for PHP >= 5.1.0? I do and I cannot reproduce the issue.
10:19 pm on Jan 9, 2007 (gmt 0)

10+ Year Member



I did not have my date.timezone set when I initially ran this.

I set the date.timezone, but am still running into the same problem. I think my best bet is to get away from using Julian dates.

 

Featured Threads

Hot Threads This Week

Hot Threads This Month