Php Global Calendar Convert - convert all calendar type to each other so simple.
Global calendar is simple code to convert all calendars like Solar Hijri(Shamsi,Jalali,... ), Gregorian and ... to each other. gCal try to find the count of days between source calendar and Millenium(2000-01-01), then calculate the the destination calendar according to this gap.
For example, in order to convert 1392/05/28 from Solar Hijri to Gregorian we do this stuff
- Find equivalent to millenium(2000-01-01) in Solar Hijri.(1378-10-11 is equal to 2000-01-01)
- Calculate count of days between 1392/05/28 and 1378-10-11 (Should be positive or negative). We do this in
gapUntilMillenium
method and result should be 4979. - Calculate destination calendar by adding 4979 to equivalent millenium date(In Gregorian 2000-01-01 is equal to millenium(2000-01-01)).We do this in
revertFromMillenium
method and result should be 2013-08-19.
There is a Sample Class in calendar
folder. All thing you need to create your new
calendar type is to create a class like Sample.php
and extend it from BaseCalendar.php
.
BaseCalendar
is an abstract class and you should implement to method for it to work:
- function gapUntilMillenium($year, $month, $day)
- function revertFromMillenium($daysUntilMillenium)
After implementing this two method, convert
method in gCal.php
will convert date
by calling your implemented methods via reflection.
Just call the static convert
method from gCal.php
function convert(
$sourceFormat, $sourceDate, $sourceCalendarName,
$destinationFormat, $destinationCalendarName
)
$solarHijri = '1392/05/24 11:01:02';
//convert to Gregorian
gCal::convert(
'Y/m/d H:i:s', $solarHijri, SolarHijri::calendarName(),
'Y-m-d H:i:s', Gregorian::calendarName()
);
- PHP 5.3+
Request for pull or fork and add your calendar. Thanks