|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2003-10-08 04:21 UTC] australia at bookrealm dot com
Description: ------------ The array key 'yday' from getdate() is one day less than it should be. Bug can be confirmed using mcal_day_of_year(). Reproduce code: --------------- <?php $y = date(Y); $m = date(n); $d = date(j); echo mcal_day_of_year($y,$m,$d) . "<br />"; $day_year = getdate(); echo $day_year[yday]; ?> Expected result: ---------------- Example date: 2003-10-8 Expected result: 281 281 Actual result: -------------- Example date: 2003-10-8 Actual result: 281 280 PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Dec 06 18:00:01 2025 UTC |
Day count for this date (2003-10-08) is 280. e.g. # php -r 'echo date("z");' 280 It's propably mcal that is broken. (and I mean the library, not extension)And, IMHO, the example you gave, echo date("z"); thus also seems to give incorrect results.Maybe this clears it for you: # php -r 'echo date("z", mktime(1,1,1,1,1,2003));' 0 The count starts from 0..Yes, I figured the count started from zero, but really it shouldn't. The 1st of the 1st of any year should be day # 1, not day # 0. The manuals state that 'yday' in getdate() and 'z' in date() give "The day of the year". This is not correct if both are out by one day, and no indication that that is the case, and no indication that you must add one day to make them correct. The proper fix would be to fix the code, but a slacker fix would be to state in the manuals that you must add a day, ie., date("z") + 1, to get the correct "day of the year" number. Up to you, of course, which you choose to do. Cheers, Andrew SkripshakOk, I'll work with it the way it is. However, there are two things, maybe in other places too, which need to be changed. The values in "Example returned values" for both date("z") and 'yday' in getdate() show "0-366", these should be changed to "0-365" (as is shown in the 'man 3 localtime' you gave me to look at). Else there be 366 days in a normal year, and 367 in a leap year? I still believe it should be "1-366", but ah well. Cheers, Andrew Skripshak