fix clear and copy week

This commit is contained in:
2019-11-05 16:58:25 +01:00
committed by Roland Schneider
parent 9c0e2a56ee
commit 2c5db234ce
19 changed files with 692 additions and 142 deletions

View File

@@ -5,18 +5,30 @@ namespace customerapi\models\available;
use DateTime;
use Exception;
/**
* Class DateIntervalHelper
* @package customerapi\models\available
* @property \DateTime $firstActiveDate
* @property \DateTime $lastActiveDate
* @property \DateTime $firstDisplayDate
* @property \DateTime $lastDisplayDate
* @property DateTime $firstActiveDate
* @property DateTime $lastActiveDate
* @property DateTime $firstDisplayDate
* @property DateTime $lastDisplayDate
*/
class EventInterval
{
const monday = 'monday';
const tuesday = 'tuesday';
const wednesday = 'wednesday';
const thursday = 'thursday';
const friday = 'friday';
const saturday = 'saturday';
const sunday = 'sunday';
const weekdays = [EventInterval::monday, EventInterval::tuesday, EventInterval::wednesday, EventInterval::thursday, EventInterval::friday, EventInterval::saturday, EventInterval::sunday];
public $year;
public $month;
@@ -29,13 +41,20 @@ class EventInterval
public $firstDisplayDate;
public $lastDisplayDate;
private function __construct($today = null, $countOfActiveDays = 14,$daysToDisplay = 21)
/**
* EventInterval constructor.
* @param DateTime $today
* @param int $countOfActiveDays count of active days from today
* @param int $daysToDisplay the count of visible days from the first weekday of week, which is calculated by today
* @throws Exception on any error
*/
private function __construct($today = null, $countOfActiveDays = 14, $daysToDisplay = 21)
{
$this->countOfActiveDays = $countOfActiveDays;
$this->daysToDisplay = $daysToDisplay;
if ( !isset($today)){
if (!isset($today)) {
$today = new DateTime();
}
$today->setTime(0, 0);
@@ -61,13 +80,20 @@ class EventInterval
}
public static function createInterval($today = null,$countOfActiveDays = 14,$daysToDisplay = 21)
/**
* @param null $today
* @param int $countOfActiveDays
* @param int $daysToDisplay
* @return EventInterval
* @throws Exception
*/
public static function createInterval($today = null, $countOfActiveDays = 14, $daysToDisplay = 21)
{
return new EventInterval($today,$countOfActiveDays,$daysToDisplay);
return new EventInterval($today, $countOfActiveDays, $daysToDisplay);
}
/**
* @param DateTime $day
* @param DateTime $day
* @return bool true if active, otherwise false
*/
public function isActive($day)
@@ -75,7 +101,7 @@ class EventInterval
$afterFirstActiveDay = $this->firstActiveDate < $day || $this->firstActiveDate == $day;
$beforeLastActiveDay = $this->lastActiveDate > $day || $this->lastActiveDate == $day;
return ($afterFirstActiveDay && $beforeLastActiveDay);
return ($afterFirstActiveDay && $beforeLastActiveDay);
}
/**
@@ -93,5 +119,4 @@ class EventInterval
}
}