summaryrefslogtreecommitdiff
path: root/ext/calendar
diff options
context:
space:
mode:
authorAdam Harvey <aharvey@php.net>2010-09-09 06:41:23 +0000
committerAdam Harvey <aharvey@php.net>2010-09-09 06:41:23 +0000
commitc2f2f68692a1fc80c22660c97b83c84332c44905 (patch)
tree5109286bf118b184d9dc3a38e320e7326ce3142b /ext/calendar
parent02b2a288820deedc1cc43bc2a3cf2982444d8a72 (diff)
downloadphp-git-c2f2f68692a1fc80c22660c97b83c84332c44905.tar.gz
Fixed bug #52744 (cal_days_in_month incorrect for December 1 BCE). Original
patch by gpap at internet dot gr.
Diffstat (limited to 'ext/calendar')
-rw-r--r--ext/calendar/calendar.c11
-rw-r--r--ext/calendar/tests/bug52744.phpt12
2 files changed, 21 insertions, 2 deletions
diff --git a/ext/calendar/calendar.c b/ext/calendar/calendar.c
index 54f2658eea..6eb2d31bef 100644
--- a/ext/calendar/calendar.c
+++ b/ext/calendar/calendar.c
@@ -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 0000000000..886086a294
--- /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)