Last active
November 11, 2016 08:02
-
-
Save MindaugasR/75073af015db2dab064e025f9e4a928a to your computer and use it in GitHub Desktop.
Nedarbo dienų apskaičiavimas
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* @param DateTime|null $date | |
* @return string|null | |
*/ | |
function isNotWorkingDay(DateTime $date = null) | |
{ | |
$localDate = $date ? clone $date : new DateTime(); | |
$month = (int)$localDate->format('n'); | |
$day = (int)$localDate->format('j'); | |
$noWorkingDays = [ | |
1 => [ | |
1 => 'Naujieji metai', | |
], | |
2 => [ | |
16 => 'Lietuvos valstybės atkūrimo diena', | |
], | |
3 => [ | |
11 => 'Lietuvos nepriklausomybės atkūrimo diena', | |
], | |
5 => [ | |
1 => 'Tarptautinė darbininkų diena', | |
], | |
6 => [ | |
24 => 'Rasos ir Joninių diena', | |
], | |
7 => [ | |
6 => 'Valstybės (Lietuvos karaliaus Mindaugo karūnavimo) diena', | |
], | |
8 => [ | |
15 => 'Žolinės (Švč. Mergelės Marijos ėmimo į dangų diena)', | |
], | |
11 => [ | |
1 => 'Visų Šventųjų diena', | |
], | |
12 => [ | |
24 => 'Kūčios', | |
25 => 'Kalėdos', | |
26 => 'Kalėdų antra diena', | |
] | |
]; | |
$stringExceptions = [ | |
'first sunday of may' => 'Motinos diena', | |
'first sunday of june' => 'Tėvo diena', | |
]; | |
foreach ($stringExceptions as $dateTitle => $title) { | |
$dateForTitle = new DateTime($dateTitle); | |
$noWorkingDays[(int)$dateForTitle->format('n')][(int)$dateForTitle->format('j')] = $title; | |
} | |
if (isset($noWorkingDays[$month][$day])) { | |
return $noWorkingDays[$month][$day]; | |
} | |
return null; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment