Package home | Report new bug | New search | Development Roadmap Status: Open | Feedback | All | Closed Since Version 1.5.0a4

Request #9732 Wrong result from NWeekdayOfMonth!
Submitted: 2007-01-04 09:53 UTC
From: even at phoniax dot no Assigned: firman
Status: Closed Package: Date (version 1.4.7)
PHP Version: 5.2.0 OS: *nix
Roadmaps: (Not assigned)    
Subscription  
Comments Add Comment Add patch


Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know! Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem : 40 + 16 = ?

 
 [2007-01-04 09:53 UTC] even at phoniax dot no (Even AndrĂ© Fiskvik)
Description: ------------ Returns wrong date when comparing to this page: http://www.timeanddate.com/calendar/index.html? year=2009&country=18 Test script: --------------- echo Date_Calc::NWeekdayOfMonth(1, 1, 12, 2008, '%Y-%m-%d'); Expected result: ---------------- 2008-12-29 The script should, according to http://www.timeanddate.com/ calendar/index.html?year=2009&country=18, output the date 2008-12-29 Actual result: -------------- 2008-12-01

Comments

 [2007-01-09 06:46 UTC] sidshakal at gmail dot com (Sid)
Frankly, I don't understand why you expect the result to be 2008-12-29. For one thing, you are comparing your test script's output (year expected is 2008), with a calendar of 2009. Why? Also, do you even understand what NWeekdayOfMonth is actually supposed to do? I'd try to explain it myself, but I was having a hard time keeping on track doing so and erased what I'd just typed. You might check the API documentation though. http://pear.php.net/package/Date/docs/latest/apidoc/Date/Date_Calc.html#methodNWeekdayOfMonth I haven't verified that the script gives the correct result myself; however, it is bound to be a hell of a lot closer than your expected result is because the 29th of December is in no way ever located in the first week of December. -- Sid
 [2007-01-09 08:02 UTC] even at phoniax dot no
Seems like I misunderstood the documentation. $week seems to range from 1-4 in this method (week of month), while I thought it was week of the year. Looking at the method-name once again this clarly makes more sence. Perhaps the "bug" should change to a feature request instead? :) I would like to be able to input week of the year, and have a valid date-range given back for that week. I couldn't find any method that did that in the current release?
 [2007-02-23 16:05 UTC] firman (Firman Wandayandi)
Yep, you misunderstood what the method purpose is. Date_Calc::NWeekdayOfMonth() is return a date for give week day of the week of month. Sid right, 29th is never become first week of December. Currently, no method that return a date range for given week of month. Well this should be feature request. -- Firman
 [2008-05-27 06:25 UTC] firman (Firman Wandayandi)
New method isoWeekToDate() has been added into Date_Calc and its now available in CVS (http://cvs.php.net/viewcvs.cgi/pear/Date/Date/Calc.php?revision=1.61&view=markup). To get the range of dates in specified ISO week number of year, you can simply write few codes to iterate it. For example: $dates = array(); for ($i = 1; $i <= 7; $i++) { $dates[] = Date_Calc::isoWeekToDate(2008, 19, $i, '%Y %m %d'); } This request accomplished.