Skip to content

Commit

Permalink
fix deprecate operation ~~
Browse files Browse the repository at this point in the history
  • Loading branch information
hekmatinasser committed Feb 10, 2022
1 parent 2765a20 commit 90f29d0
Showing 1 changed file with 9 additions and 21 deletions.
30 changes: 9 additions & 21 deletions src/Traits/Transformation.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public static function getJalali($g_y, $g_m, $g_d)
{
$gy = $g_y - 1600;
$gm = $g_m - 1;
$g_day_no = (365 * $gy + static::div($gy + 3, 4) - static::div($gy + 99, 100) + static::div($gy + 399, 400));
$g_day_no = (365 * $gy + intval(($gy + 3) / 4) - intval(($gy + 99) / 100) + intval(($gy + 399) / 400));
for ($i = 0; $i < $gm; ++$i) {
$g_day_no += static::$daysMonthGregorian[$i];
}
Expand All @@ -26,12 +26,12 @@ public static function getJalali($g_y, $g_m, $g_d)
}
$g_day_no += $g_d - 1;
$j_day_no = $g_day_no - 79;
$j_np = static::div($j_day_no, 12053); # 12053 = (365 * 33 + 32 / 4)
$j_np = intval($j_day_no / 12053); # 12053 = (365 * 33 + 32 / 4)
$j_day_no = $j_day_no % 12053;
$jy = (979 + 33 * $j_np + 4 * static::div($j_day_no, 1461)); # 1461 = (365 * 4 + 4 / 4)
$jy = (979 + 33 * $j_np + 4 * intval($j_day_no / 1461)); # 1461 = (365 * 4 + 4 / 4)
$j_day_no %= 1461;
if ($j_day_no >= 366) {
$jy += static::div($j_day_no - 1, 365);
$jy += intval(($j_day_no - 1) / 365);
$j_day_no = ($j_day_no - 1) % 365;
}
for ($i = 0; ($i < 11 && $j_day_no >= static::$daysMonthJalali[$i]); ++$i) {
Expand All @@ -53,31 +53,31 @@ public static function getGregorian($j_y, $j_m, $j_d)
{
$jy = $j_y - 979;
$jm = $j_m - 1;
$j_day_no = (365 * $jy + static::div($jy, 33) * 8 + static::div($jy % 33 + 3, 4));
$j_day_no = (365 * $jy + intval($jy / 33) * 8 + intval(($jy % 33 + 3) / 4));
for ($i = 0; $i < $jm; ++$i) {
$j_day_no += static::$daysMonthJalali[$i];
}
$j_day_no += $j_d - 1;
$g_day_no = $j_day_no + 79;
$gy = (1600 + 400 * static::div($g_day_no, 146097)); # 146097 = (365 * 400 + 400 / 4 - 400 / 100 + 400 / 400)
$gy = (1600 + 400 * intval($g_day_no / 146097)); # 146097 = (365 * 400 + 400 / 4 - 400 / 100 + 400 / 400)
$g_day_no = $g_day_no % 146097;
$leap = 1;
if ($g_day_no >= 36525) { # 36525 = (365 * 100 + 100 / 4)
$g_day_no--;
$gy += (100 * static::div($g_day_no, 36524)); # 36524 = (365 * 100 + 100 / 4 - 100 / 100)
$gy += (100 * intval($g_day_no / 36524)); # 36524 = (365 * 100 + 100 / 4 - 100 / 100)
$g_day_no = $g_day_no % 36524;
if ($g_day_no >= 365) {
$g_day_no++;
} else {
$leap = 0;
}
}
$gy += (4 * static::div($g_day_no, 1461)); # 1461 = (365 * 4 + 4 / 4)
$gy += (4 * intval($g_day_no / 1461)); # 1461 = (365 * 4 + 4 / 4)
$g_day_no %= 1461;
if ($g_day_no >= 366) {
$leap = 0;
$g_day_no--;
$gy += static::div($g_day_no, 365);
$gy += intval($g_day_no / 365);
$g_day_no = ($g_day_no % 365);
}
for ($i = 0; $g_day_no >= (static::$daysMonthGregorian[$i] + ($i == 1 && $leap)); $i++) {
Expand All @@ -86,16 +86,4 @@ public static function getGregorian($j_y, $j_m, $j_d)

return [$gy, $i + 1, $g_day_no + 1];
}

/**
* integer division
*
* @param int $a
* @param int $b
* @return int
*/
private static function div($a, $b)
{
return ~~($a / $b);
}
}

0 comments on commit 90f29d0

Please sign in to comment.