php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #19334 NWeekdayOfMonth() in Date::Calc makes incorrect function calls
Submitted: 2002-09-10 09:16 UTC Modified: 2002-09-18 09:57 UTC
From: dswhite42 at yahoo dot com Assigned:
Status: Closed Package: PEAR related
PHP Version: 4.2.3 OS: Linux 2.4.18 (Red Hat)
Private report: No CVE-ID: None
 [2002-09-10 09:16 UTC] dswhite42 at yahoo dot com
The NWeekdayOfMonth() function in the PEAR Date::Calc class calls 2 other Date::Calc functions using incorrect parameters.  This produces results that are almost always invalid.

Line 1246 of Date/Calc.php is:
  $DOW1 = Date_Calc::dayOfWeek($month,$year,$DOW1day);
when it should be:
  $DOW1 = Date_Calc::dayOfWeek($DOW1day,$month,$year);

Line 1254 of Date/Calc.php is:
  return(Date_Calc::dateFormat($month,$year,$wdate,$format));
when it should be:
  return(Date_Calc::dateFormat($wdate,$month,$year,$format));

Here is the patch:
-------------------------------------

--- Calc.php.orig       Tue Sep 10 09:51:08 2002
+++ Calc.php    Tue Sep 10 09:51:09 2002
@@ -1243,7 +1243,7 @@
         $month = sprintf("%02d",$month);
 
         $DOW1day = sprintf("%02d",(($occurance - 1) * 7 + 1));
-        $DOW1 = Date_Calc::dayOfWeek($month,$year,$DOW1day);
+        $DOW1 = Date_Calc::dayOfWeek($DOW1day,$month,$year);
 
         $wdate = ($occurance - 1) * 7 + 1 +
                 (7 + $dayOfWeek - $DOW1) % 7;
@@ -1251,7 +1251,7 @@
         if( $wdate > Date_Calc::daysInMonth($month,$year))
                 return -1;
         else
-                return(Date_Calc::dateFormat($month,$year,$wdate,$format));
+                return(Date_Calc::dateFormat($wdate,$month,$year,$format));
 
     } // end func NWeekdayOfMonth
 

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-09-18 09:57 UTC] mj@php.net
This bug has been fixed in CVS.

In case this was a PHP problem, snapshots of the sources are packaged
every three hours; this change will be in the next snapshot. You can
grab the snapshot at http://snaps.php.net/.
 
In case this was a documentation problem, the fix will show up soon at
http://www.php.net/manual/.

In case this was a PHP.net website problem, the change will show
up on the PHP.net site and on the mirror sites in short time.
 
Thank you for the report, and for helping us make PHP better.


 
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Sun Aug 01 15:01:24 2021 UTC