Skip to content

Commit 97f6da7

Browse files
committed
Fixed bug #52744 (cal_days_in_month incorrect for December 1 BCE). Original
patch by gpap at internet dot gr.
1 parent bcea4e6 commit 97f6da7

File tree

3 files changed

+23
-2
lines changed

3 files changed

+23
-2
lines changed

NEWS

+2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020

2121
- Fixed bug #52786 (PHP should reset section to [PHP] after ini sections).
2222
(Fedora at famillecollet dot com)
23+
- Fixed bug #52744 (cal_days_in_month incorrect for December 1 BCE).
24+
(gpap at internet dot gr, Adam)
2325
- Fixed bug #52725 (gcc builtin atomic functions were sometimes used when they
2426
were not available). (fat)
2527
- Fixed bug #52745 (Binding params doesn't work when selecting a date inside a

ext/calendar/calendar.c

+9-2
Original file line numberDiff line numberDiff line change
@@ -348,8 +348,15 @@ PHP_FUNCTION(cal_days_in_month)
348348
sdn_next = calendar->to_jd(year, 1 + month, 1);
349349

350350
if (sdn_next == 0) {
351-
/* if invalid, try first month of the next year... */
352-
sdn_next = calendar->to_jd(year + 1, 1, 1);
351+
/* If the next month is invalid, then we need to try the first month of
352+
* the next year, bearing in mind that the next year after 1 BCE is
353+
* actually 1 AD and not 0. */
354+
if (year == -1) {
355+
sdn_next = calendar->to_jd(1, 1, 1);
356+
}
357+
else {
358+
sdn_next = calendar->to_jd(year + 1, 1, 1);
359+
}
353360
}
354361

355362
RETURN_LONG(sdn_next - sdn_start);

ext/calendar/tests/bug52744.phpt

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
--TEST--
2+
Bug #52744 (cal_days_in_month incorrect for December 1 BCE)
3+
--SKIPIF--
4+
<?php include 'skipif.inc'; ?>
5+
--FILE--
6+
<?php
7+
var_dump(cal_days_in_month(CAL_GREGORIAN, 12, -1));
8+
var_dump(cal_days_in_month(CAL_JULIAN, 12, -1));
9+
?>
10+
--EXPECT--
11+
int(31)
12+
int(31)

0 commit comments

Comments
 (0)