- return $this->redirectToRoute('rapsys_air', ['session' => $session->getId()]);
- }
-
- /**
- * Compute eastern for selected year
- *
- * @param int $year The eastern year
- *
- * @return DateTime The eastern date
- */
- function getEastern($year) {
- //Set static
- static $data = null;
- //Check if already computed
- if (isset($data[$year])) {
- //Return computed eastern
- return $data[$year];
- //Check if data is null
- } elseif (is_null($data)) {
- //Init data array
- $data = [];
- }
- $d = (19 * ($year % 19) + 24) % 30;
- $e = (2 * ($year % 4) + 4 * ($year % 7) + 6 * $d + 5) % 7;
-
- $day = 22 + $d + $e;
- $month = 3;
-
- if ($day > 31) {
- $day = $d + $e - 9;
- $month = 4;
- } elseif ($d == 29 && $e == 6) {
- $day = 10;
- $month = 4;
- } elseif ($d == 28 && $e == 6) {
- $day = 18;
- $month = 4;
- }
-
- //Store eastern in data
- return ($data[$year] = new \DateTime(sprintf('%04d-%02d-%02d', $year, $month, $day)));
- }
-
- /**
- * Check if date is a premium day
- *
- * @desc Consider as premium a day off
- *
- * @param DateTime $date The date to check
- * @return bool Whether the date is off or not
- */
- function isPremium($date) {
- //Get day number
- $w = $date->format('w');
-
- //Check if weekend day
- if ($w == 0 || $w == 6) {
- //Date is weekend day
- return true;
- }
-
- //Get date day
- $d = $date->format('d');
-
- //Get date month
- $m = $date->format('m');
-
- //Check if fixed holiday
- if (
- //Check if 1st january
- ($d == 1 && $m == 1) ||
- //Check if 1st may
- ($d == 1 && $m == 5) ||
- //Check if 8st may
- ($d == 8 && $m == 5) ||
- //Check if 14st july
- ($d == 14 && $m == 7) ||
- //Check if 15st august
- ($d == 15 && $m == 8) ||
- //Check if 1st november
- ($d == 1 && $m == 11) ||
- //Check if 11st november
- ($d == 11 && $m == 11) ||
- //Check if 25st december
- ($d == 25 && $m == 12)
- ) {
- //Date is a fixed holiday
- return true;
- }
-
- //Get eastern
- $eastern = $this->getEastern($date->format('Y'));
-
- //Check dynamic holidays
- if (
- (clone $eastern)->add(new \DateInterval('P1D')) == $date ||
- (clone $eastern)->add(new \DateInterval('P39D')) == $date ||
- (clone $eastern)->add(new \DateInterval('P50D')) == $date
- ) {
- //Date is a dynamic holiday
- return true;
- }
-
- //Date is not a holiday and week day
- return false;