Skip to content

Commit

Permalink
Fix issue #28
Browse files Browse the repository at this point in the history
Fixed problem of one day diffrent when last year is leap year
  • Loading branch information
shahrokhniakan committed Dec 8, 2017
1 parent e5aa440 commit a9020f1
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 7 deletions.
8 changes: 7 additions & 1 deletion src/CalendarSettings/Hijri.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@
*/
'convert_from' => function ($date_time) {

$config = include 'Gregorian.php';

$year = $date_time->format('Y');

$month = $date_time->format('m');
Expand All @@ -114,6 +116,10 @@

$year = $result[2];

if (! $day || $config['leap_year']($year - 1) ) {
$day++;
}

$date_time->setDate($year, $month, $day);

return $date_time;
Expand Down Expand Up @@ -177,7 +183,7 @@
*\_________________________________________________________/
*/
'days_of_week' => array (

'al-Aḥad',
'al-Ithnayn',
'ath-Thulatha\'',
Expand Down
15 changes: 9 additions & 6 deletions src/CalendarSettings/Jalali.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,24 +161,27 @@
$gregorian_month -= $value;
}

$gregorian_day = $gregorian_month;
$gregorian_day = $gregorian_month;

$gregorian_month = $month;
$gregorian_month = $month;

if ( ( ( $gregorian_year % 4 ) == 0 ) && ( ( ( $gregorian_year % 100 ) != 0 ) || ( ( $gregorian_year % 400 ) == 0 ) ) ) {
if ( ( ( $gregorian_year % 4 ) == 0 ) && ( ( ( $gregorian_year % 100 ) != 0 ) || ( ( $gregorian_year % 400 ) == 0 ) ) ) {

if ( $gregorian_month < 3 || ( $gregorian_month == 3 && $gregorian_day < 22 ) ) {

$gregorian_day++;

}

}
}

$date_time->setDate($gregorian_year, $gregorian_month, $gregorian_day);
if (! $gregorian_day || $config['leap_year']($gregorian_year - 1) ) {
$gregorian_day++;
}

$date_time->setDate($gregorian_year, $gregorian_month, $gregorian_day);

return $date_time;
return $date_time;

},

Expand Down
8 changes: 8 additions & 0 deletions tests/ConvertTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ public function testJalaliToGregorian()

$this->assertEquals('2016-01-25 00:00:00', $date);

$date = Datium::create(1396, 9, 11)->from('jalali')->get();

$this->assertEquals('2017-12-02 00:00:00', $date);

}

public function testHijriToGregorian()
Expand All @@ -45,6 +49,10 @@ public function testHijriToGregorian()

$this->assertEquals('2016-06-13 00:00:00', $date);

$date = Datium::create(1439, 03, 12)->from('hijri')->get();

$this->assertEquals('2017-12-02 00:00:00', $date);

}

public function testJalaliToHijri()
Expand Down

0 comments on commit a9020f1

Please sign in to comment.