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
861 stars 110 forks source link

problem with leap years #11

Closed palvaneh closed 8 years ago

palvaneh commented 8 years ago

$date = jDate::forge('2012-10-12')->reforge('next year')->format('Y-m-d'); reforge function works on Gregorian date and ignores Jalali leap years.

Specially, I want to add 1 year to a SQL date column without losing leap year computation. (In my program SQL date columns are Gregorian, but users should work with Jalali date formats.)

thanks

morilog commented 8 years ago

There is no library such as DateTime or Carbon for working with Jalali time and i have to work with gregorian date . Every operations are work on a DateTime instance in jDate class and in the format method i convert it into jalali date.

palvaneh commented 8 years ago

my solution $mydate = Carbon::createFromFormat('Y-m-d', $sqlDate); $arr = jDateTime::toJalali($mydate->year, $mydate->month, $mydate->day); $arr = jDateTime::toGregorian(++$arr[0], $arr[1], $arr[2]); $newSqlDate = Carbon::createFromDate($arr[0], $arr[1], $arr[2])->toDateString();