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

Add modify function #16

Closed mdaliyan closed 7 years ago

mdaliyan commented 7 years ago

This PR is created to add Jalali-base modify function to jDate

Not all modifications are available but it is usable and fully tested this far. These are some examples of features that are added to jDate:

$jDate = jDate::create() // Now
$jDate = $jDate->modify('1394-03-10 15:30:10'); // 1394-03-10 15:30:10
$jDate = $jDate->modify('+1 year');  //1395-03-10 15:30:10
$jDate = $jDate->modify('+6 month');  //1395-09-10 15:30:10
$jDate = $jDate->modify('+1 day');  //1395-09-11 15:30:10
$jDate = $jDate->modify('+8 weekdays')  //1395-09-21 15:30:10
$jDate = $jDate->modify('next year'); //1396-09-21 15:30:10

$jDate = $jDate->modify('first day of next month');  //1396-10-01 15:30:10
$jDate = $jDate->modify('last day of esfand 1395');  //1395-12-30 15:30:10
mdaliyan commented 7 years ago

Surely, this needs refactoring, but it works so far.

I'll add missing modification options later.

morilog commented 7 years ago

Thanks from PR, But your commits changes jDate functionality. If anyone uses jdate() or jDate::forge() then can't to use modify method. jDate class is just for displaying gregorian datetime in jalai format and not about parsing jalali data & time. Please create another class for parsing jalai date and make a PR on develop branch.

mdaliyan commented 7 years ago

I'm afraid, it's not true. reforge and forge functions still work with gregorian dates, and modify function did't exist in jDate before this. so nothing breaking will accure. All tests are green. besides, the person who uses modify, more likely uses format along side. why should we separate them? Likewise, both of them exist beside each other in datetime class.

morilog commented 7 years ago

A class with multiple functionality? some time with gregorian and some times with jalali?

morilog commented 7 years ago

The right solution is a jalali implementation of DateTime or Carbon classes.

mdaliyan commented 7 years ago

A class with multiple functionality? some time with gregorian and some times with jalali?

Exactly.

The right solution is a jalali implementation of DateTime or Carbon classes.

I'm working on it. But I was planning to use morilog/jalali as backbone.

morilog commented 7 years ago

BTW multiple functionality for jDate is not acceptable