Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 13
0.00% covered (danger)
0.00%
0 / 5
CRAP
0.00% covered (danger)
0.00%
0 / 1
Closure
0.00% covered (danger)
0.00%
0 / 13
0.00% covered (danger)
0.00%
0 / 5
72
0.00% covered (danger)
0.00%
0 / 1
 getDefaults
0.00% covered (danger)
0.00%
0 / 4
0.00% covered (danger)
0.00%
0 / 1
2
 setTimestampFromDateformat
0.00% covered (danger)
0.00%
0 / 4
0.00% covered (danger)
0.00%
0 / 1
6
 getDateTime
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 isNewerThan
0.00% covered (danger)
0.00%
0 / 3
0.00% covered (danger)
0.00%
0 / 1
12
 isAffectingAvailability
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2
3namespace BO\Zmsentities;
4
5class Closure extends Schema\Entity
6{
7    const PRIMARY = 'id';
8
9    public static $schema = "closure.json";
10
11    #[\Override]
12    public function getDefaults()
13    {
14        return [
15            'id' => 0,
16            'lastChange' => 1447924981
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($this->year . '-' . $this->month . '-' . $this->day));
32    }
33
34    /**
35     * Check if closure 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}