PHP Class Morilog\Jalali\jDateTime

Requires PHP >= 5.2 PHP's default 'date' function does not support years higher than 2038. Intorduced in PHP5, DateTime class supports higher years and also invalid date entries. Also, Persian users are using classic 'jdate' function for years now and beside the fact that it's amazing and also helped me to write this one, it's really out of date, and can't be used in modern real world web applications as it is completely written in functions. Copyright (C) 2012 Sallar Kaboli (http://sallar.me) Part of Phoenix Framework (p5x.org) by Phoenix Alternatvie Original Jalali to Gregorian (and vice versa) convertor: Copyright (C) 2000 Roozbeh Pournader and Mohammad Toossi List of supported timezones can be found here: http://www.php.net/manual/en/timezones.php PHP version 5 LICENSE: This source file is subject to version 3.01 of the PHP license that is available through the world-wide-web at the following URI: http://www.php.net/license/3_01.txt. If you did not receive a copy of the PHP License and are unable to obtain it through the web, please send a note to [email protected] so we can mail you a copy immediately.
See also: DateTime
Author: Sallar Kaboli ([email protected])
Author: Omid Pilevar ([email protected])
Datei anzeigen Open project: morilog/jalali Class Usage Examples

Public Methods

Method Description
checkDate ( $year, $month, $day, boolean $isJalali = true ) : boolean Checks whether a date is valid or not.
convertNumbers ( string $string ) : string Convert Latin numbers to persian numbers
createCarbonFromFormat ( $format, $str, null $timezone = null ) : Carbon\Carbon
createDateTime ( $timestamp = null, null $timezone = null ) : DateTime | static
createDatetimeFromFormat ( $format, $str, null $timezone = null ) : DateTime
createTimeZone ( null $timezone = null ) : DateTimeZone | null
d2g ( $jdn ) : array
d2j ( integer $jdn ) : array Converts the Julian Day number to a date in the Jalaali calendar.
date ( $format, boolean $stamp = false, boolean $timezone = null ) : mixed
div ( $a, $b ) : float
g2d ( integer $gy, integer $gm, integer $gd ) : integer Calculates the Julian Day number from Gregorian or Julian calendar dates. This integer number corresponds to the noon of the date (i.e. 12 hours of Universal Time).
isLeapJalaliYear ( $jy ) : boolean Is this a leap year or not?
isValidateJalaliDate ( integer $jy, integer $jm, integer $jd ) : boolean Checks whether a Jalaali date is valid or not.
j2d ( integer $jy, integer $jm, integer $jd ) : integer Converts a date of the Jalaali calendar to the Julian Day number.
jalaliCal ( integer $jy ) : array This function determines if the Jalaali (Persian) year is leap (366-day long) or is the common year (365 days), and finds the day in March (Gregorian calendar) of the first day of the Jalaali year (jy).
jalaliMonthLength ( integer $jy, integer $jm ) : integer Number of days in a given month in a Jalaali year.
mod ( $a, $b ) : mixed
parseFromFormat ( $format, $date ) : array
strftime ( $format, boolean $stamp = false, null $timezone = null ) : mixed
toGregorian ( integer $jy, integer $jm, integer $jd ) : array Converts a Jalali date to Gregorian.
toJalali ( $gy, $gm, $gd ) : array Converts a Gregorian date to Jalali.

Private Methods

Method Description
filterArray ( $needle, $haystack, $always = [] )
getDayNames ( $day, $shorten = false, $len = 1, $numeric = false )
getMonthNames ( $month, $shorten = false, $len = 3 )

Method Details

checkDate() public static method

Checks whether a date is valid or not.
public static checkDate ( $year, $month, $day, boolean $isJalali = true ) : boolean
$year
$month
$day
$isJalali boolean
return boolean

convertNumbers() public static method

Convert Latin numbers to persian numbers
public static convertNumbers ( string $string ) : string
$string string
return string

createCarbonFromFormat() public static method

public static createCarbonFromFormat ( $format, $str, null $timezone = null ) : Carbon\Carbon
$format
$str
$timezone null
return Carbon\Carbon

createDateTime() public static method

public static createDateTime ( $timestamp = null, null $timezone = null ) : DateTime | static
$timestamp
$timezone null
return DateTime | static

createDatetimeFromFormat() public static method

public static createDatetimeFromFormat ( $format, $str, null $timezone = null ) : DateTime
$format
$str
$timezone null
return DateTime

createTimeZone() public static method

public static createTimeZone ( null $timezone = null ) : DateTimeZone | null
$timezone null
return DateTimeZone | null

d2g() public static method

public static d2g ( $jdn ) : array
$jdn
return array

d2j() public static method

Converts the Julian Day number to a date in the Jalaali calendar.
public static d2j ( integer $jdn ) : array
$jdn integer Julian Day number
return array 0: Jalaali year (1 to 3100) 1: Jalaali month (1 to 12) 2: Jalaali day (1 to 29/31)

date() public static method

public static date ( $format, boolean $stamp = false, boolean $timezone = null ) : mixed
$format
$stamp boolean
$timezone boolean
return mixed

div() public static method

public static div ( $a, $b ) : float
$a
$b
return float

g2d() public static method

The procedure was tested to be good since 1 March, -100100 (of both calendars) up to a few million years into the future.
public static g2d ( integer $gy, integer $gm, integer $gd ) : integer
$gy integer Calendar year (years BC numbered 0, -1, -2, ...)
$gm integer Calendar month (1 to 12)
$gd integer Calendar day of the month (1 to 28/29/30/31)
return integer Julian Day number

isLeapJalaliYear() public static method

Is this a leap year or not?
public static isLeapJalaliYear ( $jy ) : boolean
$jy
return boolean

isValidateJalaliDate() public static method

Checks whether a Jalaali date is valid or not.
public static isValidateJalaliDate ( integer $jy, integer $jm, integer $jd ) : boolean
$jy integer
$jm integer
$jd integer
return boolean

j2d() public static method

Converts a date of the Jalaali calendar to the Julian Day number.
public static j2d ( integer $jy, integer $jm, integer $jd ) : integer
$jy integer Jalaali year (1 to 3100)
$jm integer Jalaali month (1 to 12)
$jd integer Jalaali day (1 to 29/31)
return integer Julian Day number

jalaliCal() public static method

This function determines if the Jalaali (Persian) year is leap (366-day long) or is the common year (365 days), and finds the day in March (Gregorian calendar) of the first day of the Jalaali year (jy).
public static jalaliCal ( integer $jy ) : array
$jy integer Jalaali calendar year (-61 to 3177)
return array leap: number of years since the last leap year (0 to 4) gy: Gregorian year of the beginning of Jalaali year march: the March day of Farvardin the 1st (1st day of jy)

jalaliMonthLength() public static method

Number of days in a given month in a Jalaali year.
public static jalaliMonthLength ( integer $jy, integer $jm ) : integer
$jy integer
$jm integer
return integer

mod() public static method

public static mod ( $a, $b ) : mixed
$a
$b
return mixed

parseFromFormat() public static method

public static parseFromFormat ( $format, $date ) : array
$format
$date
return array

strftime() public static method

public static strftime ( $format, boolean $stamp = false, null $timezone = null ) : mixed
$format
$stamp boolean
$timezone null
return mixed

toGregorian() public static method

Converts a Jalali date to Gregorian.
public static toGregorian ( integer $jy, integer $jm, integer $jd ) : array
$jy integer
$jm integer
$jd integer
return array 0: Year 1: Month 2: Day

toJalali() public static method

Converts a Gregorian date to Jalali.
public static toJalali ( $gy, $gm, $gd ) : array
$gy
$gm
$gd
return array 0: Year 1: Month 2: Day