homepage Welcome to WebmasterWorld Guest from 54.227.215.140
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
Timestamp glitch?
panic

10+ Year Member



 
Msg#: 3209844 posted 10:01 pm on Jan 5, 2007 (gmt 0)

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?

 

mcavic

WebmasterWorld Senior Member 10+ Year Member



 
Msg#: 3209844 posted 11:02 pm on Jan 5, 2007 (gmt 0)

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.

eelixduppy

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



 
Msg#: 3209844 posted 11:14 pm on Jan 5, 2007 (gmt 0)

What version of PHP are you both running?

mcavic

WebmasterWorld Senior Member 10+ Year Member



 
Msg#: 3209844 posted 11:17 pm on Jan 5, 2007 (gmt 0)

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.

panic

10+ Year Member



 
Msg#: 3209844 posted 11:50 pm on Jan 5, 2007 (gmt 0)

I'm running PHP 5.2.0 on Windows XP.

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

encyclo

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



 
Msg#: 3209844 posted 12:02 am on Jan 6, 2007 (gmt 0)

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.

eelixduppy

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



 
Msg#: 3209844 posted 12:08 am on Jan 6, 2007 (gmt 0)

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

Thanks!

mcavic

WebmasterWorld Senior Member 10+ Year Member



 
Msg#: 3209844 posted 2:38 am on Jan 6, 2007 (gmt 0)

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.

eelixduppy

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



 
Msg#: 3209844 posted 3:45 am on Jan 6, 2007 (gmt 0)

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]

mcavic

WebmasterWorld Senior Member 10+ Year Member



 
Msg#: 3209844 posted 3:52 am on Jan 6, 2007 (gmt 0)

Aha, I never knew that. Even if shifting by 12 hours works, it would probably be more reliable without any Julian functions.

coopster

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



 
Msg#: 3209844 posted 7:34 pm on Jan 6, 2007 (gmt 0)

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.

panic

10+ Year Member



 
Msg#: 3209844 posted 10:19 pm on Jan 9, 2007 (gmt 0)

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.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved