Last active
December 20, 2015 05:29
-
-
Save Neolot/6078663 to your computer and use it in GitHub Desktop.
Возвращает числовое значение временного интервала
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 | |
/* | |
Возвращает числовое значение временного интервала | |
1 - Рабочее время | |
2 - Нерабочее время | |
3 - Выходные | |
*/ | |
$starthour = 9; // Время начала рабочего дня | |
$endhour = 18; // Время конца рабочего дня | |
$offset = 4; // Смещение времени или часовой пояс | |
$weekday = date('w'); | |
$hour = date('G')+$offset; | |
// Рабочее время | |
if ( | |
$weekday >= 1 && | |
$weekday <= 5 && | |
$hour >= $starthour && | |
$hour < $endhour | |
) { | |
$workstatus = 1; | |
} | |
// Нерабочее время | |
if ( | |
$weekday >= 1 && | |
$weekday <= 5 && | |
($hour >= $endhour || $hour < $starthour) | |
) { | |
$workstatus = 2; | |
} | |
// Выходные | |
if ( | |
($weekday >= 5 && $hour >= $endhour) || | |
$weekday == 6 || | |
$weekday == 0 | |
) { | |
$workstatus = 3; | |
} | |
if ( $output == 'return' ) { | |
return $workstatus; | |
} else { | |
echo $workstatus; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment