Bug #61185 [Opn->Dup]: jdtojewish return values incompatible with cal_days_in_month on non-leap years
| From: | cmb@php.net | Date: | Sat, 18 Jun 2016 11:38:14 +0000 |
| Subject: | Bug #61185 [Opn->Dup]: jdtojewish return values incompatible with cal_days_in_month on non-leap years | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-201709@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=61185&edit=1
ID: 61185
Updated by: cmb@php.net
Reported by: php-bugs at shimi dot net
Summary: jdtojewish return values incompatible with
cal_days_in_month on non-leap years
-Status: Open
+Status: Duplicate
Type: Bug
Package: Calendar related
Operating System: Linux
PHP Version: 5.4.0RC8
-Assigned To:
+Assigned To: cmb
Block user comment: N
Private report: N
New Comment:
Indeed, that is a duplicate of bug #54254.
Previous Comments:
------------------------------------------------------------------------
[2012-07-12 13:00:47] eitan at mosenkis dot net
Duplicate of 54254
------------------------------------------------------------------------
[2012-02-26 09:10:15] php-bugs at shimi dot net
Description:
------------
Preamble:
Please bear with me for the long explanation, it is my reasoning for the request I'm going to
give in the end.
I'm pretty sure the code I'm testing now worked a few years ago; I have specific code that
actually checks if the Jewish year is leap, and if so, add 1 month to all calculations after the 6th
month if the year is leap.
Now my code is broken. Regardless if it really worked in the past or not, I see an incompatibility
between two calendar functions, which I think should be aligned together.
My code calculates the dates of many Jewish events, according to the Jewish calendar. For those who
are not familiar with the Jewish calendar - not every year has the same amount of months. If the
(Jewish year % 19) is 0, 3, 6, 8, 11, 14 or 17, then the year is "leap" (I don't have
a better word in English), and an additional month is added between the 5th month (Shvat) and the
6th month (Adar). The new month added is also called "Adar" (and denoted "Adar
A", while the original Adar becomes the second, and denoted "Adar B", so the holiday
that we have in Adar every year, remains in B).
Now, at the moment, we're in an Adar month (which is why the bug popped out), but this is not a
leap year (Jewish year now is 5772 % 19 = 15), so we have only one Adar month.
Now, as memory serves me (and as written in my code), cal_days_in_month could accept 1-12 as valid
month on non-leap years, and 1-13 on leap years. My code has tests for those things, and acted
accordingly. Now, it appears, that cal_days_in_month always accepts a 1-13 value, and simply expect
the programmer to jump over the 6th month, returning "0" if there was no Adar A added
before the regular Adar.
This is OK! Actually, it makes all my calculations of leap years - redundant.
The problem is - that even though cal_days_in_month understand that the _current_ month is actually
the 7th (as we "skipped" the 6th of 13 of a leap year), jdtojewish, the function that
gives you those dates in the first place, says that we're in the 6th month...
I think that if cal_days_in_month thinks there is no 6th month this year, jdtojewish should never
return the number "6" for this year.
[p.s. example code will not show the mentioned problem in ~28 days when the Hebrew month changes,
but will probably return a wrong day count...]
Test script:
---------------
Code:
<?php
list($jewishmonth, $jewishday, $jewishyear) = explode('/',
jdtojewish(gregoriantojd(date('m'), date('d'), date('y'))));
echo "Jewish month is $jewishmonth. How many days do we have this month? " .
cal_days_in_month(CAL_JEWISH, $jewishmonth, $jewishyear) . "\n";
?>
Expected result:
----------------
Jewish month is 7. How many days do we have this month? 29
Actual result:
--------------
Jewish month is 6. How many days do we have this month? 0
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=61185&edit=1