Skip to content

Commit 01750cc

Browse files
committed
Merge pull request #7 from puraminy/master
Update jDateTime.php
2 parents b0b2cb0 + 50a90d3 commit 01750cc

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

src/Miladr/Jalali/jDateTime.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,34 @@ private static function div($a, $b)
466466
{
467467
return (int) ($a / $b);
468468
}
469+
/**
470+
* Converts Gregorian DateTime to Jalali and return it as string.
471+
* By Ahmad Pouramini
472+
*/
473+
public static function toJalaliStr($g_date, $curSep = '-', $newSep = '/')
474+
{
475+
$arr = explode($curSep, $g_date);
476+
if (count($arr) < 3 || intval($arr[2]) == 0) //invalid dates
477+
return "";
478+
else
479+
$j_date = jDateTime::toJalali($arr[0],$arr[1],$arr[2]);
480+
$j_date_rev = array($j_date[2],$j_date[1],$j_date[0]);
481+
return implode($newSep,$j_date_rev);
482+
}
483+
/**
484+
* Converts Jalai DateTime to Gregorian and return it as string.
485+
* By Ahmad Pouramini
486+
*/
487+
public static function toGregorianStr($j_date, $sep = '/')
488+
{
489+
$arr = explode($sep,$j_date);
490+
if (count($arr) < 3 || intval($arr[0]) == 0) // invalid date
491+
return "";
492+
else
493+
$g_date = jDateTime::toGregorian($arr[2],$arr[1],$arr[0]);
494+
return implode($sep,$g_date);
495+
}
496+
469497

470498
/**
471499
* Gregorian to Jalali Conversion

0 commit comments

Comments
 (0)