Skip to content

Commit

Permalink
Fixed: calculation of julian day first of year when not exists it yea…
Browse files Browse the repository at this point in the history
…r in list.
  • Loading branch information
ataiemajid63 committed May 6, 2022
1 parent 9a63697 commit 4d4583d
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions src/Calendars/ShiaCalendar.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ public function daysInMonth($year, $month)
1440 => [30, 29, 30, 30, 30, 29, 29, 30, 29, 30, 29, 29],
1441 => [29, 30, 29, 30, 30, 29, 30, 30, 29, 30, 29, 30],
1442 => [29, 29, 30, 29, 30, 29, 30, 30, 29, 30, 30, 29],
1443 => [29, 30, 30, 29, 29, 30, 29, 30, 29, 30, 30, 29]

1443 => [29, 30, 30, 29, 29, 30, 29, 30, 29, 30, 30, 29],
1444 => [30, 30, 29, 30, 29, 29, 30, 30, 29, 30, 29, 30],
];

if ($month < 1 || $month > 12) {
Expand All @@ -109,13 +109,26 @@ public function julianDayFirstOfYear($year)
1440 => 2458372.5,
1441 => 2458727.5,
1442 => 2459082.5,
1443 => 2459436.5
1443 => 2459436.5,
1444 => 2459790.5,
];

if (isset($julianDays[$year])) {
return $julianDays[$year];
}
return $this->dateToJulianDay($year, 1, 1, 0, 0, 0);

$availYears = array_keys($julianDays);
$minYear = min($availYears);
$maxYear = max($availYears);

if($year > $maxYear) {
$julianDay = $julianDays[$maxYear] + (($year - $maxYear) * Constants::DAYS_OF_SHIA_YEAR);
}
else { // $year < $minYear
$julianDay = $julianDays[$minYear] - (($minYear - $year) * Constants::DAYS_OF_SHIA_YEAR);
}

return $julianDay;
}

public function isLeap($year)
Expand Down

0 comments on commit 4d4583d

Please sign in to comment.