[wplug] weird php issue

Chris Romano romano.chris at gmail.com
Wed Jan 27 16:25:21 EST 2010


On Wed, Jan 27, 2010 at 4:09 PM, Justin Liebler <jliebler at gmail.com> wrote:
> On Wed, Jan 27, 2010 at 2:24 PM, Chris Romano <romano.chris at gmail.com>
> wrote:
>>
>> On Wed, Jan 27, 2010 at 7:45 AM, Eli Heady <eli.heady at gmail.com> wrote:
>> > On Tue, Jan 26, 2010 at 9:48 PM, Chris Romano <romano.chris at gmail.com>
>> > wrote:
>> >> I'm running CentOS and using php 5.1.6
>> >>
>> >> There seems to be an issue with the date function.  I don't know if
>> >> there is something on my end (coding) of it's a system issue.  Here is
>> >> the code in question:
>> >>
>> >> $firstWeek = date("W",mktime(0,0,0,$month,1,$year));
>> >>
>> >> which for January would be something like this
>> >> $firstWeek = date("W",mktime(0,0,0,01,1,2010));
>> >>
>> >> When this code is ran, $firstWeek is being set to 53.  It should be
>> >> set to 01.  The code works perfect if the year is 2009.
>> >>
>> >> Any ideas?
>> >>
>> >> Thanks,
>> >> Chris
>> >
>> > Same here: php 5.3.1 (suhosin patched)
>> >
>> > Occurs every six years, then in the following year the week is off by -2
>> >
>> > A quick search revealed an issue with similar timing, due to daylight
>> > saving time: http://bugs.php.net/bug.php?id=29065
>> >
>> > It is suggested in that bug report to use gmmktime or gmdate instead.
>> > Is that an option for you?
>> >
>> > date("W",gmdate(0,0,0,01,1,2010));
>> > seems to work as expected
>>
>> Well that doesn't work.
>>
>>
>> $firstWeek = gmdate("W",gmmktime(0,0,0,1,1,2010));
>> print "First Week = $firstWeek<br>";
>>
>> prints
>>
>> First Week = 53
>>
>> Not sure what's going on now.
>>
> I believe you are getting the correct answer according to ISO 8601.  It
> defines the first week of the year as the week with the first Thursday, or
> equivalently the first week that contains January 4th.  So that would mean
> that this year 1/1/2010 falls in the last week of 2009, week 53.
> http://en.wikipedia.org/wiki/ISO_week_date

Justin,

That makes complete sense.  I don't even think about the 1st day of
the year being part of the previous year's week.

Thank you for that.

Chris
-- 
"They that would trade essential liberty for a little temporary safety
deserve neither." -- Benjamin Franklin


More information about the wplug mailing list