HijriDateLib

Calendar
in package

Hijri Calendar Class is group of functions that gets the Hijri Calendar and converts it to other calendars

This class contains functions work similar to calendar functions in PHP but it is work with Hijri Calendar. The Class has two algorithms to calculate the Hijri Date

Hijri Tabular Algorithm:
This algorithm was used by past to simplify the Hijri Calendar calculation, The result of this algorithm identical to Hijri Calendar in Microsoft programs and "The Calendar of Centuries-تقويم القرون" book of "Saleh Alojiry صالح العجيري".
Umm Al-Qura Algorithm(Recommended).
This is the official calendar of Saudi Arabia Kingdom based on astronomical calculation which published in the site http://www.ummulqura.org.sa, the range of this algorithm from year 1318 to 1500, the start of hijri months of this algorithm can be adjusted by using CalendarAdjustment Class see file adjuster.php in folder example as sample
to set the default setting of this class use $hijri_settings variable which is an array with this sample structure:
$hijri_settings=array(
'langcode'=>'ar',
'defaultformat'=>'_j _M _Yهـ',
'umalqura'=> TRUE,
'adj_data'=> array(1426 => 57250, 1429 => 57339,),
'grdate_format' => 'j M Y',
);
Tags
copyright

2015-2022 Saeed Hubaishan

license

LGPL

license

GPL-2

author

Saeed Hubaishan

version
2.3.2
category

datetime, calendar

link
http://salafitech.net
since
2.3.0

$hijri_sittings['adj_data'] must be an array or string contains a serialiezed array

Table of Contents

mjd_factor  = 2400000
int factor for convert julianday to modified julianday
umendjd  = 2479960
the Um Al-Qura Calendar end Julian day
umendyear  = 1500
the Um Al-Qura Calendar end year
umstartjd  = 2415140
the Um Al-Qura Calendar start Julian day
umstartyear  = 1318
the Um Al-Qura Calendar start year
$supported_languages  : array<string|int, mixed>
$umalqura  : bool
$adj_data  : array<string|int, mixed>
$umdata  : array<string|int, int>
__construct()  : Calendar
Create new hijri\Calendar object according to given settings
checkHijriDate()  : bool
Checks the given Hijri date, returns true is the date is correct
days_in_month()  : int
Returns count of days in month (29 or 30)
english_suffix()  : string
returns english suffix for number
GregorianToHijri()  : array<string|int, mixed>
Return Hijri Date from Gregorian date
HijriToGregorian()  : array<string|int, mixed>
Return Gregorian Date from Hijri date
HijriToJD()  : int
Returns julianday from Hijri date
HijriToJulian()  : array<string|int, mixed>
Returns Julian Date from Hijri date
HijriToWestern()  : array<string|int, mixed>
Return Western Date from Hijri date
jd2hijri()  : void
Returns Hijri date from julianday
JDToHijri()  : string
Returns Hijri Date in Format month/day/year from julianday
JulianToHijri()  : array<string|int, mixed>
Returns Hijri Date from Julian date
leap_year()  : int
Return 1 if the given year is leap, 0 else
month_name()  : string
Returns the hijri month name in 20 languages
monthnames()  : array<string|int, mixed>
Returns array of the hijri month names in 20 languages
WesternToHijri()  : array<string|int, mixed>
Returns Hijri Date from Western date
get_umalquradata()  : array<string|int, mixed>|bool
Loads Um Al-Qura data and apply the adjustments

Constants

mjd_factor

int factor for convert julianday to modified julianday

public mixed mjd_factor = 2400000

umendjd

the Um Al-Qura Calendar end Julian day

public mixed umendjd = 2479960

umendyear

the Um Al-Qura Calendar end year

public mixed umendyear = 1500

umstartjd

the Um Al-Qura Calendar start Julian day

public mixed umstartjd = 2415140

umstartyear

the Um Al-Qura Calendar start year

public mixed umstartyear = 1318

Properties

$supported_languages

public static array<string|int, mixed> $supported_languages = array('ar', 'en', 'fa', 'ur', 'sq', 'az', 'bn', 'bs', 'zh', 'fr', 'de', 'hi', 'id', 'ckb', 'ms', 'ru', 'es', 'tr', 'pt', 'it')

Array of supported langcodes

Tags
static

$umalqura

public bool $umalqura = TRUE

TRUE to use Um Al-Qura algorithm, FALSE to use Hijri Tabular Algorithm

$adj_data

protected array<string|int, mixed> $adj_data

the Um AlQura adjustment data, keys are month indexes from umstartyear, values are modified Julian day

$umdata

protected array<string|int, int> $umdata

The Um Al-Qura Data

Methods

__construct()

Create new hijri\Calendar object according to given settings

public __construct([array<string|int, mixed> $settings = array() ]) : Calendar
Parameters
$settings : array<string|int, mixed> = array()

Optional array contains one or more settings of the hijri calendar object these settings are:

umalqura:bool
TRUE to use Um AlQura algorithm, FALSE to use Hijri Tabular algorithm
adj_data:string|array
string: contains Um Al-Qura adjustment data that got by function get_adjdata(TRUE) of CalendarAdjustment class or array contains Um Al-Qura adjustment data that got by function get_adjdata(FALSE)
if not set, the defaults from $hijri_settings global variable will be used.
Tags
global

array $hijri_settings global hijri calendar settings

Return values
Calendar

hijri\Calendar object with the specified settings.

checkHijriDate()

Checks the given Hijri date, returns true is the date is correct

public checkHijriDate(int $year, int $month, int $day) : bool
Parameters
$year : int

the Hijri year

$month : int

the Hijri month

$day : int

the Hijri day

Return values
bool

TRUE if the given date is correct, FALSE else

days_in_month()

Returns count of days in month (29 or 30)

public days_in_month(int $month, int $year[, bool $umalqura = null ]) : int
Parameters
$month : int

the Hijri month

$year : int

the Hijri year

$umalqura : bool = null

TRUE to use Um Al-Qura, FALSE to use Tabular, defaults from Calendar object

Return values
int

count of days in month 29 or 30

english_suffix()

returns english suffix for number

public static english_suffix(int $number) : string
Parameters
$number : int
Tags
since
2.3.0
Return values
string

GregorianToHijri()

Return Hijri Date from Gregorian date

public GregorianToHijri(int $year, int $month, int $day) : array<string|int, mixed>
Parameters
$year : int

the Gregorian year

$month : int

the Gregorian month

$day : int

the Gregorian day

Return values
array<string|int, mixed>

An array contains Hijri Date: 'y' key for year,'m' key for month,'d' key for day

HijriToGregorian()

Return Gregorian Date from Hijri date

public HijriToGregorian(int $year, int $month, int $day) : array<string|int, mixed>
Parameters
$year : int

the Hijri year

$month : int

the Hijri month

$day : int

the Hijri day

Return values
array<string|int, mixed>

An array contains Gregorian Date: 'y' key for year,'m' key for month,'d' key for day

HijriToJD()

Returns julianday from Hijri date

public HijriToJD(int $month, int $day, int $year) : int
Parameters
$month : int

the Hijri month

$day : int

the Hijri day

$year : int

the Hijri year

Return values
int

julianday

HijriToJulian()

Returns Julian Date from Hijri date

public HijriToJulian(int $year, int $month, int $day) : array<string|int, mixed>
Parameters
$year : int

the Hijri year

$month : int

the Hijri month

$day : int

the Hijri day

Return values
array<string|int, mixed>

An array contains Julian Date: 'y' key for year,'m' key for month,'d' key for day

HijriToWestern()

Return Western Date from Hijri date

public HijriToWestern(int $year, int $month, int $day) : array<string|int, mixed>

The Western date is Julian date before 1582 and Gregorian after

Parameters
$year : int

the Hijri year

$month : int

the Hijri month

$day : int

the Hijri day

Return values
array<string|int, mixed>

An array contains Western Date: 'y' key for year,'m' key for month,'d' key for day

jd2hijri()

Returns Hijri date from julianday

public jd2hijri(int $julianday, int &$hy, int &$hm, int &$hd, int &$hz) : void
Parameters
$julianday : int

the julianday

$hy : int

variable to store Hijri year

$hm : int

variable to store Hijri month

$hd : int

variable to store Hijri day in month

$hz : int

variable to store Hijri day in year (starting from 0)

Return values
void

JDToHijri()

Returns Hijri Date in Format month/day/year from julianday

public JDToHijri(int $julianday) : string
Parameters
$julianday : int

the julianday

Return values
string

Hijri date in format month/day/year

JulianToHijri()

Returns Hijri Date from Julian date

public JulianToHijri(int $year, int $month, int $day) : array<string|int, mixed>
Parameters
$year : int

the Julian year

$month : int

the Julian month

$day : int

the Julian day

Return values
array<string|int, mixed>

An array contains Hijri Date: 'y' key for year,'m' key for month,'d' key for day

leap_year()

Return 1 if the given year is leap, 0 else

public leap_year(int $year[, bool $umalqura = null ]) : int
Parameters
$year : int

the Hijri Year

$umalqura : bool = null

TRUE to use Um Al-Qura, FALSE to use Tabular, defaults from Calendar object

Return values
int

1 if the given year is leap(have 355 days), 0 else

month_name()

Returns the hijri month name in 20 languages

public month_name(string $month[, string $langcode = 'ar' ][, bool $short = FALSE ]) : string
Parameters
$month : string

the month number

$langcode : string = 'ar'

the language ISO code

$short : bool = FALSE

return short names of months for European languages

Tags
since
2.2.0

$short param added

Return values
string

Hijri month name

monthnames()

Returns array of the hijri month names in 20 languages

public monthnames([string $langcode = 'ar' ]) : array<string|int, mixed>
Parameters
$langcode : string = 'ar'

the language code

Return values
array<string|int, mixed>

Array of Hijri month names, keys are month number (start from 1), values are string of month name

WesternToHijri()

Returns Hijri Date from Western date

public WesternToHijri(int $year, int $month, int $day) : array<string|int, mixed>

The Western date is Julian date before 1582 and Gregorian after

Parameters
$year : int

the Western year

$month : int

the Western month

$day : int

the Western day

Return values
array<string|int, mixed>

An array contains Hijri Date: 'y' key for year,'m' key for month,'d' key for day

get_umalquradata()

Loads Um Al-Qura data and apply the adjustments

protected get_umalquradata([bool $with_adj = TRUE ][, bool $return_array = FALSE ]) : array<string|int, mixed>|bool
Parameters
$with_adj : bool = TRUE

TRUE (default) to apply adjustments, FALSE to not

$return_array : bool = FALSE

True to return umdata array, False to load umdata to $umdata variable

Return values
array<string|int, mixed>|bool

array contains Um Al-Qura data if $return_array =true, bool true else

Search results