Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
13 / 13
100.00% covered (success)
100.00%
5 / 5
CRAP
100.00% covered (success)
100.00%
1 / 1
Dayoff
100.00% covered (success)
100.00%
13 / 13
100.00% covered (success)
100.00%
5 / 5
8
100.00% covered (success)
100.00%
1 / 1
 getDefaults
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
1
 setTimestampFromDateformat
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
2
 getDateTime
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 isNewerThan
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
3
 isAffectingAvailability
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3namespace BO\Zmsentities;
4
5class Dayoff extends Schema\Entity
6{
7    public const PRIMARY = 'id';
8
9    public static $schema = "dayoff.json";
10
11    #[\Override]
12    public function getDefaults()
13    {
14        return [
15            'date' => 1447924981,
16            'name' => ''
17        ];
18    }
19
20    public function setTimestampFromDateformat($fromFormat = 'd.m.Y')
21    {
22        $dateTime = \DateTimeImmutable::createFromFormat($fromFormat, $this->date, new \DateTimeZone('UTC'));
23        if ($dateTime) {
24            $this->date = $dateTime->modify('00:00:00')->getTimestamp();
25        }
26        return $this;
27    }
28
29    public function getDateTime()
30    {
31        return (new \BO\Zmsentities\Helper\DateTime())->setTimestamp($this->date);
32    }
33
34    /**
35     * Check if dayoff is newer than given time
36     *
37     * @return bool
38     */
39    public function isNewerThan(\DateTimeInterface $dateTime, $filterByAvailability = null, $now = null)
40    {
41        if ($filterByAvailability && !$this->isAffectingAvailability($filterByAvailability, $now)) {
42            return false;
43        }
44        return ($dateTime->getTimestamp() < $this->lastChange);
45    }
46
47    public function isAffectingAvailability(Availability $availabiliy, \DateTimeInterface $now)
48    {
49        return $availabiliy->isBookable($this->getDateTime(), $now);
50    }
51}