\hijridatetime

Hijri Date custom extensions to the PHP DateTime class This handles the Hijri Calendar beside the Gregorian Calendar

This class override PHP DateTime Class to show the Hijri Calendar Date and also showing the Gregorian Calendar Translated to Arabic Language if language set to 'ar' the Hijri Calendar calculated depending of hijri\calendar Class which have two algorithms:

  • Hijri Tabular Algorithm.
  • Umm Al-Qura Algorithm.

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,)
);

Summary

Methods
Properties
Constants
__construct()
createFromHijri()
format()
__toString()
setDateHijri()
$defaultformat
$langcode
No constants found
No protected methods found
$hcal
$s_hcal
N/A
No private methods found
No private properties found
N/A

Properties

$defaultformat

$defaultformat : string

Type

string — the default datetime format

$langcode

$langcode : string

Type

string — language code can set to 'ar' to show Arabic Date

$hcal

$hcal : \hijri\Calendar

Type

\hijri\Calendar — Calendar Object used to produce the Hijri Calendar from the timestamp

$s_hcal

$s_hcal : \hijri\Calendar

Type

\hijri\Calendar — static Calendar Object used to the last used Calendar

Methods

__construct()

__construct(string  $time = 'now', \DateTimeZone  $timezone = null, string  $langcode = null, \hijri\Calendar  $hijriCalendar = null) 

Constructs a new instance of datetime, expanded to include an argument to inject the user context and modify the timezone to the users selected timezone if one is not set.

Parameters

string $time

String in a format accepted by strtotime() default is 'now'

\DateTimeZone $timezone

Time zone of the time default is ini timezone

string $langcode

set the language which can be any of supported languages in Calendar object if not set the default is 'ar'

\hijri\Calendar $hijriCalendar

Calendar object which used for calendar converting, if not set the class will create new Calendar object with default settings

Examples

Create new DateTime
** File not found : 'examples/monthCalendar.php' **

createFromHijri()

createFromHijri(integer  $year, integer  $month, integer  $day, \DateTimeZone  $timezone = null, string  $langcode = null, \hijri\Calendar  $hijriCalendar = null) : self

Create DateTime object from hijri date

Parameters

integer $year

the hijri year

integer $month

the hijri month

integer $day

the hijri day

\DateTimeZone $timezone

Optional the time zone object

string $langcode

Optional the langcode

\hijri\Calendar $hijriCalendar

Optional the Calendar object

Returns

self —

datetime object from the given hijri date

format()

format(string  $format = null, boolean  $force_hijri = FALSE) : string

Formats the current date time into the specified format, this method overrides Datetime original method, if format characters are with "_" underscore prefix it will return hijri equivalent, if langcode set to 'ar' it will return Arabic translated date for Hijri or Gregorian Calendars

Parameters

string $format

Optional format to use for output The following characters are recognized to output Hijri Calendar in the format parameter string

format characterDescriptionExample Output
_jDay of the hijri month without leading zeros 1 to 301-30
_dDay of the hijri month with leading zeros 01 to 3001-30
_SEnglish suffix for numbers (new in 2.3.0)st, nd ,th
_zThe day of the year (starting from 0)0-354
_FA full textual representation of a month, such as Muharram or SafarMuharram-Dhul Hijjah
_MA short textual representation of a month, three letters(in Arabic same as _F)Muh-Hij
_mNumeric representation of a month, with leading zeros01-12
_nNumeric representation of a month, without leading zeros1-12
_LWhether it's a leap year1 if it is a leap year, 0 otherwise
_YA full numeric representation of a year, 4 digits1380 or 1436
_yA two digit representation of a year80 or 36
These format character will overridden if langcode set to 'ar'
l, DA full textual representation of the day of the week in Arabic?????-??????
FA full textual representation of a month, Syrian Name????? ??????? ????
MA full textual representation of a month, English translated?????? ??????
aLowercase Ante meridiem and Post meridiem in Arabic? ? ?
AFull Ante meridiem and Post meridiem in Arabic????? ? ????
    if it is not given it defaults to $hijri_settings['defaultformat'], if it is not set it defaults to '_j _M _Y??'
boolean $force_hijri

force the returned date to be Hijri if the $format does not contain underscore (_)

Returns

string —

Formatted date time

__toString()

__toString() : string

Magic method to convert DateTime object to string

Returns

string —

Formatted date time, according to the default settings in $hijri_settings variable

setDateHijri()

setDateHijri(integer  $year, integer  $month, integer  $day) : void

Resets the current date of the DateTime object to a different hijri date

Parameters

integer $year

the hijri year

integer $month

the hijri month

integer $day

the hijri day