Initial Checkin.
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
class Helper {
|
||||
public static function parseHolidays($config) {
|
||||
$text = $config['holidays']['text'];
|
||||
$from = DateTime::createFromFormat('Y-m-d', $config['holidays']['from']);
|
||||
$until = DateTime::createFromFormat('Y-m-d', $config['holidays']['until']);
|
||||
$text = preg_replace('/\{\{from\}\}/', $from->format('d.m.Y'), $text);
|
||||
$text = preg_replace('/\{\{until\}\}/', $until->format('d.m.Y'), $text);
|
||||
|
||||
return $text;
|
||||
}
|
||||
|
||||
public static function isHoliday($config) {
|
||||
if(!array_key_exists('holidays', $config)) {
|
||||
throw new Exception('holidays missing in config');
|
||||
}
|
||||
|
||||
if(!array_key_exists('from', $config['holidays']) || !array_key_exists('until', $config['holidays'])) {
|
||||
throw new Exception('from/until missing in holidays config');
|
||||
}
|
||||
|
||||
$from = DateTime::createFromFormat('Y-m-d', $config['holidays']['from']);
|
||||
$from->setTime(0, 0);
|
||||
$until = DateTime::createFromFormat('Y-m-d', $config['holidays']['until']);
|
||||
$until->setTime(23, 59, 59);
|
||||
|
||||
$today = new DateTime();
|
||||
$today->setTime(0, 0);
|
||||
|
||||
$dialogShowFrom = clone $from;
|
||||
|
||||
if(array_key_exists('before', $config['holidays']) && !empty($config['holidays']['before'])) {
|
||||
$dialogShowFrom->sub(new DateInterval('P' . $config['holidays']['before']));
|
||||
}
|
||||
|
||||
return ($dialogShowFrom <= $today && $until > $today);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user