php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #67976 cal_days_month() fails for final month of the French calendar
Submitted: 2014-09-08 10:04 UTC Modified: 2016-07-28 17:38 UTC
Votes:1
Avg. Score:1.0 ± 0.0
Reproduced:0 of 0 (0.0%)
From: fisharebest at gmail dot com Assigned: cmb (profile)
Status: Closed Package: Calendar related
PHP Version: 5.6.0 OS: All
Private report: No CVE-ID: None
 [2014-09-08 10:04 UTC] fisharebest at gmail dot com
Description:
------------
PHP calendar functions support the French Republican calendar.

Most calendars (Jewish, Gregorian, Julian) start at 0001-01-01 and run forwards until the end of time.

However, PHP implements an end date for the French calendar.  Hence dates in year 15 onwards are invalid.  In other words, it starts at 0001-01-01 and ends at 0014-13-05.

The algorithm for calculating the number of days in each month (ext/calendar/calendar.c#363) can be summarised as:

(Julian day of the first day of the next month) minus (Julian day of the first day of this month)

For example, the number of days in December 2014 is given by

JD(2015-01-01) - JD(2014-12-01).

Now, when calculating the number of days of finl month of the final year of the French calendar, PHP attempts to calculate

JD(0015-01-01) - JD(0014-13-01)

Since the first date is invalid (JD=0), this returns a nonsensical answer.  This bug applies to all versions of PHP - see http://3v4l.org/2vhM7

IMHO, this bug should be fixed by removing the end date.  The French calendar is still used today, though rarely and in limited contexts.

Test script:
---------------
echo cal_days_in_month(CAL_FRENCH, 13, 14); // Should give 5, not -2380948


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2016-07-28 17:37 UTC] cmb@php.net
Automatic comment on behalf of cmb
Revision: http://git.php.net/?p=php-src.git;a=commit;h=7ab39e2faef499c8a1857205fa332d2e38a0a584
Log: Fix #67976: cal_days_month() fails for final month of the French calendar
 [2016-07-28 17:37 UTC] cmb@php.net
-Status: Open +Status: Closed
 [2016-07-28 17:38 UTC] cmb@php.net
-Assigned To: +Assigned To: cmb
 [2016-07-28 17:38 UTC] cmb@php.net
> IMHO, this bug should be fixed by removing the end date.

I agree that this should be considered, but I'm uncomfortable to
do so as bugfix. The algorithm we're using[1] claims to have "been
tested for the year 1 to 14", so extending the algorithm might
introduce unforseen issues (in particular, the handling of leap
years comes to mind). Furthermore the French calendar is most
likely not used very often, so if you still wish to extend this
calendar, file a new feature request, please.

Anyhow, thanks for the bug report and for helping us to make PHP
better.

[1] <https://github.com/php/php-src/blob/PHP-7.0.8/ext/calendar/french.c>
 [2016-10-17 10:10 UTC] bwoebi@php.net
Automatic comment on behalf of cmb
Revision: http://git.php.net/?p=php-src.git;a=commit;h=7ab39e2faef499c8a1857205fa332d2e38a0a584
Log: Fix #67976: cal_days_month() fails for final month of the French calendar
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 11:01:30 2024 UTC