Bug #67976 [NEW]: cal_days_month() fails for final month of the French calendar

From: Date: Mon, 08 Sep 2014 10:04:17 +0000
Subject: Bug #67976 [NEW]: cal_days_month() fails for final month of the French calendar
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-187442@lists.php.net to get a copy of this message
From:             fisharebest at gmail dot com
Operating system: All
PHP version:      5.6.0
Package:          Calendar related
Bug Type:         Bug
Bug description:cal_days_month() fails for final month of the French calendar

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


-- 
Edit bug report at https://bugs.php.net/bug.php?id=67976&edit=1
-- 



Thread (3 messages)

« previous php.bugs (#187442) next »