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