diff --git a/system/autoload/Package.php b/system/autoload/Package.php index 8ba37d5d..a07fe9ae 100644 --- a/system/autoload/Package.php +++ b/system/autoload/Package.php @@ -149,24 +149,18 @@ class Package $exp_date->modify('first day of next month'); $exp_date->setDate($exp_date->format('Y'), $exp_date->format('m'), $day_exp); - $min_days = 7; - $max_days = 35; - - // If validity is more than 2 months, multiply the limit days - if ($p['validity'] >= 2) { - $min_days *= $p['validity']; - $max_days *= $p['validity']; - } + $min_days = 7 * $p['validity']; + $max_days = 35 * $p['validity']; $days_until_exp = $exp_date->diff($current_date)->days; - // If less than min_days away, move to the next month + // If less than min_days away, move to the next period while ($days_until_exp < $min_days) { $exp_date->modify('+1 month'); $days_until_exp = $exp_date->diff($current_date)->days; } - // If more than max_days away, move to the previous month + // If more than max_days away, move to the previous period while ($days_until_exp > $max_days) { $exp_date->modify('-1 month'); $days_until_exp = $exp_date->diff($current_date)->days; @@ -177,9 +171,15 @@ class Package $exp_date->modify('+1 month'); } + // Adjust for multiple periods + if ($p['validity'] > 1) { + $exp_date->modify('+' . ($p['validity'] - 1) . ' months'); + } + $date_exp = $exp_date->format('Y-m-d'); $time = "23:59:59"; } else if ($p['validity_unit'] == 'Days') { + $datetime = explode(' ', date("Y-m-d H:i:s", strtotime('+' . $p['validity'] . ' day'))); $date_exp = $datetime[0]; $time = $datetime[1];