Mercurial > hg > rc1
comparison plugins/libcalendaring/lib/Sabre/VObject/Component/VFreeBusy.php @ 4:888e774ee983
libcalendar plugin as distributed
author | Charlie Root |
---|---|
date | Sat, 13 Jan 2018 08:57:56 -0500 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
3:f6fe4b6ae66a | 4:888e774ee983 |
---|---|
1 <?php | |
2 | |
3 namespace Sabre\VObject\Component; | |
4 | |
5 use Sabre\VObject; | |
6 | |
7 /** | |
8 * The VFreeBusy component | |
9 * | |
10 * This component adds functionality to a component, specific for VFREEBUSY | |
11 * components. | |
12 * | |
13 * @copyright Copyright (C) 2007-2013 fruux GmbH (https://fruux.com/). | |
14 * @author Evert Pot (http://evertpot.com/) | |
15 * @license http://code.google.com/p/sabredav/wiki/License Modified BSD License | |
16 */ | |
17 class VFreeBusy extends VObject\Component { | |
18 | |
19 /** | |
20 * Checks based on the contained FREEBUSY information, if a timeslot is | |
21 * available. | |
22 * | |
23 * @param DateTime $start | |
24 * @param Datetime $end | |
25 * @return bool | |
26 */ | |
27 public function isFree(\DateTime $start, \Datetime $end) { | |
28 | |
29 foreach($this->select('FREEBUSY') as $freebusy) { | |
30 | |
31 // We are only interested in FBTYPE=BUSY (the default), | |
32 // FBTYPE=BUSY-TENTATIVE or FBTYPE=BUSY-UNAVAILABLE. | |
33 if (isset($freebusy['FBTYPE']) && strtoupper(substr((string)$freebusy['FBTYPE'],0,4))!=='BUSY') { | |
34 continue; | |
35 } | |
36 | |
37 // The freebusy component can hold more than 1 value, separated by | |
38 // commas. | |
39 $periods = explode(',', (string)$freebusy); | |
40 | |
41 foreach($periods as $period) { | |
42 // Every period is formatted as [start]/[end]. The start is an | |
43 // absolute UTC time, the end may be an absolute UTC time, or | |
44 // duration (relative) value. | |
45 list($busyStart, $busyEnd) = explode('/', $period); | |
46 | |
47 $busyStart = VObject\DateTimeParser::parse($busyStart); | |
48 $busyEnd = VObject\DateTimeParser::parse($busyEnd); | |
49 if ($busyEnd instanceof \DateInterval) { | |
50 $tmp = clone $busyStart; | |
51 $tmp->add($busyEnd); | |
52 $busyEnd = $tmp; | |
53 } | |
54 | |
55 if($start < $busyEnd && $end > $busyStart) { | |
56 return false; | |
57 } | |
58 | |
59 } | |
60 | |
61 } | |
62 | |
63 return true; | |
64 | |
65 } | |
66 | |
67 } | |
68 |