]> granicus.if.org Git - php/commitdiff
Fixed bug #52744 (cal_days_in_month incorrect for December 1 BCE). Original
authorAdam Harvey <aharvey@php.net>
Thu, 9 Sep 2010 06:41:23 +0000 (06:41 +0000)
committerAdam Harvey <aharvey@php.net>
Thu, 9 Sep 2010 06:41:23 +0000 (06:41 +0000)
patch by gpap at internet dot gr.

NEWS
ext/calendar/calendar.c
ext/calendar/tests/bug52744.phpt [new file with mode: 0644]

diff --git a/NEWS b/NEWS
index 9cba2bdb639d12ec85e66461ff55a95f156b1c51..e52246a6f103170922bfc9acdb5a3f0c630515b5 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -20,6 +20,8 @@
 
 - Fixed bug #52786 (PHP should reset section to [PHP] after ini sections).
   (Fedora at famillecollet dot com)
+- Fixed bug #52744 (cal_days_in_month incorrect for December 1 BCE).
+  (gpap at internet dot gr, Adam)
 - Fixed bug #52725 (gcc builtin atomic functions were sometimes used when they
   were not available). (fat)
 - Fixed bug #52745 (Binding params doesn't work when selecting a date inside a
index 54f2658eeae5b9af57b7d204aee0d57099e68b8e..6eb2d31beff5eb9c34fd874313c79e9de13a2f81 100644 (file)
@@ -348,8 +348,15 @@ PHP_FUNCTION(cal_days_in_month)
        sdn_next = calendar->to_jd(year, 1 + month, 1);
 
        if (sdn_next == 0) {
-/* if invalid, try first month of the next year... */
-               sdn_next = calendar->to_jd(year + 1, 1, 1);
+               /* If the next month is invalid, then we need to try the first month of
+                * the next year, bearing in mind that the next year after 1 BCE is
+                * actually 1 AD and not 0. */
+               if (year == -1) {
+                       sdn_next = calendar->to_jd(1, 1, 1);
+               }
+               else {
+                       sdn_next = calendar->to_jd(year + 1, 1, 1);
+               }
        }
 
        RETURN_LONG(sdn_next - sdn_start);
diff --git a/ext/calendar/tests/bug52744.phpt b/ext/calendar/tests/bug52744.phpt
new file mode 100644 (file)
index 0000000..886086a
--- /dev/null
@@ -0,0 +1,12 @@
+--TEST--
+Bug #52744 (cal_days_in_month incorrect for December 1 BCE)
+--SKIPIF--
+<?php include 'skipif.inc'; ?>
+--FILE--
+<?php
+var_dump(cal_days_in_month(CAL_GREGORIAN, 12, -1));
+var_dump(cal_days_in_month(CAL_JULIAN, 12, -1));
+?>
+--EXPECT--
+int(31)
+int(31)