summaryrefslogtreecommitdiff
path: root/library/fisharebest/ext-calendar
diff options
context:
space:
mode:
authorGreg Roach <fisharebest@gmail.com>2014-09-18 16:07:18 +0100
committerGreg Roach <fisharebest@gmail.com>2014-09-18 16:07:18 +0100
commitd41520a343b581ec5e36379e39e1d04685053a99 (patch)
tree1721d3e8a845a37bbfeb3b5c56d431fdbad786d1 /library/fisharebest/ext-calendar
parent638c61f00f33ca62228ad219b6660398f5abdafe (diff)
downloadwebtrees-d41520a343b581ec5e36379e39e1d04685053a99.tar.gz
webtrees-d41520a343b581ec5e36379e39e1d04685053a99.tar.bz2
webtrees-d41520a343b581ec5e36379e39e1d04685053a99.zip
Update vendor code: zend-framework and ext-calendar
Diffstat (limited to 'library/fisharebest/ext-calendar')
-rw-r--r--library/fisharebest/ext-calendar/CHANGELOG.md3
-rw-r--r--library/fisharebest/ext-calendar/src/JewishCalendar.php117
-rw-r--r--library/fisharebest/ext-calendar/src/Shim.php22
3 files changed, 84 insertions, 58 deletions
diff --git a/library/fisharebest/ext-calendar/CHANGELOG.md b/library/fisharebest/ext-calendar/CHANGELOG.md
index 13a7d6d2b9..1827c8f821 100644
--- a/library/fisharebest/ext-calendar/CHANGELOG.md
+++ b/library/fisharebest/ext-calendar/CHANGELOG.md
@@ -1,6 +1,9 @@
CHANGE LOG
==========
+## 1.1.2 (2014-09-16)
+ - Fix #1; add support for the third parameter in jdtojewish().
+
## 1.1.1 (2014-09-14)
- Cannot inherit abstract classes in PHP 5.3.0 - 5.3.8.
diff --git a/library/fisharebest/ext-calendar/src/JewishCalendar.php b/library/fisharebest/ext-calendar/src/JewishCalendar.php
index 038188fcd0..adf8b2dc34 100644
--- a/library/fisharebest/ext-calendar/src/JewishCalendar.php
+++ b/library/fisharebest/ext-calendar/src/JewishCalendar.php
@@ -21,7 +21,7 @@ namespace Fisharebest\ExtCalendar;
* 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 Calendar implements CalendarInterface{
+class JewishCalendar extends Calendar implements CalendarInterface {
/** Same as PHP’s ext/calendar extension */
const PHP_CALENDAR_NAME = 'Jewish';
@@ -56,13 +56,13 @@ class JewishCalendar extends Calendar implements CalendarInterface{
const ALAFIM = 'אלפים';
/** A year that is one day shorter than normal. */
- const DEFECTIVE_YEAR = -1;
+ const DEFECTIVE_YEAR = -1;
/** A year that has the normal number of days. */
- const REGULAR_YEAR = 0;
+ const REGULAR_YEAR = 0;
/** A year that is one day longer than normal. */
- const COMPLETE_YEAR = 1;
+ const COMPLETE_YEAR = 1;
/**
* Hebrew numbers are represented by letters, similar to roman numerals.
@@ -70,15 +70,6 @@ class JewishCalendar extends Calendar implements CalendarInterface{
* @var string[]
*/
private static $HEBREW_NUMERALS = array(
- 9000 => 'ט',
- 8000 => 'ח',
- 7000 => 'ז',
- 6000 => 'ו',
- 5000 => 'ה',
- 4000 => 'ד',
- 3000 => 'ג',
- 2000 => 'ב',
- 1000 => 'א',
400 => 'ת',
300 => 'ש',
200 => 'ר',
@@ -109,23 +100,6 @@ class JewishCalendar extends Calendar implements CalendarInterface{
);
/**
- * Some numerals take a different form when they appear at the end of a number.
- *
- * @var string[]
- */
- private static $HEBREW_NUMERALS_FINAL = array(
- 90 => 'צ',
- 80 => 'פ',
- 70 => 'ע',
- 60 => 'ס',
- 50 => 'נ',
- 40 => 'מ',
- 30 => 'ל',
- 20 => 'כ',
- 10 => 'י',
- );
-
- /**
* These months have fixed lengths. Others are variable.
*
* @var int[]
@@ -147,7 +121,7 @@ class JewishCalendar extends Calendar implements CalendarInterface{
-1 => array( // Deficient years
1 => 0, 30, 59, 88, 117, 147, 147, 176, 206, 235, 265, 294, 324
),
- 0 => array( // Regular years
+ 0 => array( // Regular years
1 => 0, 30, 59, 89, 118, 148, 148, 177, 207, 236, 266, 295, 325
),
1 => array( // Complete years
@@ -158,7 +132,7 @@ class JewishCalendar extends Calendar implements CalendarInterface{
-1 => array( // Deficient years
1 => 0, 30, 59, 88, 117, 147, 177, 206, 236, 265, 295, 324, 354
),
- 0 => array( // Regular years
+ 0 => array( // Regular years
1 => 0, 30, 59, 89, 118, 148, 178, 207, 237, 266, 296, 325, 355
),
1 => array( // Complete years
@@ -178,7 +152,8 @@ class JewishCalendar extends Calendar implements CalendarInterface{
/**
* Determine whether a year is a leap year.
*
- * @param int $year
+ * @param int $year
+ *
* @return bool
*/
public function leapYear($year) {
@@ -441,24 +416,39 @@ class JewishCalendar extends Calendar implements CalendarInterface{
}
/**
+ * Add geresh (׳) and gershayim (״) punctuation to numeric values.
+ *
+ * Gereshayim is a contraction of “geresh” and “gershayim”.
+ *
+ * @param string $number
+ *
+ * @return string
+ */
+ protected function addGereshayim($hebrew) {
+ switch (mb_strlen($hebrew, 'UTF-8')) {
+ case 0:
+ // Zero, e.g. the zeros from the year 5,000
+ return $hebrew;
+ case 1:
+ // Single digit - append a geresh
+ return $hebrew . self::GERESH;
+ default:
+ // Multiple digits - insert a gershayim
+ return mb_substr($hebrew, 0, mb_strlen($hebrew, 'UTF-8') - 1, 'UTF-8') . self::GERSHAYIM . mb_substr($hebrew, -1, 1, 'UTF-8');
+ }
+ }
+
+ /**
* Convert a number into Hebrew numerals.
- *
- * @param int $number
- * @param bool $alafim_garesh
- * @param bool $alafim
- * @param bool $gereshayim
+ *
+ * @param int $number
+ * @param bool $gereshayim Add punctuation to numeric values
*
* @return string
*/
- protected function numToHebrew($number, $alafim_garesh, $alafim, $gereshayim) {
+ protected function numberToHebrewNumerals($number, $gereshayim) {
$hebrew = '';
while ($number > 0) {
- foreach (self::$HEBREW_NUMERALS_FINAL as $n => $h) {
- if ($number == $n) {
- $hebrew .= $h;
- break 2;
- }
- }
foreach (self::$HEBREW_NUMERALS as $n => $h) {
if ($number >= $n) {
$hebrew .= $h;
@@ -467,7 +457,38 @@ class JewishCalendar extends Calendar implements CalendarInterface{
}
}
}
- return $hebrew;
+
+ // Hebrew numerals are letters. Add punctuation to prevent confusion with actual words.
+ if ($gereshayim) {
+ return $this->addGereshayim($hebrew);
+ } else {
+ return $hebrew;
+ }
+ }
+
+ /**
+ * 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
+ *
+ * @return string
+ */
+ protected function yearToHebrewNumerals($year, $alafim_geresh, $alafim, $gereshayim) {
+ if ($year < 1000) {
+ return $this->numberToHebrewNumerals($year, $gereshayim);
+ } else {
+ $thousands = $this->numberToHebrewNumerals((int)($year / 1000), false);
+ if ($alafim_geresh) {
+ $thousands .= self::GERESH;
+ }
+ if ($alafim) {
+ $thousands .= ' ' . self::ALAFIM . ' ';
+ }
+ return $thousands . $this->numberToHebrewNumerals($year % 1000, $gereshayim);
+ }
}
/**
@@ -484,8 +505,8 @@ class JewishCalendar extends Calendar implements CalendarInterface{
list($year, $month, $day) = $this->jdToYmd($jd);
return
- $this->numToHebrew($day, $alafim_garesh, $alafim, $gereshayim) . ' ' .
+ $this->numberToHebrewNumerals($day, $gereshayim) . ' ' .
$this->hebrewMonthName($year, $month) . ' ' .
- $this->numToHebrew($year, $alafim_garesh, $alafim, $gereshayim);
+ $this->yearToHebrewNumerals($year, $alafim_garesh, $alafim, $gereshayim);
}
}
diff --git a/library/fisharebest/ext-calendar/src/Shim.php b/library/fisharebest/ext-calendar/src/Shim.php
index ee7ce55bbb..fc6e468b15 100644
--- a/library/fisharebest/ext-calendar/src/Shim.php
+++ b/library/fisharebest/ext-calendar/src/Shim.php
@@ -220,18 +220,17 @@ class Shim {
*
* @return int
*/
- public static function easterDate($year=null) {
- if ($year === null) {
- $year = date('Y');
- } elseif ($year < 1970 || $year > 2037) {
+ public static function easterDate($year) {
+ if ($year < 1970 || $year > 2037) {
return trigger_error('This function is only valid for years between 1970 and 2037 inclusive', E_USER_WARNING);
}
+
$gregorian = new GregorianCalendar;
$days = $gregorian->easterDays($year);
- // Calculate time-zone offset
- $date_time = new \DateTime('now', new \DateTimeZone(date_default_timezone_get()));
- $offset_seconds = $date_time->format('Z');
+ // Calculate time-zone offset
+ $date_time = new \DateTime('now', new \DateTimeZone(date_default_timezone_get()));
+ $offset_seconds = $date_time->format('Z');
if ($days < 11) {
return jdtounix($gregorian->ymdToJd($year, 3, $days + 21)) - $offset_seconds;
@@ -439,15 +438,18 @@ class Shim {
* @link https://php.net/JdtoJewish
*
* @param int $juliandaycount A Julian Day number
- * @param bool $hebrew If set, the date is returned in Hebrew text
- * @param int $fl If set, then add alafim and gereshayim to the text
+ * @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
*
* @return string A string of the form "month/day/year"
*/
- public static function jdToJewish($juliandaycount, $hebrew = false, $fl = 0) {
+ public static function jdToJewish($juliandaycount, $hebrew, $fl) {
$jewish = new JewishCalendar;
if ($hebrew) {
+ if ($juliandaycount < 347998 || $juliandaycount > 4000075) {
+ return trigger_error('Year out of range (0-9999).', E_USER_WARNING);
+ }
$hebrew = $jewish->jdToHebrew($juliandaycount, $fl & CAL_JEWISH_ADD_ALAFIM_GERESH, $fl & CAL_JEWISH_ADD_ALAFIM, $fl & CAL_JEWISH_ADD_GERESHAYIM);
// Our code generates Hebrew punctuation. PHP uses ASCII punctuation.
$hebrew = strtr($hebrew, array(JewishCalendar::GERESH => "'", JewishCalendar::GERSHAYIM => '"'));