morilog / jalali

This Package helps developers to easily work with Jalali (Shamsi or Iranian) dates in php appliations, based on Jalali (Shamsi) DateTime class.
MIT License
860 stars 110 forks source link

wrong calculate of some date #41

Closed sherafatian closed 6 years ago

sherafatian commented 6 years ago

this package convert 1397/02/30 to 2018-05-20 that it's correct but convert 2018-05-20 to 1397/03/02 that means wrong. See my functions that do this:

function hijri2miladi($hijriDate) {
   $parseDate = date_parse($hijriDate);

   $miladi=jDateTime::toGregorian($parseDate['year'],$parseDate['month'],$parseDate['day']);

   $myDate = new DateTime();
   $myDate = $myDate->setDate($miladi[0], $miladi[1], $miladi[2])->format('Y-m-d');

   return $myDate;
}

And

function miladi2hijri($miladiDate) {
   $parseDate = date_parse($miladiDate);

   $shamsi = jDateTime::toJalali($parseDate['year'], $parseDate['month'], $parseDate['day']);
   $myDate = new DateTime();
   $myDate = $myDate->setDate($shamsi[0], $shamsi[1], $shamsi[2])->format('Y/m/d');

   return $myDate;
}
morilog commented 6 years ago

Your functions are wrong. You passed shamsi parsed arguments to DateTime constrcutor

>>> \Morilog\Jalali\jDateTime::toJalali(2018, 5, 20);
=> [
     1397,
     2,
     30,
   ]
>>> \Morilog\Jalali\jDateTime::toGregorian(1397, 2, 30);
=> [
     2018,
     5,
     20,
   ]