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 string PRIMARY = 'id';
8
9    public static $schema = "dayoff.json";
10
11    /**
12     * @return (int|string)[]
13     *
14     */
15    #[\Override]
16    public function getDefaults()
17    {
18        return [
19            'date' => 1447924981,
20            'name' => ''
21        ];
22    }
23
24    public function setTimestampFromDateformat($fromFormat = 'd.m.Y'): static
25    {
26        $dateTime = \DateTimeImmutable::createFromFormat($fromFormat, $this->date, new \DateTimeZone('UTC'));
27        if ($dateTime) {
28            $this->date = $dateTime->modify('00:00:00')->getTimestamp();
29        }
30        return $this;
31    }
32
33    public function getDateTime(): Helper\DateTime
34    {
35        return (new \BO\Zmsentities\Helper\DateTime())->setTimestamp($this->date);
36    }
37
38    /**
39     * Check if dayoff is newer than given time
40     *
41     * @return bool
42     */
43    public function isNewerThan(\DateTimeInterface $dateTime, $filterByAvailability = null, $now = null)
44    {
45        if ($filterByAvailability && !$this->isAffectingAvailability($filterByAvailability, $now)) {
46            return false;
47        }
48        return ($dateTime->getTimestamp() < $this->lastChange);
49    }
50
51    public function isAffectingAvailability(Availability $availabiliy, \DateTimeInterface $now): bool
52    {
53        return $availabiliy->isBookable($this->getDateTime(), $now);
54    }
55}