. */ namespace Fisharebest\Webtrees\Date; use Fisharebest\ExtCalendar\ArabicCalendar; use Fisharebest\Webtrees\I18N; /** * Definitions for the Hijri calendar. * * Note that these are "theoretical" dates. * "True" dates are based on local lunar observations, and can be a +/- one day. */ class HijriDate extends CalendarDate { /** @var int[] Convert GEDCOM month names to month numbers */ public static $MONTH_ABBREV = [ '' => 0, 'MUHAR' => 1, 'SAFAR' => 2, 'RABIA' => 3, 'RABIT' => 4, 'JUMAA' => 5, 'JUMAT' => 6, 'RAJAB' => 7, 'SHAAB' => 8, 'RAMAD' => 9, 'SHAWW' => 10, 'DHUAQ' => 11, 'DHUAH' => 12, ]; /** * Create a date from either: * a Julian day number * day/month/year strings from a GEDCOM date * another CalendarDate object * * @param array|int|CalendarDate $date */ public function __construct($date) { $this->calendar = new ArabicCalendar(); parent::__construct($date); } /** * Full month name in nominative case. * * @param int $month_number * @param bool $leap_year Some calendars use leap months * * @return string */ public static function monthNameNominativeCase(int $month_number, bool $leap_year): string { static $translated_month_names; if ($translated_month_names === null) { $translated_month_names = [ 0 => '', /* I18N: http://en.wikipedia.org/wiki/Muharram */ 1 => I18N::translateContext('NOMINATIVE', 'Muharram'), /* I18N: http://en.wikipedia.org/wiki/Safar */ 2 => I18N::translateContext('NOMINATIVE', 'Safar'), /* I18N: http://en.wikipedia.org/wiki/Rabi%27_al-awwal */ 3 => I18N::translateContext('NOMINATIVE', 'Rabi’ al-awwal'), /* I18N: http://en.wikipedia.org/wiki/Rabi%27_al-thani */ 4 => I18N::translateContext('NOMINATIVE', 'Rabi’ al-thani'), /* I18N: http://en.wikipedia.org/wiki/Jumada_al-awwal */ 5 => I18N::translateContext('NOMINATIVE', 'Jumada al-awwal'), /* I18N: http://en.wikipedia.org/wiki/Jumada_al-thani */ 6 => I18N::translateContext('NOMINATIVE', 'Jumada al-thani'), /* I18N: http://en.wikipedia.org/wiki/Rajab */ 7 => I18N::translateContext('NOMINATIVE', 'Rajab'), /* I18N: http://en.wikipedia.org/wiki/Sha%27aban */ 8 => I18N::translateContext('NOMINATIVE', 'Sha’aban'), /* I18N: http://en.wikipedia.org/wiki/Ramadan_%28calendar_month%29 */ 9 => I18N::translateContext('NOMINATIVE', 'Ramadan'), /* I18N: http://en.wikipedia.org/wiki/Shawwal */ 10 => I18N::translateContext('NOMINATIVE', 'Shawwal'), /* I18N: http://en.wikipedia.org/wiki/Dhu_al-Qi%27dah */ 11 => I18N::translateContext('NOMINATIVE', 'Dhu al-Qi’dah'), /* I18N: http://en.wikipedia.org/wiki/Dhu_al-Hijjah */ 12 => I18N::translateContext('NOMINATIVE', 'Dhu al-Hijjah'), ]; } return $translated_month_names[$month_number]; } /** * Full month name in genitive case. * * @param int $month_number * @param bool $leap_year Some calendars use leap months * * @return string */ protected function monthNameGenitiveCase(int $month_number, bool $leap_year): string { static $translated_month_names; if ($translated_month_names === null) { $translated_month_names = [ 0 => '', /* I18N: http://en.wikipedia.org/wiki/Muharram */ 1 => I18N::translateContext('GENITIVE', 'Muharram'), /* I18N: http://en.wikipedia.org/wiki/Safar */ 2 => I18N::translateContext('GENITIVE', 'Safar'), /* I18N: http://en.wikipedia.org/wiki/Rabi%27_al-awwal */ 3 => I18N::translateContext('GENITIVE', 'Rabi’ al-awwal'), /* I18N: http://en.wikipedia.org/wiki/Rabi%27_al-thani */ 4 => I18N::translateContext('GENITIVE', 'Rabi’ al-thani'), /* I18N: http://en.wikipedia.org/wiki/Jumada_al-awwal */ 5 => I18N::translateContext('GENITIVE', 'Jumada al-awwal'), /* I18N: http://en.wikipedia.org/wiki/Jumada_al-thani */ 6 => I18N::translateContext('GENITIVE', 'Jumada al-thani'), /* I18N: http://en.wikipedia.org/wiki/Rajab */ 7 => I18N::translateContext('GENITIVE', 'Rajab'), /* I18N: http://en.wikipedia.org/wiki/Sha%27aban */ 8 => I18N::translateContext('GENITIVE', 'Sha’aban'), /* I18N: http://en.wikipedia.org/wiki/Ramadan_%28calendar_month%29 */ 9 => I18N::translateContext('GENITIVE', 'Ramadan'), /* I18N: http://en.wikipedia.org/wiki/Shawwal */ 10 => I18N::translateContext('GENITIVE', 'Shawwal'), /* I18N: http://en.wikipedia.org/wiki/Dhu_al-Qi%27dah */ 11 => I18N::translateContext('GENITIVE', 'Dhu al-Qi’dah'), /* I18N: http://en.wikipedia.org/wiki/Dhu_al-Hijjah */ 12 => I18N::translateContext('GENITIVE', 'Dhu al-Hijjah'), ]; } return $translated_month_names[$month_number]; } /** * Full month name in locative case. * * @param int $month_number * @param bool $leap_year Some calendars use leap months * * @return string */ protected function monthNameLocativeCase(int $month_number, bool $leap_year): string { static $translated_month_names; if ($translated_month_names === null) { $translated_month_names = [ 0 => '', /* I18N: http://en.wikipedia.org/wiki/Muharram */ 1 => I18N::translateContext('LOCATIVE', 'Muharram'), /* I18N: http://en.wikipedia.org/wiki/Safar */ 2 => I18N::translateContext('LOCATIVE', 'Safar'), /* I18N: http://en.wikipedia.org/wiki/Rabi%27_al-awwal */ 3 => I18N::translateContext('LOCATIVE', 'Rabi’ al-awwal'), /* I18N: http://en.wikipedia.org/wiki/Rabi%27_al-thani */ 4 => I18N::translateContext('LOCATIVE', 'Rabi’ al-thani'), /* I18N: http://en.wikipedia.org/wiki/Jumada_al-awwal */ 5 => I18N::translateContext('LOCATIVE', 'Jumada al-awwal'), /* I18N: http://en.wikipedia.org/wiki/Jumada_al-thani */ 6 => I18N::translateContext('LOCATIVE', 'Jumada al-thani'), /* I18N: http://en.wikipedia.org/wiki/Rajab */ 7 => I18N::translateContext('LOCATIVE', 'Rajab'), /* I18N: http://en.wikipedia.org/wiki/Sha%27aban */ 8 => I18N::translateContext('LOCATIVE', 'Sha’aban'), /* I18N: http://en.wikipedia.org/wiki/Ramadan_%28calendar_month%29 */ 9 => I18N::translateContext('LOCATIVE', 'Ramadan'), /* I18N: http://en.wikipedia.org/wiki/Shawwal */ 10 => I18N::translateContext('LOCATIVE', 'Shawwal'), /* I18N: http://en.wikipedia.org/wiki/Dhu_al-Qi%27dah */ 11 => I18N::translateContext('LOCATIVE', 'Dhu al-Qi’dah'), /* I18N: http://en.wikipedia.org/wiki/Dhu_al-Hijjah */ 12 => I18N::translateContext('LOCATIVE', 'Dhu al-Hijjah'), ]; } return $translated_month_names[$month_number]; } /** * Full month name in instrumental case. * * @param int $month_number * @param bool $leap_year Some calendars use leap months * * @return string */ protected function monthNameInstrumentalCase(int $month_number, bool $leap_year): string { static $translated_month_names; if ($translated_month_names === null) { $translated_month_names = [ 0 => '', /* I18N: http://en.wikipedia.org/wiki/Muharram */ 1 => I18N::translateContext('INSTRUMENTAL', 'Muharram'), /* I18N: http://en.wikipedia.org/wiki/Safar */ 2 => I18N::translateContext('INSTRUMENTAL', 'Safar'), /* I18N: http://en.wikipedia.org/wiki/Rabi%27_al-awwal */ 3 => I18N::translateContext('INSTRUMENTAL', 'Rabi’ al-awwal'), /* I18N: http://en.wikipedia.org/wiki/Rabi%27_al-thani */ 4 => I18N::translateContext('INSTRUMENTAL', 'Rabi’ al-thani'), /* I18N: http://en.wikipedia.org/wiki/Jumada_al-awwal */ 5 => I18N::translateContext('INSTRUMENTAL', 'Jumada al-awwal'), /* I18N: http://en.wikipedia.org/wiki/Jumada_al-thani */ 6 => I18N::translateContext('INSTRUMENTAL', 'Jumada al-thani'), /* I18N: http://en.wikipedia.org/wiki/Rajab */ 7 => I18N::translateContext('INSTRUMENTAL', 'Rajab'), /* I18N: http://en.wikipedia.org/wiki/Sha%27aban */ 8 => I18N::translateContext('INSTRUMENTAL', 'Sha’aban'), /* I18N: http://en.wikipedia.org/wiki/Ramadan_%28calendar_month%29 */ 9 => I18N::translateContext('INSTRUMENTAL', 'Ramadan'), /* I18N: http://en.wikipedia.org/wiki/Shawwal */ 10 => I18N::translateContext('INSTRUMENTAL', 'Shawwal'), /* I18N: http://en.wikipedia.org/wiki/Dhu_al-Qi%27dah */ 11 => I18N::translateContext('INSTRUMENTAL', 'Dhu al-Qi’dah'), /* I18N: http://en.wikipedia.org/wiki/Dhu_al-Hijjah */ 12 => I18N::translateContext('INSTRUMENTAL', 'Dhu al-Hijjah'), ]; } return $translated_month_names[$month_number]; } /** * Abbreviated month name * * @param int $month_number * @param bool $leap_year Some calendars use leap months * * @return string */ protected function monthNameAbbreviated(int $month_number, bool $leap_year): string { return self::monthNameNominativeCase($month_number, $leap_year); } }