Skip to content

Commit a9020f1

Browse files
Fix issue #28
Fixed problem of one day diffrent when last year is leap year
1 parent e5aa440 commit a9020f1

3 files changed

Lines changed: 24 additions & 7 deletions

File tree

src/CalendarSettings/Hijri.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@
9797
*/
9898
'convert_from' => function ($date_time) {
9999

100+
$config = include 'Gregorian.php';
101+
100102
$year = $date_time->format('Y');
101103

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

115117
$year = $result[2];
116118

119+
if (! $day || $config['leap_year']($year - 1) ) {
120+
$day++;
121+
}
122+
117123
$date_time->setDate($year, $month, $day);
118124

119125
return $date_time;
@@ -177,7 +183,7 @@
177183
*\_________________________________________________________/
178184
*/
179185
'days_of_week' => array (
180-
186+
181187
'al-Aḥad',
182188
'al-Ithnayn',
183189
'ath-Thulatha\'',

src/CalendarSettings/Jalali.php

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -161,24 +161,27 @@
161161
$gregorian_month -= $value;
162162
}
163163

164-
$gregorian_day = $gregorian_month;
164+
$gregorian_day = $gregorian_month;
165165

166-
$gregorian_month = $month;
166+
$gregorian_month = $month;
167167

168-
if ( ( ( $gregorian_year % 4 ) == 0 ) && ( ( ( $gregorian_year % 100 ) != 0 ) || ( ( $gregorian_year % 400 ) == 0 ) ) ) {
168+
if ( ( ( $gregorian_year % 4 ) == 0 ) && ( ( ( $gregorian_year % 100 ) != 0 ) || ( ( $gregorian_year % 400 ) == 0 ) ) ) {
169169

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

172172
$gregorian_day++;
173173

174174
}
175175

176-
}
176+
}
177177

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

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

181-
return $date_time;
184+
return $date_time;
182185

183186
},
184187

tests/ConvertTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ public function testJalaliToGregorian()
3636

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

39+
$date = Datium::create(1396, 9, 11)->from('jalali')->get();
40+
41+
$this->assertEquals('2017-12-02 00:00:00', $date);
42+
3943
}
4044

4145
public function testHijriToGregorian()
@@ -45,6 +49,10 @@ public function testHijriToGregorian()
4549

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

52+
$date = Datium::create(1439, 03, 12)->from('hijri')->get();
53+
54+
$this->assertEquals('2017-12-02 00:00:00', $date);
55+
4856
}
4957

5058
public function testJalaliToHijri()

0 commit comments

Comments
 (0)