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