diff options
| author | Greg Roach <fisharebest@gmail.com> | 2014-10-31 20:02:28 +0000 |
|---|---|---|
| committer | Greg Roach <fisharebest@gmail.com> | 2014-10-31 22:44:26 +0000 |
| commit | ee407f4447e4d6c602067ba69aea50589f8fd840 (patch) | |
| tree | 6a9fc335bc394db3ee2a3da331ef431b86500509 /library/fisharebest/ext-calendar | |
| parent | e4ab762dd58b99cd0051254c2da39d58c8f59659 (diff) | |
| download | webtrees-ee407f4447e4d6c602067ba69aea50589f8fd840.tar.gz webtrees-ee407f4447e4d6c602067ba69aea50589f8fd840.tar.bz2 webtrees-ee407f4447e4d6c602067ba69aea50589f8fd840.zip | |
Update libraries
Diffstat (limited to 'library/fisharebest/ext-calendar')
12 files changed, 450 insertions, 414 deletions
diff --git a/library/fisharebest/ext-calendar/CHANGELOG.md b/library/fisharebest/ext-calendar/CHANGELOG.md index 04e06cdb0e..2cc4e2eddb 100644 --- a/library/fisharebest/ext-calendar/CHANGELOG.md +++ b/library/fisharebest/ext-calendar/CHANGELOG.md @@ -1,6 +1,9 @@ CHANGE LOG ========== +## 1.3.0 (2014-10-31) + - Only emulate bugs in the shim functions, not when using the calendar classes. + ## 1.2.0 (2014-09-27) - Improve coverage of unit tests. - Remove dependency on mb_string - generate Hebrew text directly in ISO-8859-8. diff --git a/library/fisharebest/ext-calendar/README.md b/library/fisharebest/ext-calendar/README.md index 9c528c8a96..67117f0359 100644 --- a/library/fisharebest/ext-calendar/README.md +++ b/library/fisharebest/ext-calendar/README.md @@ -125,4 +125,5 @@ library, given version numbers, unit tests, etc. Future plans ============ -It is hoped to extend the French calendar to allow it to be used for modern times. +* Support alternate leap-year schemes for the French calendar (true equinox, Romme, 128-year cycle) as well as the 4-year cycle. +* Support other calendars, such as Ethiopian, Hindu, Chinese, etc. diff --git a/library/fisharebest/ext-calendar/src/AbstractCalendar.php b/library/fisharebest/ext-calendar/src/AbstractCalendar.php index c353fff2ab..2a4115ca32 100644 --- a/library/fisharebest/ext-calendar/src/AbstractCalendar.php +++ b/library/fisharebest/ext-calendar/src/AbstractCalendar.php @@ -6,20 +6,20 @@ use InvalidArgumentException; /** * class AbstractCalendar - generic base class for specific calendars. * - * @author Greg Roach <fisharebest@gmail.com> + * @author Greg Roach <fisharebest@gmail.com> * @copyright (c) 2014 Greg Roach - * @license This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * @license This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. */ abstract class AbstractCalendar { /** See the GEDCOM specification */ @@ -37,14 +37,25 @@ abstract class AbstractCalendar { /** Does the calendar start at year 1, or are we allowed negative (BCE) years. */ const NEGATIVE_YEARS_ALLOWED = false; + /** @var mixed[] special behaviour for this calendar */ + protected $options = array(); + /** - * Calculate the number of days in a month. + * Some calendars have options that change their behaviour. * - * @param int $year - * @param int $month + * @param mixed[] $options + */ + public function __construct($options = array()) { + $this->options = array_merge($this->options, $options); + } + + /** + * Calculate the number of days in a month. * - * @return int + * @param integer $year + * @param integer $month * + * @return integer * @throws InvalidArgumentException */ public function daysInMonth($year, $month) { diff --git a/library/fisharebest/ext-calendar/src/ArabicCalendar.php b/library/fisharebest/ext-calendar/src/ArabicCalendar.php index bfc4223a0a..a6b6f26518 100644 --- a/library/fisharebest/ext-calendar/src/ArabicCalendar.php +++ b/library/fisharebest/ext-calendar/src/ArabicCalendar.php @@ -4,20 +4,20 @@ namespace Fisharebest\ExtCalendar; /** * Class ArabicCalendar - calculations for the Arabic (Hijri) calendar. * - * @author Greg Roach <fisharebest@gmail.com> + * @author Greg Roach <fisharebest@gmail.com> * @copyright (c) 2014 Greg Roach - * @license This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * @license This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. */ class ArabicCalendar extends AbstractCalendar implements CalendarInterface { /** See the GEDCOM specification */ @@ -29,7 +29,7 @@ class ArabicCalendar extends AbstractCalendar implements CalendarInterface { /** * Month lengths for regular years and leap-years. * - * @var int[][] + * @var integer[][] */ protected static $DAYS_IN_MONTH = array( 0 => array(1 => 30, 28, 30, 29, 30, 29, 30, 29, 30, 29, 30, 29), @@ -39,8 +39,9 @@ class ArabicCalendar extends AbstractCalendar implements CalendarInterface { /** * Determine whether a year is a leap year. * - * @param int $year - * @return bool + * @param integer $year + * + * @return boolean */ public function isLeapYear($year) { return ((11 * $year + 14) % 30) < 11; @@ -49,9 +50,9 @@ class ArabicCalendar extends AbstractCalendar implements CalendarInterface { /** * Convert a Julian day number into a year/month/day. * - * @param int $julian_day + * @param integer $julian_day * - * @return int[]; + * @return integer[] */ public function jdToYmd($julian_day) { $year = (int)((30 * ($julian_day - 1948439) + 10646) / 10631); @@ -64,11 +65,11 @@ class ArabicCalendar extends AbstractCalendar implements CalendarInterface { /** * Convert a year/month/day into a Julian day number * - * @param int $year - * @param int $month - * @param int $day + * @param integer $year + * @param integer $month + * @param integer $day * - * @return int + * @return integer */ public function ymdToJd($year, $month, $day) { return $day + 29 * ($month - 1) + (int)((6 * $month - 1) / 11) + $year * 354 + (int)((3 + 11 * $year) / 30) + 1948084; diff --git a/library/fisharebest/ext-calendar/src/CalendarInterface.php b/library/fisharebest/ext-calendar/src/CalendarInterface.php index d3784a4a36..4fbd31aedd 100644 --- a/library/fisharebest/ext-calendar/src/CalendarInterface.php +++ b/library/fisharebest/ext-calendar/src/CalendarInterface.php @@ -7,58 +7,58 @@ namespace Fisharebest\ExtCalendar; * * Many of them are actually provided by the AbstractCalendar base class. * - * @author Greg Roach <fisharebest@gmail.com> + * @author Greg Roach <fisharebest@gmail.com> * @copyright (c) 2014 Greg Roach - * @license This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * @license This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. */ interface CalendarInterface { /** * Determine the number of days in a specified month, allowing for leap years, etc. * - * @param int $year - * @param int $month + * @param integer $year + * @param integer $month * - * @return int + * @return integer */ public function daysInMonth($year, $month); /** * Convert a Julian day number into a year/month/day. * - * @param int $julian_day + * @param integer $julian_day * - * @return int[] + * @return integer[] */ public function jdToYmd($julian_day); /** * Determine whether or not a given year is a leap-year. * - * @param int $year + * @param integer $year * - * @return bool + * @return boolean */ public function isLeapYear($year); /** * Convert a year/month/day to a Julian day number. * - * @param int $year - * @param int $month - * @param int $day + * @param integer $year + * @param integer $month + * @param integer $day * - * @return int + * @return integer */ public function ymdToJd($year, $month, $day); } diff --git a/library/fisharebest/ext-calendar/src/FrenchCalendar.php b/library/fisharebest/ext-calendar/src/FrenchCalendar.php index dc74af24f6..6b020d523c 100644 --- a/library/fisharebest/ext-calendar/src/FrenchCalendar.php +++ b/library/fisharebest/ext-calendar/src/FrenchCalendar.php @@ -4,20 +4,20 @@ namespace Fisharebest\ExtCalendar; /** * Class FrenchCalendar - calculations for the French Republican calendar. * - * @author Greg Roach <fisharebest@gmail.com> + * @author Greg Roach <fisharebest@gmail.com> * @copyright (c) 2014 Greg Roach - * @license This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * @license This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. */ class FrenchCalendar extends AbstractCalendar implements CalendarInterface { /** See the GEDCOM specification */ @@ -35,7 +35,7 @@ class FrenchCalendar extends AbstractCalendar implements CalendarInterface { /** * Month lengths for regular years and leap-years. * - * @var int[][] + * @var integer[][] */ protected static $DAYS_IN_MONTH = array( 0 => array(1 => 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 5), @@ -49,8 +49,9 @@ class FrenchCalendar extends AbstractCalendar implements CalendarInterface { * were ever observed. Moves to a gregorian-like (fixed) system were proposed * but never implemented. * - * @param int $year - * @return bool + * @param integer $year + * + * @return boolean */ public function isLeapYear($year) { return $year % 4 == 3; @@ -59,9 +60,9 @@ class FrenchCalendar extends AbstractCalendar implements CalendarInterface { /** * Convert a Julian day number into a year/month/day. * - * @param $julian_day + * @param integer $julian_day * - * @return int[]; + * @return integer[] */ public function jdToYmd($julian_day) { $year = (int)(($julian_day - 2375109) * 4 / 1461) - 1; @@ -74,11 +75,11 @@ class FrenchCalendar extends AbstractCalendar implements CalendarInterface { /** * Convert a year/month/day into a Julian day number * - * @param int $year - * @param int $month - * @param int $day + * @param integer $year + * @param integer $month + * @param integer $day * - * @return int + * @return integer */ public function ymdToJd($year, $month, $day) { return 2375444 + $day + $month * 30 + $year * 365 + (int)($year / 4); diff --git a/library/fisharebest/ext-calendar/src/GregorianCalendar.php b/library/fisharebest/ext-calendar/src/GregorianCalendar.php index ae2d56442d..0ed29453f2 100644 --- a/library/fisharebest/ext-calendar/src/GregorianCalendar.php +++ b/library/fisharebest/ext-calendar/src/GregorianCalendar.php @@ -4,20 +4,20 @@ namespace Fisharebest\ExtCalendar; /** * class GregorianCalendar - calculations for the (proleptic) Gregorian calendar. * - * @author Greg Roach <fisharebest@gmail.com> + * @author Greg Roach <fisharebest@gmail.com> * @copyright (c) 2014 Greg Roach - * @license This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * @license This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. */ class GregorianCalendar extends JulianCalendar implements CalendarInterface { /** Same as PHP’s ext/calendar extension */ @@ -35,8 +35,9 @@ class GregorianCalendar extends JulianCalendar implements CalendarInterface { /** * Determine whether a year is a leap year. * - * @param int $year - * @return bool + * @param integer $year + * + * @return boolean */ public function isLeapYear($year) { if ($year < 0) { @@ -49,9 +50,9 @@ class GregorianCalendar extends JulianCalendar implements CalendarInterface { /** * Convert a Julian day number into a year/month/day. * - * @param $julian_day + * @param integer $julian_day * - * @return int[]; + * @return integer[] */ public function jdToYmd($julian_day) { $a = $julian_day + 32044; @@ -74,11 +75,11 @@ class GregorianCalendar extends JulianCalendar implements CalendarInterface { /** * Convert a year/month/day into a Julian day number * - * @param int $year - * @param int $month - * @param int $day + * @param integer $year + * @param integer $month + * @param integer $day * - * @return int + * @return integer */ public function ymdToJd($year, $month, $day) { if ($year < 0) { @@ -97,9 +98,9 @@ class GregorianCalendar extends JulianCalendar implements CalendarInterface { * * Uses the algorithm found in PHP’s ext/calendar/easter.c * - * @param int $year + * @param integer $year * - * @return int + * @return integer */ public function easterDays($year) { // The “golden” number diff --git a/library/fisharebest/ext-calendar/src/JewishCalendar.php b/library/fisharebest/ext-calendar/src/JewishCalendar.php index 88d93896a3..0705c4b521 100644 --- a/library/fisharebest/ext-calendar/src/JewishCalendar.php +++ b/library/fisharebest/ext-calendar/src/JewishCalendar.php @@ -9,20 +9,20 @@ use InvalidArgumentException; * Hebrew characters in the code have ISO-8859-8 encoding (and ASCII punctuation). * Hebrew characters in the comments have UTF-8 encoding (and Hebrew punctuation). * - * @author Greg Roach <fisharebest@gmail.com> + * @author Greg Roach <fisharebest@gmail.com> * @copyright (c) 2014 Greg Roach - * @license This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * @license This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. */ class JewishCalendar extends AbstractCalendar implements CalendarInterface { /** See the GEDCOM specification */ @@ -37,6 +37,9 @@ class JewishCalendar extends AbstractCalendar implements CalendarInterface { /** The maximum number of months in any year. */ const MAX_MONTHS_IN_YEAR = 13; + /** Optional behaviour for this calendar. */ + const EMULATE_BUG_54254 = 'EMULATE_BUG_54254'; + /** Place this symbol before the final letter of a sequence of numerals. */ const GERSHAYIM = '"'; // The gershayim symbol - ״ @@ -65,35 +68,35 @@ class JewishCalendar extends AbstractCalendar implements CalendarInterface { 300 => "\xf9", // Shin - ש 200 => "\xf8", // Resh - ר 100 => "\xf7", // Kuf - ק - 90 => "\xf6", // Tsadi - צ - 80 => "\xf4", // Pei - פ - 70 => "\xf2", // Ayin - ע - 60 => "\xf1", // Samech - ס - 50 => "\xf0", // Nun - נ - (note that we don’t distinguish end nuns from regular nuns) - 40 => "\xee", // Mem - מ - 30 => "\xec", // Lamed - ל - 20 => "\xeb", // Kaf - כ - 19 => "\xe9\xe8", // Yud Tet - יט - (to prevent 19 matching 17 + 2) - 18 => "\xe9\xe7", // Yud Het - יח - (to prevent 18 matching 17 + 1) - 17 => "\xe9\xe6", // Yud Zayin - יז - (to prevent 17 matching 16 + 1) - 16 => "\xe8\xe6", // Tet Zayin - טז - 15 => "\xe8\xe5", // Tet Vav - טו - 10 => "\xe9", // Yud - י - 9 => "\xe8", // Tet - ט - 8 => "\xe7", // Het - ח - 7 => "\xe6", // Zayin -ז - 6 => "\xe5", // Vav - ו - 5 => "\xe4", // Hei - ה - 4 => "\xe3", // Dalet - ד - 3 => "\xe2", // Gimel - ג - 2 => "\xe1", // Bet - ב - 1 => "\xe0", // Aleph - א + 90 => "\xf6", // Tsadi - צ + 80 => "\xf4", // Pei - פ + 70 => "\xf2", // Ayin - ע + 60 => "\xf1", // Samech - ס + 50 => "\xf0", // Nun - נ - (note that we don’t distinguish end nuns from regular nuns) + 40 => "\xee", // Mem - מ + 30 => "\xec", // Lamed - ל + 20 => "\xeb", // Kaf - כ + 19 => "\xe9\xe8", // Yud Tet - יט - (to prevent 19 matching 17 + 2) + 18 => "\xe9\xe7", // Yud Het - יח - (to prevent 18 matching 17 + 1) + 17 => "\xe9\xe6", // Yud Zayin - יז - (to prevent 17 matching 16 + 1) + 16 => "\xe8\xe6", // Tet Zayin - טז + 15 => "\xe8\xe5", // Tet Vav - טו + 10 => "\xe9", // Yud - י + 9 => "\xe8", // Tet - ט + 8 => "\xe7", // Het - ח + 7 => "\xe6", // Zayin -ז + 6 => "\xe5", // Vav - ו + 5 => "\xe4", // Hei - ה + 4 => "\xe3", // Dalet - ד + 3 => "\xe2", // Gimel - ג + 2 => "\xe1", // Bet - ב + 1 => "\xe0", // Aleph - א ); /** * These months have fixed lengths. Others are variable. * - * @var int[] + * @var integer[] */ private static $FIXED_MONTH_LENGTHS = array( 1 => 30, 4 => 29, 5 => 30, 7 => 29, 8 => 30, 9 => 29, 10 => 30, 11 => 29, 12 => 30, 13 => 29 @@ -105,47 +108,51 @@ class JewishCalendar extends AbstractCalendar implements CalendarInterface { * Second index is year type (-1, 0, 1) * Third index is month number (1 ... 13) * - * @var int[][][] + * @var integer[][][] */ private static $CUMULATIVE_DAYS = array( 0 => array( // Non-leap years - -1 => array( // Deficient years + self::DEFECTIVE_YEAR => array( 1 => 0, 30, 59, 88, 117, 147, 147, 176, 206, 235, 265, 294, 324 ), - 0 => array( // Regular years + self::REGULAR_YEAR => array( // Regular years 1 => 0, 30, 59, 89, 118, 148, 148, 177, 207, 236, 266, 295, 325 ), - 1 => array( // Complete years + self::COMPLETE_YEAR => array( // Complete years 1 => 0, 30, 60, 90, 119, 149, 149, 178, 208, 237, 267, 296, 326 ), ), 1 => array( // Leap years - -1 => array( // Deficient years + self::DEFECTIVE_YEAR => array( // Deficient years 1 => 0, 30, 59, 88, 117, 147, 177, 206, 236, 265, 295, 324, 354 ), - 0 => array( // Regular years + self::REGULAR_YEAR => array( // Regular years 1 => 0, 30, 59, 89, 118, 148, 178, 207, 237, 266, 296, 325, 355 ), - 1 => array( // Complete years + self::COMPLETE_YEAR => array( // Complete years 1 => 0, 30, 60, 90, 119, 149, 179, 208, 238, 267, 297, 326, 356 ), ), ); - /** * Rosh Hashanah cannot fall on a Sunday, Wednesday or Friday. Move the year start accordingly. * - * @var int[] + * @var integer[] */ private static $ROSH_HASHANAH = array(347998, 347997, 347997, 347998, 347997, 347998, 347997); + /** @var mixed[] special behaviour for this calendar */ + protected $options = array( + self::EMULATE_BUG_54254 => false, + ); + /** * Determine whether a year is a leap year. * - * @param int $year + * @param integer $year * - * @return bool + * @return boolean */ public function isLeapYear($year) { return (7 * $year + 1) % 19 < 7; @@ -154,9 +161,9 @@ class JewishCalendar extends AbstractCalendar implements CalendarInterface { /** * Convert a Julian day number into a year. * - * @param int $julian_day + * @param integer $julian_day * - * @return int; + * @return integer */ protected function jdToY($julian_day) { // Generate an approximate year - may be out by one either way. Add one to it. @@ -173,9 +180,9 @@ class JewishCalendar extends AbstractCalendar implements CalendarInterface { /** * Convert a Julian day number into a year/month/day. * - * @param int $julian_day + * @param integer $julian_day * - * @return int[]; + * @return integer[] */ public function jdToYmd($julian_day) { // Find the year, by adding one month at a time to use up the remaining days. @@ -189,7 +196,7 @@ class JewishCalendar extends AbstractCalendar implements CalendarInterface { } // PHP 5.4 and earlier converted non leap-year Adar into month 6, instead of month 7. - $month -= (Shim::shouldEmulateBug54254() && $month === 7 && !$this->isLeapYear($year)) ? 1 : 0; + $month -= ($month === 7 && $this->options[self::EMULATE_BUG_54254] && !$this->isLeapYear($year)) ? 1 : 0; return array($year, $month, $day); } @@ -197,9 +204,9 @@ class JewishCalendar extends AbstractCalendar implements CalendarInterface { /** * Calculate the Julian Day number of the first day in a year. * - * @param int $year + * @param integer $year * - * @return int + * @return integer */ protected function yToJd($year) { $div19 = (int)(($year - 1) / 19); @@ -226,11 +233,11 @@ class JewishCalendar extends AbstractCalendar implements CalendarInterface { /** * Convert a year/month/day into a Julian day number. * - * @param int $year - * @param int $month - * @param int $day + * @param integer $year + * @param integer $month + * @param integer $day * - * @return int + * @return integer */ public function ymdToJd($year, $month, $day) { return @@ -242,9 +249,9 @@ class JewishCalendar extends AbstractCalendar implements CalendarInterface { /** * Determine whether a year is normal, defective or complete. * - * @param int $year + * @param integer $year * - * @return int defective (-1), normal (0) or complete (1) + * @return integer defective (-1), normal (0) or complete (1) */ private function yearType($year) { $year_length = $this->yToJd($year + 1) - $this->yToJd($year); @@ -261,9 +268,9 @@ class JewishCalendar extends AbstractCalendar implements CalendarInterface { /** * Calculate the number of days in Heshvan. * - * @param int $year + * @param integer $year * - * @return int + * @return integer */ private function daysInMonthHeshvan($year) { if ($this->yearType($year) === self::COMPLETE_YEAR) { @@ -276,9 +283,9 @@ class JewishCalendar extends AbstractCalendar implements CalendarInterface { /** * Calculate the number of days in Kislev. * - * @param int $year + * @param integer $year * - * @return int + * @return integer */ private function daysInMonthKislev($year) { if ($this->yearType($year) === self::DEFECTIVE_YEAR) { @@ -291,9 +298,9 @@ class JewishCalendar extends AbstractCalendar implements CalendarInterface { /** * Calculate the number of days in Adar I. * - * @param int $year + * @param integer $year * - * @return int + * @return integer */ private function daysInMonthAdarI($year) { if ($this->isLeapYear($year)) { @@ -306,11 +313,10 @@ class JewishCalendar extends AbstractCalendar implements CalendarInterface { /** * Calculate the number of days in a given month. * - * @param int $year - * @param int $month - * - * @return int + * @param integer $year + * @param integer $month * + * @return integer * @throws InvalidArgumentException */ public function daysInMonth($year, $month) { @@ -334,7 +340,7 @@ class JewishCalendar extends AbstractCalendar implements CalendarInterface { * * @link https://bugs.php.net/bug.php?id=54254 * - * @param int $year + * @param integer $year * * @return string[] */ @@ -347,8 +353,8 @@ class JewishCalendar extends AbstractCalendar implements CalendarInterface { "\xeb\xf1\xec\xe5", // Kislev - כסלו "\xe8\xe1\xfa", // Tevet - טבת "\xf9\xe1\xe8", // Shevat - שבט - $leap_year ? (Shim::shouldEmulateBug54254() ? "\xe0\xe3\xf8" : "\xe0\xe3\xf8 \xe0'") : "\xe0\xe3\xf8", // Adar I - אדר - אדר א׳ - אדר - $leap_year ? (Shim::shouldEmulateBug54254() ? "'\xe0\xe3\xf8 \xe1" : "\xe0\xe3\xf8 \xe1'") : "\xe0\xe3\xf8", // Adar II - 'אדר ב - אדר ב׳ - אדר + $leap_year ? ($this->options[self::EMULATE_BUG_54254] ? "\xe0\xe3\xf8" : "\xe0\xe3\xf8 \xe0'") : "\xe0\xe3\xf8", // Adar I - אדר - אדר א׳ - אדר + $leap_year ? ($this->options[self::EMULATE_BUG_54254] ? "'\xe0\xe3\xf8 \xe1" : "\xe0\xe3\xf8 \xe1'") : "\xe0\xe3\xf8", // Adar II - 'אדר ב - אדר ב׳ - אדר "\xf0\xe9\xf1\xef", // Nisan - ניסן "\xe0\xe9\xe9\xf8", // Iyar - אייר "\xf1\xe9\xe5\xef", // Sivan - סיון @@ -361,8 +367,8 @@ class JewishCalendar extends AbstractCalendar implements CalendarInterface { /** * The Hebrew name of a given month. * - * @param int $year - * @param int $month + * @param integer $year + * @param integer $month * * @return string */ @@ -398,8 +404,8 @@ class JewishCalendar extends AbstractCalendar implements CalendarInterface { /** * Convert a number into Hebrew numerals. * - * @param int $number - * @param bool $gereshayim Add punctuation to numeric values + * @param integer $number + * @param boolean $gereshayim Add punctuation to numeric values * * @return string */ @@ -426,10 +432,10 @@ class JewishCalendar extends AbstractCalendar implements CalendarInterface { /** * Format a year using Hebrew numerals. * - * @param int $year - * @param bool $alafim_geresh Add a geresh (׳) after thousands - * @param bool $alafim Add the word for thousands after the thousands - * @param bool $gereshayim Add geresh (׳) and gershayim (״) punctuation to numeric values + * @param integer $year + * @param boolean $alafim_geresh Add a geresh (׳) after thousands + * @param boolean $alafim Add the word for thousands after the thousands + * @param boolean $gereshayim Add geresh (׳) and gershayim (״) punctuation to numeric values * * @return string */ @@ -444,6 +450,7 @@ class JewishCalendar extends AbstractCalendar implements CalendarInterface { if ($alafim) { $thousands .= self::ALAFIM; } + return $thousands . $this->numberToHebrewNumerals($year % 1000, $gereshayim); } } @@ -451,12 +458,12 @@ class JewishCalendar extends AbstractCalendar implements CalendarInterface { /** * Convert a Julian Day number into a Hebrew date. * - * @param int $julian_day - * @param bool $alafim_garesh - * @param bool $alafim - * @param bool $gereshayim + * @param integer $julian_day + * @param boolean $alafim_garesh + * @param boolean $alafim + * @param boolean $gereshayim * - * @return string $string + * @return string */ public function jdToHebrew($julian_day, $alafim_garesh, $alafim, $gereshayim) { list($year, $month, $day) = $this->jdToYmd($julian_day); diff --git a/library/fisharebest/ext-calendar/src/JulianCalendar.php b/library/fisharebest/ext-calendar/src/JulianCalendar.php index 05b38a6552..1294d5c842 100644 --- a/library/fisharebest/ext-calendar/src/JulianCalendar.php +++ b/library/fisharebest/ext-calendar/src/JulianCalendar.php @@ -4,20 +4,20 @@ namespace Fisharebest\ExtCalendar; /** * Class JulianCalendar - calculations for the Julian calendar. * - * @author Greg Roach <fisharebest@gmail.com> + * @author Greg Roach <fisharebest@gmail.com> * @copyright (c) 2014 Greg Roach - * @license This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * @license This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. */ class JulianCalendar extends AbstractCalendar implements CalendarInterface { /** See the GEDCOM specification */ @@ -29,7 +29,7 @@ class JulianCalendar extends AbstractCalendar implements CalendarInterface { /** * Month lengths for regular years and leap-years. * - * @var int[][] + * @var integer[][] */ protected static $DAYS_IN_MONTH = array( 0 => array(1 => 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31), @@ -39,8 +39,9 @@ class JulianCalendar extends AbstractCalendar implements CalendarInterface { /** * Determine whether a year is a leap year. * - * @param int $year - * @return bool + * @param integer $year + * + * @return boolean */ public function isLeapYear($year) { if ($year < 0) { @@ -55,7 +56,7 @@ class JulianCalendar extends AbstractCalendar implements CalendarInterface { * * @param $julian_day * - * @return int[]; + * @return integer[] */ public function jdToYmd($julian_day) { $c = $julian_day + 32082; @@ -77,11 +78,11 @@ class JulianCalendar extends AbstractCalendar implements CalendarInterface { /** * Convert a year/month/day into a Julian day number * - * @param int $year - * @param int $month - * @param int $day + * @param integer $year + * @param integer $month + * @param integer $day * - * @return int + * @return integer */ public function ymdToJd($year, $month, $day) { if ($year < 0) { @@ -100,9 +101,9 @@ class JulianCalendar extends AbstractCalendar implements CalendarInterface { * * Uses the algorithm found in PHP’s ext/calendar/easter.c * - * @param int $year + * @param integer $year * - * @return int + * @return integer */ public function easterDays($year) { // The “golden” number diff --git a/library/fisharebest/ext-calendar/src/PersianCalendar.php b/library/fisharebest/ext-calendar/src/PersianCalendar.php index 179c93b074..5827b26457 100644 --- a/library/fisharebest/ext-calendar/src/PersianCalendar.php +++ b/library/fisharebest/ext-calendar/src/PersianCalendar.php @@ -4,20 +4,20 @@ namespace Fisharebest\ExtCalendar; /** * Class PersianCalendar - calculations for the Persian (Jalali) calendar. * - * @author Greg Roach <fisharebest@gmail.com> + * @author Greg Roach <fisharebest@gmail.com> * @copyright (c) 2014 Greg Roach - * @license This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * @license This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. */ class PersianCalendar extends AbstractCalendar implements CalendarInterface { /** See the GEDCOM specification */ @@ -29,7 +29,7 @@ class PersianCalendar extends AbstractCalendar implements CalendarInterface { /** * Month lengths for regular years and leap-years. * - * @var int[][] + * @var integer[][] */ protected static $DAYS_IN_MONTH = array( 0 => array(1 => 31, 31, 31, 31, 31, 31, 30, 30, 30, 30, 30, 29), @@ -39,7 +39,7 @@ class PersianCalendar extends AbstractCalendar implements CalendarInterface { /** * In each 128 year cycle, the following years are leap years. * - * @var int[] + * @var integer[] */ private static $LEAP_YEAR_CYCLE = array( 0, 5, 9, 13, 17, 21, 25, 29, 34, 38, 42, 46, 50, 54, 58, 62, 67, 71, 75, 79, 83, 87, 91, 95, 100, 104, 108, 112, 116, 120, 124 @@ -48,8 +48,9 @@ class PersianCalendar extends AbstractCalendar implements CalendarInterface { /** * Determine whether a year is a leap year. * - * @param int $year - * @return bool + * @param integer $year + * + * @return boolean */ public function isLeapYear($year) { return in_array((($year + 2346) % 2820) % 128, self::$LEAP_YEAR_CYCLE); @@ -58,9 +59,9 @@ class PersianCalendar extends AbstractCalendar implements CalendarInterface { /** * Convert a Julian day number into a year/month/day. * - * @param $julian_day + * @param integer $julian_day * - * @return int[]; + * @return integer[] */ public function jdToYmd($julian_day) { $depoch = $julian_day - 2121447; @@ -86,11 +87,11 @@ class PersianCalendar extends AbstractCalendar implements CalendarInterface { /** * Convert a year/month/day into a Julian day number * - * @param int $year - * @param int $month - * @param int $day + * @param integer $year + * @param integer $month + * @param integer $day * - * @return int + * @return integer */ public function ymdToJd($year, $month, $day) { $epbase = $year - (($year >= 0) ? 474 : 473); diff --git a/library/fisharebest/ext-calendar/src/Shim.php b/library/fisharebest/ext-calendar/src/Shim.php index 4a87a326b5..b3df5f107b 100644 --- a/library/fisharebest/ext-calendar/src/Shim.php +++ b/library/fisharebest/ext-calendar/src/Shim.php @@ -6,22 +6,22 @@ use InvalidArgumentException; /** * class Shim - PHP implementations of functions from the PHP calendar extension. * - * @link http://php.net/manual/en/book.calendar.php + * @link http://php.net/manual/en/book.calendar.php * - * @author Greg Roach <fisharebest@gmail.com> + * @author Greg Roach <fisharebest@gmail.com> * @copyright (c) 2014 Greg Roach - * @license This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * @license This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. */ class Shim { /** @var FrenchCalendar */ @@ -83,7 +83,7 @@ class Shim { 'Adar II', 'Nisan', 'Iyyar', 'Sivan', 'Tammuz', 'Av', 'Elul', ); - /** @var string[] Names of the months of the Jewish calendar (before PHP bug 54254 was fixed)*/ + /** @var string[] Names of the months of the Jewish calendar (before PHP bug 54254 was fixed) */ private static $MONTH_NAMES_JEWISH_54254 = array( '', 'Tishri', 'Heshvan', 'Kislev', 'Tevet', 'Shevat', 'AdarI', 'AdarII', 'Nisan', 'Iyyar', 'Sivan', 'Tammuz', 'Av', 'Elul', @@ -100,15 +100,17 @@ class Shim { * @return void */ public static function create( - FrenchCalendar $french_calendar = null, + FrenchCalendar $french_calendar = null, GregorianCalendar $gregorian_calendar = null, - JewishCalendar $jewish_calendar = null, - JulianCalendar $julian_calendar = null + JewishCalendar $jewish_calendar = null, + JulianCalendar $julian_calendar = null ) { - self::$french_calendar = $french_calendar ?: new FrenchCalendar; + self::$french_calendar = $french_calendar ?: new FrenchCalendar; self::$gregorian_calendar = $gregorian_calendar ?: new GregorianCalendar; - self::$jewish_calendar = $jewish_calendar ?: new JewishCalendar; - self::$julian_calendar = $julian_calendar ?: new JulianCalendar; + self::$jewish_calendar = $jewish_calendar ?: new JewishCalendar(array( + JewishCalendar::EMULATE_BUG_54254 => self::shouldEmulateBug54254(), + )); + self::$julian_calendar = $julian_calendar ?: new JulianCalendar; defined('CAL_NUM_CALS') || require __DIR__ . '/shims.php'; } @@ -122,7 +124,7 @@ class Shim { * * @link https://bugs.php.net/bug.php?id=54254 * - * @return bool + * @return boolean */ public static function shouldEmulateBug54254() { return version_compare(PHP_VERSION, '5.5.0', '<'); @@ -138,7 +140,7 @@ class Shim { * @link https://bugs.php.net/bug.php?id=67960 * @link https://github.com/php/php-src/pull/806 * - * @return bool + * @return boolean */ public static function shouldEmulateBug67960() { return true; @@ -152,7 +154,7 @@ class Shim { * * @link https://bugs.php.net/bug.php?id=67976 * - * @return bool + * @return boolean */ public static function shouldEmulateBug67976() { return true; @@ -166,11 +168,11 @@ class Shim { * @link https://php.net/cal_days_in_month * @link https://bugs.php.net/bug.php?id=67976 * - * @param int $calendar_id - * @param int $month - * @param int $year + * @param integer $calendar_id + * @param integer $month + * @param integer $year * - * @return int The number of days in the specified month + * @return integer|boolean The number of days in the specified month, or false on error */ public static function calDaysInMonth($calendar_id, $month, $year) { switch ($calendar_id) { @@ -195,15 +197,15 @@ class Shim { * Calculate the number of days in a month in a specified (Gregorian or Julian) calendar. * * @param CalendarInterface $calendar - * @param int $year - * @param int $month + * @param integer $year + * @param integer $month * - * @return int + * @return integer|boolean */ private static function calDaysInMonthCalendar(CalendarInterface $calendar, $year, $month) { try { return $calendar->daysInMonth($year, $month); - } catch (InvalidArgumentException $ex){ + } catch (InvalidArgumentException $ex) { return trigger_error('invalid date.', E_USER_WARNING); } } @@ -213,10 +215,10 @@ class Shim { * * Mimic PHP’s validation of the parameters * - * @param int $year - * @param int $month + * @param integer $year + * @param integer $month * - * @return int + * @return integer|boolean */ private static function calDaysInMonthFrench($year, $month) { if ($month == 13 && $year == 14 && self::shouldEmulateBug67976()) { @@ -235,10 +237,10 @@ class Shim { * * @link https://php.net/cal_from_jd * - * @param int $julian_day Julian Day number - * @param int $calendar_id Calendar constant + * @param integer $julian_day Julian Day number + * @param integer $calendar_id Calendar constant * - * @return array + * @return array|boolean */ public static function calFromJd($julian_day, $calendar_id) { switch ($calendar_id) { @@ -250,6 +252,7 @@ class Shim { case CAL_JEWISH: $months = self::jdMonthNameJewishMonths($julian_day); + return self::calFromJdCalendar($julian_day, self::jdToCalendar(self::$jewish_calendar, $julian_day, 347998, 324542846), $months, $months); case CAL_JULIAN: @@ -263,26 +266,26 @@ class Shim { /** * Convert a Julian day number to a calendar and provide details. * - * @param int $julian_day + * @param integer $julian_day * @param string $mdy * @param string[] $months * @param string[] $months_short * - * @return mixed[] + * @return array */ private static function calFromJdCalendar($julian_day, $mdy, $months, $months_short) { list($month, $day, $year) = explode('/', $mdy); return array( - 'date' => $month . '/' . $day . '/' . $year, - 'month' => (int)$month, - 'day' => (int)$day, - 'year' => (int)$year, - 'dow' => self::jdDayOfWeek($julian_day, 0), + 'date' => $month . '/' . $day . '/' . $year, + 'month' => (int)$month, + 'day' => (int)$day, + 'year' => (int)$year, + 'dow' => self::jdDayOfWeek($julian_day, 0), 'abbrevdayname' => self::jdDayOfWeek($julian_day, 2), - 'dayname' => self::jdDayOfWeek($julian_day, 1), - 'abbrevmonth' => $months_short[$month], - 'monthname' => $months[$month], + 'dayname' => self::jdDayOfWeek($julian_day, 1), + 'abbrevmonth' => $months_short[$month], + 'monthname' => $months[$month], ); } @@ -293,9 +296,9 @@ class Shim { * * @link https://php.net/cal_info * - * @param int $calendar_id + * @param integer $calendar_id * - * @return mixed[] + * @return array|boolean */ public static function calInfo($calendar_id) { switch ($calendar_id) { @@ -307,6 +310,7 @@ class Shim { case CAL_JEWISH: $months = self::shouldEmulateBug54254() ? self::$MONTH_NAMES_JEWISH_54254 : self::$MONTH_NAMES_JEWISH_LEAP_YEAR; + return self::calInfoCalendar($months, $months, 30, 'Jewish', 'CAL_JEWISH'); case CAL_JULIAN: @@ -330,11 +334,11 @@ class Shim { * * @param string[] $month_names * @param string[] $month_names_short - * @param int $max_days_in_month + * @param integer $max_days_in_month * @param string $calendar_name * @param string $calendar_symbol * - * @return mixed[] + * @return array */ private static function calInfoCalendar($month_names, $month_names_short, $max_days_in_month, $calendar_name, $calendar_symbol) { return array( @@ -353,15 +357,15 @@ class Shim { * * @link https://php.net/cal_to_jd * - * @param int $calendar - * @param int $month - * @param int $day - * @param int $year + * @param integer $calendar_id + * @param integer $month + * @param integer $day + * @param integer $year * - * @return int + * @return integer|boolean */ - public static function calToJd($calendar, $month, $day, $year) { - switch ($calendar) { + public static function calToJd($calendar_id, $month, $day, $year) { + switch ($calendar_id) { case CAL_FRENCH: return self::frenchToJd($month, $day, $year); @@ -375,7 +379,7 @@ class Shim { return self::julianToJd($month, $day, $year); default: - return trigger_error('invalid calendar ID ' . $calendar . '.', E_USER_WARNING); + return trigger_error('invalid calendar ID ' . $calendar_id . '.', E_USER_WARNING); } } @@ -386,9 +390,9 @@ class Shim { * * @link https://php.net/easter_date * - * @param int $year + * @param integer $year * - * @return int + * @return integer|boolean */ public static function easterDate($year) { if ($year < 1970 || $year > 2037) { @@ -399,12 +403,12 @@ class Shim { // Calculate time-zone offset $date_time = new \DateTime('now', new \DateTimeZone(date_default_timezone_get())); - $offset_seconds = $date_time->format('Z'); + $offset_seconds = (int)$date_time->format('Z'); if ($days < 11) { - return jdtounix(self::$gregorian_calendar->ymdToJd($year, 3, $days + 21)) - $offset_seconds; + return Shim::jdtounix(self::$gregorian_calendar->ymdToJd($year, 3, $days + 21)) - $offset_seconds; } else { - return jdtounix(self::$gregorian_calendar->ymdToJd($year, 4, $days - 10)) - $offset_seconds; + return Shim::jdtounix(self::$gregorian_calendar->ymdToJd($year, 4, $days - 10)) - $offset_seconds; } } @@ -415,10 +419,10 @@ class Shim { * * @link https://php.net/easter_days * - * @param int $year - * @param int $method Use the Julian or Gregorian calendar + * @param integer $year + * @param integer $method Use the Julian or Gregorian calendar * - * @return int + * @return integer */ public static function easterDays($year, $method) { if ( @@ -439,11 +443,11 @@ class Shim { * * @link https://php.net/FrenchToJD * - * @param int $month - * @param int $day - * @param int $year + * @param integer $month + * @param integer $day + * @param integer $year * - * @return int + * @return integer */ public static function frenchToJd($month, $day, $year) { if ($year <= 0) { @@ -460,11 +464,11 @@ class Shim { * * @link https://php.net/GregorianToJD * - * @param int $month - * @param int $day - * @param int $year + * @param integer $month + * @param integer $day + * @param integer $year * - * @return int + * @return integer */ public static function gregorianToJd($month, $day, $year) { if ($year == 0) { @@ -482,10 +486,10 @@ class Shim { * @link https://php.net/JDDayOfWeek * @link https://bugs.php.net/bug.php?id=67960 * - * @param int $julian_day - * @param int $mode + * @param integer $julian_day + * @param integer $mode * - * @return int|string + * @return integer|string */ public static function jdDayOfWeek($julian_day, $mode) { $day_of_week = ($julian_day + 1) % 7; @@ -494,14 +498,14 @@ class Shim { } switch ($mode) { - case 1: // 1, not CAL_DOW_LONG - see bug 67960 - return self::$DAY_NAMES[$day_of_week]; + case 1: // 1, not CAL_DOW_LONG - see bug 67960 + return self::$DAY_NAMES[$day_of_week]; - case 2: // 2, not CAL_DOW_SHORT - see bug 67960 - return self::$DAY_NAMES_SHORT[$day_of_week]; + case 2: // 2, not CAL_DOW_SHORT - see bug 67960 + return self::$DAY_NAMES_SHORT[$day_of_week]; - default: // CAL_DOW_DAYNO or anything else - return $day_of_week; + default: // CAL_DOW_DAYNO or anything else + return $day_of_week; } } @@ -512,31 +516,31 @@ class Shim { * * @link https://php.net/JDMonthName * - * @param int $julian_day - * @param int $mode + * @param integer $julian_day + * @param integer $mode * * @return string */ public static function jdMonthName($julian_day, $mode) { switch ($mode) { - case CAL_MONTH_GREGORIAN_LONG: - return self::jdMonthNameCalendar(self::$gregorian_calendar, $julian_day, self::$MONTH_NAMES); + case CAL_MONTH_GREGORIAN_LONG: + return self::jdMonthNameCalendar(self::$gregorian_calendar, $julian_day, self::$MONTH_NAMES); - case CAL_MONTH_JULIAN_LONG: - return self::jdMonthNameCalendar(self::$julian_calendar, $julian_day, self::$MONTH_NAMES); + case CAL_MONTH_JULIAN_LONG: + return self::jdMonthNameCalendar(self::$julian_calendar, $julian_day, self::$MONTH_NAMES); - case CAL_MONTH_JULIAN_SHORT: - return self::jdMonthNameCalendar(self::$julian_calendar, $julian_day, self::$MONTH_NAMES_SHORT); + case CAL_MONTH_JULIAN_SHORT: + return self::jdMonthNameCalendar(self::$julian_calendar, $julian_day, self::$MONTH_NAMES_SHORT); - case CAL_MONTH_JEWISH: - return self::jdMonthNameCalendar(self::$jewish_calendar, $julian_day, self::jdMonthNameJewishMonths($julian_day)); + case CAL_MONTH_JEWISH: + return self::jdMonthNameCalendar(self::$jewish_calendar, $julian_day, self::jdMonthNameJewishMonths($julian_day)); - case CAL_MONTH_FRENCH: - return self::jdMonthNameCalendar(self::$french_calendar, $julian_day, self::$MONTH_NAMES_FRENCH); + case CAL_MONTH_FRENCH: + return self::jdMonthNameCalendar(self::$french_calendar, $julian_day, self::$MONTH_NAMES_FRENCH); - case CAL_MONTH_GREGORIAN_SHORT: - default: - return self::jdMonthNameCalendar(self::$gregorian_calendar, $julian_day, self::$MONTH_NAMES_SHORT); + case CAL_MONTH_GREGORIAN_SHORT: + default: + return self::jdMonthNameCalendar(self::$gregorian_calendar, $julian_day, self::$MONTH_NAMES_SHORT); } } @@ -545,7 +549,7 @@ class Shim { * with given set of month names. * * @param CalendarInterface $calendar - * @param int $julian_day + * @param integer $julian_day * @param string[] $months * * @return string @@ -559,7 +563,7 @@ class Shim { /** * Determine which month names to use for the Jewish calendar. * - * @param int $julian_day + * @param integer $julian_day * * @return string[] */ @@ -579,13 +583,13 @@ class Shim { * Julian days outside the specified range are returned as “0/0/0”. * * @param CalendarInterface $calendar - * @param int $julian_day - * @param int $min_jd - * @param int $max_jd + * @param integer $julian_day + * @param integer $min_jd + * @param integer $max_jd * * @return string */ - private static function jdToCalendar($calendar, $julian_day, $min_jd, $max_jd) { + private static function jdToCalendar(CalendarInterface $calendar, $julian_day, $min_jd, $max_jd) { if ($julian_day >= $min_jd && $julian_day <= $max_jd) { list($year, $month, $day) = $calendar->jdToYmd($julian_day); @@ -602,7 +606,7 @@ class Shim { * * @link https://php.net/JDToFrench * - * @param int $julian_day A Julian Day number + * @param integer $julian_day A Julian Day number * * @return string A string of the form "month/day/year" */ @@ -619,7 +623,7 @@ class Shim { * * @link https://php.net/JDToGregorian * - * @param int $julian_day A Julian Day number + * @param integer $julian_day A Julian Day number * * @return string A string of the form "month/day/year" */ @@ -637,11 +641,11 @@ class Shim { * * @link https://php.net/JdtoJewish * - * @param int $julian_day A Julian Day number - * @param bool $hebrew If true, the date is returned in Hebrew text - * @param int $fl If $hebrew is true, then add alafim and gereshayim to the text + * @param integer $julian_day A Julian Day number + * @param boolean $hebrew If true, the date is returned in Hebrew text + * @param integer $fl If $hebrew is true, then add alafim and gereshayim to the text * - * @return string A string of the form "month/day/year" + * @return string|boolean A string of the form "month/day/year", or false on error */ public static function jdToJewish($julian_day, $hebrew, $fl) { if ($hebrew) { @@ -649,7 +653,12 @@ class Shim { return trigger_error('Year out of range (0-9999).', E_USER_WARNING); } - return self::$jewish_calendar->jdToHebrew($julian_day, $fl & CAL_JEWISH_ADD_ALAFIM_GERESH, $fl & CAL_JEWISH_ADD_ALAFIM, $fl & CAL_JEWISH_ADD_GERESHAYIM); + return self::$jewish_calendar->jdToHebrew( + $julian_day, + (bool)($fl & CAL_JEWISH_ADD_ALAFIM_GERESH), + (bool)($fl & CAL_JEWISH_ADD_ALAFIM), + (bool)($fl & CAL_JEWISH_ADD_GERESHAYIM) + ); } else { // The upper limit is hard-coded into PHP to prevent numeric overflow on 32 bit systems. return self::jdToCalendar(self::$jewish_calendar, $julian_day, 347998, 324542846); @@ -663,7 +672,7 @@ class Shim { * * @link https://php.net/JDToJulian * - * @param int $julian_day A Julian Day number + * @param integer $julian_day A Julian Day number * * @return string A string of the form "month/day/year" */ @@ -681,9 +690,9 @@ class Shim { * * @link https://php.net/jdtounix * - * @param int $julian_day + * @param integer $julian_day * - * @return false|int + * @return integer|false */ public static function jdToUnix($julian_day) { if ($julian_day >= 2440588 && $julian_day <= 2465343) { @@ -700,11 +709,11 @@ class Shim { * * @link https://php.net/JewishToJD * - * @param int $month - * @param int $day - * @param int $year + * @param integer $month + * @param integer $day + * @param integer $year * - * @return int + * @return integer */ public static function jewishToJd($month, $day, $year) { if ($year <= 0) { @@ -721,11 +730,11 @@ class Shim { * * @link https://php.net/JdToJulian * - * @param int $month - * @param int $day - * @param int $year + * @param integer $month + * @param integer $day + * @param integer $year * - * @return int + * @return integer */ public static function julianToJd($month, $day, $year) { if ($year == 0) { @@ -742,9 +751,9 @@ class Shim { * * @link https://php.net/unixtojd * - * @param int $timestamp + * @param integer $timestamp * - * @return false|int + * @return false|integer */ public static function unixToJd($timestamp) { if ($timestamp < 0) { diff --git a/library/fisharebest/ext-calendar/src/shims.php b/library/fisharebest/ext-calendar/src/shims.php index d0a5eee4ba..dc2cb1838a 100644 --- a/library/fisharebest/ext-calendar/src/shims.php +++ b/library/fisharebest/ext-calendar/src/shims.php @@ -3,20 +3,20 @@ * Link the global functions and constants from ext/calendar interface to our * own shim functions. * - * @author Greg Roach <fisharebest@gmail.com> + * @author Greg Roach <fisharebest@gmail.com> * @copyright (c) 2014 Greg Roach - * @license This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * @license This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. */ use Fisharebest\ExtCalendar\Shim; @@ -44,101 +44,101 @@ define('CAL_JEWISH_ADD_ALAFIM', 4); define('CAL_JEWISH_ADD_GERESHAYIM', 8); /** - * @param int $calendar_id - * @param int $month - * @param int $year + * @param integer $calendar_id + * @param integer $month + * @param integer $year * - * @return int + * @return integer|boolean */ function cal_days_in_month($calendar_id, $month, $year) { return Shim::calDaysInMonth($calendar_id, $month, $year); } /** - * @param int $julian_day - * @param int $calendar_id + * @param integer $julian_day + * @param integer $calendar_id * - * @return array + * @return array|boolean */ function cal_from_jd($julian_day, $calendar_id) { return Shim::calFromJd($julian_day, $calendar_id); } /** - * @param int $calendar_id + * @param integer $calendar_id * - * @return array + * @return array|boolean */ function cal_info($calendar_id = -1) { return Shim::calInfo($calendar_id); } /** - * @param int $calendar_id - * @param int $month - * @param int $day - * @param int $year + * @param integer $calendar_id + * @param integer $month + * @param integer $day + * @param integer $year * - * @return int + * @return integer|boolean */ function cal_to_jd($calendar_id, $month, $day, $year) { return Shim::calToJd($calendar_id, $month, $day, $year); } /** - * @param int $year + * @param integer|null $year * - * @return int + * @return integer|boolean */ function easter_date($year = null) { - return Shim::easterDate($year ? $year : date('Y')); + return Shim::easterDate($year ? $year : (int)date('Y')); } /** - * @param int $year - * @param int $method + * @param integer|null $year + * @param integer $method * - * @return int + * @return integer */ function easter_days($year = null, $method = CAL_EASTER_DEFAULT) { - return Shim::easterDays($year ? $year : date('Y'), $method); + return Shim::easterDays($year ? $year : (int)date('Y'), $method); } /** - * @param int $month - * @param int $day - * @param int $year + * @param integer $month + * @param integer $day + * @param integer $year * - * @return int + * @return integer */ function FrenchToJD($month, $day, $year) { return Shim::FrenchToJD($month, $day, $year); } /** - * @param int $month - * @param int $day - * @param int $year + * @param integer $month + * @param integer $day + * @param integer $year * - * @return int + * @return integer */ function GregorianToJD($month, $day, $year) { return Shim::GregorianToJD($month, $day, $year); } /** - * @param int $julian_day - * @param int $mode + * @param integer $julian_day + * @param integer $mode * - * @return mixed + * @return integer|string */ function JDDayOfWeek($julian_day, $mode = CAL_DOW_DAYNO) { return Shim::JDDayOfWeek($julian_day, $mode); } /** - * @param int $julian_day - * @param int $mode + * @param integer $julian_day + * @param integer $mode * * @return string */ @@ -147,7 +147,7 @@ function JDMonthName($julian_day, $mode) { } /** - * @param int $julian_day + * @param integer $julian_day * * @return string */ @@ -156,7 +156,7 @@ function JDToFrench($julian_day) { } /** - * @param int $julian_day + * @param integer $julian_day * * @return string */ @@ -165,18 +165,18 @@ function JDToGregorian($julian_day) { } /** - * @param int $julian_day - * @param bool $hebrew - * @param int $flags + * @param integer $julian_day + * @param boolean $hebrew + * @param integer $flags * - * @return string + * @return string|boolean */ function jdtojewish($julian_day, $hebrew = false, $flags = 0) { return Shim::jdtojewish($julian_day, $hebrew, $flags); } /** - * @param int $julian_day + * @param integer $julian_day * * @return string */ @@ -185,40 +185,40 @@ function JDToJulian($julian_day) { } /** - * @param int $julian_day + * @param integer $julian_day * - * @return int + * @return integer|false */ function jdtounix($julian_day) { return Shim::jdtounix($julian_day); } /** - * @param int $month - * @param int $day - * @param int $year + * @param integer $month + * @param integer $day + * @param integer $year * - * @return int + * @return integer */ function JewishToJD($month, $day, $year) { return Shim::JewishToJD($month, $day, $year); } /** - * @param int $month - * @param int $day - * @param int $year + * @param integer $month + * @param integer $day + * @param integer $year * - * @return int + * @return integer */ function JulianToJD($month, $day, $year) { return Shim::JulianToJD($month, $day, $year); } /** - * @param int $timestamp + * @param integer|null $timestamp * - * @return int + * @return false|integer */ function unixtojd($timestamp = null) { return Shim::unixtojd($timestamp ? $timestamp : time()); |
