summaryrefslogtreecommitdiff
path: root/ext/calendar
diff options
context:
space:
mode:
authorOndřej Surý <ondrej@sury.org>2011-02-16 10:13:02 +0100
committerOndřej Surý <ondrej@sury.org>2011-02-16 10:13:02 +0100
commitfd5a0b31640419ca63d1ddeaffd6d3cf2a741814 (patch)
treebfd17d84c5181d7b98d7d66f56573f4fc897e31c /ext/calendar
parent01fcdff3849c3691d9aaeaab735846ab6d8895ca (diff)
downloadphp-fd5a0b31640419ca63d1ddeaffd6d3cf2a741814.tar.gz
Imported Upstream version 5.3.5upstream/5.3.5
Diffstat (limited to 'ext/calendar')
-rw-r--r--ext/calendar/calendar.c13
-rw-r--r--ext/calendar/tests/bug52744.phpt12
2 files changed, 22 insertions, 3 deletions
diff --git a/ext/calendar/calendar.c b/ext/calendar/calendar.c
index 6884d171d..b23b892e2 100644
--- a/ext/calendar/calendar.c
+++ b/ext/calendar/calendar.c
@@ -18,7 +18,7 @@
| Wez Furlong <wez@thebrainroom.com> |
+----------------------------------------------------------------------+
*/
-/* $Id: calendar.c 293036 2010-01-03 09:23:27Z sebastian $ */
+/* $Id: calendar.c 303203 2010-09-09 06:41:23Z aharvey $ */
#ifdef HAVE_CONFIG_H
#include "config.h"
@@ -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
index 000000000..886086a29
--- /dev/null
+++ b/ext/calendar/tests/bug52744.phpt
@@ -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)