3 * @file mod_roomReservationTimeslice.inc
4 * Representation of a timeslice
5 * @author Roland Hieber (roland.hieber@wilhelm-gym.net)
8 * Copyright © 2007 Roland Hieber
10 * Permission is hereby granted, free of charge, to any person obtaining
11 * copy of this software and associated documentation files (the "Software"),
12 * to deal in the Software without restriction, including without limitation
13 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
14 * and/or sell copies of the Software, and to permit persons to whom the
15 * Software is furnished to do so, subject to the following conditions:
17 * The above copyright notice and this permission notice shall be included in
18 * all copies or substantial portions of the Software.
20 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
29 /** Implementation of a simple timeslice with beginning and ending time */
30 class mod_roomReservationTimeslice {
32 /** (timestamp) Time when the timeslice begins */
33 protected $tsBegin = -1;
34 /** (timestamp) Time when the timeslice ends */
35 protected $tsEnd = 86400;
37 /***************************************************************************/
42 * @param $tsBegin (timestamp) Time when the timeslice begins. Only the
43 * time part is used, the date part is ignored.
44 * @param $tsEnd (timestamp) Time when the timeslice ends. Only the time
45 * part is used, the date part is ignored.
46 * @return mod_roomReservationTimeslice
48 public function __construct($tsBegin, $tsEnd) {
49 $this->setBegin($tsBegin);
50 $this->setEnd($tsEnd);
53 /***************************************************************************/
56 * @name Access to attributes
61 * Set the beginning. Only the time part is used, the date part is ignored.
62 * If the timestamp is invalid, an Exception is thrown.
63 * @param $ts (timestamp)
66 public function setBegin($ts) {
67 if(intval($ts) >= $this->getEnd()) {
68 throw new Exception(MOD_ROOM_RESERVATION_ERROR_END_BEFORE_BEGIN);
70 $this->tsBegin = (intval($ts) % 86400);
75 * Set the ending. Only the time part is used, the date part is ignored.
76 * If the timestamp is invalid, an Exception is thrown.
77 * @param $ts (timestamp)
80 public function setEnd($ts) {
81 if($this->getBegin() >= intval($ts)) {
82 throw new Exception(MOD_ROOM_RESERVATION_ERROR_END_BEFORE_BEGIN);
84 $this->tsEnd = (intval($ts) % 86400);
92 public function getBegin() { return $this->tsBegin; }
98 public function getEnd() { return $this->tsEnd; }