Skip to content

Instantly share code, notes, and snippets.

@Gyvastis
Last active March 4, 2021 19:42
Show Gist options
  • Save Gyvastis/ee0f6b7d146af86b2124997f4d899d6a to your computer and use it in GitHub Desktop.
Save Gyvastis/ee0f6b7d146af86b2124997f4d899d6a to your computer and use it in GitHub Desktop.
visa 90 days in 180 days calculator
<?php
$visitDates = [
['2020-06-16', '2020-06-30'],
['2020-07-23', '2020-07-28'],
['2020-10-09', '2020-11-04'],
['2020-12-15', '2021-01-16'],
['2021-01-30', '2021-02-26'],
];
$visaDays = 90;
$visaWindowDays = 180;
$controlDate = (new DateTime('2021-04-06'))->modify(sprintf('-%d day', $visaWindowDays));
// var_dump($controlDate);
foreach($visitDates as $visitDate) {
$leaveDate = new DateTime($visitDate[1]);
if($leaveDate < $controlDate) {
continue;
}
$enterDate = new DateTime($visitDate[0]);
if($enterDate < $controlDate) {
$enterDate = $controlDate;
}
$durationDays = $leaveDate->diff($enterDate)->days + 1;
// var_dump($durationDays);
$visaDays -= $durationDays;
}
var_dump($visaDays);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment