Example #1
0
 private function appendBlocked($start, $end, $label, $dayOfWeek = null)
 {
     $this->layout->AppendBlockedPeriod(Time::Parse($start, $this->timezone), Time::Parse($end, $this->timezone), $label, $dayOfWeek);
 }
Example #2
0
 /**
  * @param string $time
  * @param bool $isEndTime
  * @return Date
  */
 public function SetTimeString($time, $isEndTime = false)
 {
     return $this->SetTime(Time::Parse($time, $this->Timezone()), $isEndTime);
 }
Example #3
0
 public function GetLayout($scheduleId, ILayoutFactory $layoutFactory)
 {
     /**
      * @var $layout ScheduleLayout
      */
     $layout = $layoutFactory->CreateLayout();
     $reader = ServiceLocator::GetDatabase()->Query(new GetLayoutCommand($scheduleId));
     while ($row = $reader->GetRow()) {
         $timezone = $row[ColumnNames::BLOCK_TIMEZONE];
         $start = Time::Parse($row[ColumnNames::BLOCK_START], $timezone);
         $end = Time::Parse($row[ColumnNames::BLOCK_END], $timezone);
         $label = $row[ColumnNames::BLOCK_LABEL];
         $periodType = $row[ColumnNames::BLOCK_CODE];
         $dayOfWeek = $row[ColumnNames::BLOCK_DAY_OF_WEEK];
         if ($periodType == PeriodTypes::RESERVABLE) {
             $layout->AppendPeriod($start, $end, $label, $dayOfWeek);
         } else {
             $layout->AppendBlockedPeriod($start, $end, $label, $dayOfWeek);
         }
     }
     $reader->Free();
     return $layout;
 }
Example #4
0
 public function testTimesCanBeCompared()
 {
     $date = Date::Parse('2010-01-01');
     $early = Time::Parse('10:11');
     $late = Time::Parse('12:11');
     $this->assertEquals(-1, $early->Compare($late, $date));
     $this->assertEquals(1, $late->Compare($early, $date));
     $early2 = Time::Parse('10:11', 'US/Central');
     $late2 = Time::Parse('10:11', 'US/Pacific');
     $this->assertEquals(-1, $early2->Compare($late2, $date));
 }
Example #5
0
 public function testGetsDailySummaryForResource()
 {
     $targetTimezone = 'America/Chicago';
     $date = Date::Parse('2009-09-02', $targetTimezone);
     $start = $date->SetTime(Time::Parse('04:00'));
     $end = $date->SetTime(Time::Parse('05:00'));
     $resourceId = 1;
     $scheduleLayout = new ScheduleLayout($targetTimezone);
     $scheduleLayout->AppendPeriod(new Time(4, 0, 0, $targetTimezone), new Time(5, 0, 0, $targetTimezone));
     $listing = $this->getMock('IReservationListing');
     $firstReservation = new TestReservationListItem($start, $end, $resourceId);
     $reservations = array($firstReservation, new TestReservationListItem($start, $end, $resourceId), new TestBlackoutListItem($start, $end, $resourceId));
     $listing->expects($this->once())->method('OnDateForResource')->with($this->equalTo($date), $this->equalTo($resourceId))->will($this->returnValue($reservations));
     $layout = new DailyLayout($listing, $scheduleLayout);
     $summary = $layout->GetSummary($date, $resourceId);
     $this->assertEquals(2, $summary->NumberOfReservations());
     $this->assertEquals($firstReservation, $summary->FirstReservation());
 }
 public function testSkipsAddingBufferSlotsIfThereIsAnotherItemAtThatTime()
 {
     $tz = 'America/Chicago';
     $listDate = Date::Parse('2011-02-08', $tz);
     $layout = new ScheduleLayout($tz);
     $layout->AppendPeriod(Time::Parse('0:00', $tz), Time::Parse('0:30', $tz));
     $layout->AppendPeriod(Time::Parse('0:30', $tz), Time::Parse('1:00', $tz));
     $layout->AppendPeriod(Time::Parse('1:00', $tz), Time::Parse('1:30', $tz));
     $layout->AppendPeriod(Time::Parse('1:30', $tz), Time::Parse('2:00', $tz));
     $layout->AppendPeriod(Time::Parse('2:00', $tz), Time::Parse('6:00', $tz));
     $layout->AppendPeriod(Time::Parse('6:00', $tz), Time::Parse('0:00', $tz));
     $item1 = new TestReservationItemView(1, Date::Parse('2011-02-08 0:30', $tz)->ToUtc(), Date::Parse('2011-02-08 1:00', $tz)->ToUtc(), 1);
     $item2 = new TestReservationItemView(2, Date::Parse('2011-02-08 1:30', $tz)->ToUtc(), Date::Parse('2011-02-08 2:00', $tz)->ToUtc(), 1);
     $item1->WithBufferTime(60 * 60);
     $item2->WithBufferTime(60 * 60);
     $r1 = new ReservationListItem($item1);
     $r2 = new ReservationListItem($item2);
     $list = new ScheduleReservationList(array($r1, $r2), $layout, $listDate, false);
     /** @var IReservationSlot[] $slots */
     $slots = $list->BuildSlots();
     $this->assertTrue($slots[0]->Begin()->Equals(Time::Parse('0:00', $tz)));
     $this->assertTrue($slots[0]->End()->Equals(Time::Parse('0:30', $tz)));
     $this->assertInstanceOf('BufferSlot', $slots[0]);
     $this->assertTrue($slots[1]->Begin()->Equals(Time::Parse('0:30', $tz)));
     $this->assertTrue($slots[1]->End()->Equals(Time::Parse('1:00', $tz)));
     $this->assertInstanceOf('ReservationSlot', $slots[1]);
     $this->assertTrue($slots[2]->Begin()->Equals(Time::Parse('1:00', $tz)));
     $this->assertTrue($slots[2]->End()->Equals(Time::Parse('1:30', $tz)));
     $this->assertInstanceOf('EmptyReservationSlot', $slots[2]);
     $this->assertTrue($slots[3]->Begin()->Equals(Time::Parse('1:30', $tz)));
     $this->assertTrue($slots[3]->End()->Equals(Time::Parse('2:00', $tz)));
     $this->assertInstanceOf('ReservationSlot', $slots[3]);
     $this->assertTrue($slots[4]->Begin()->Equals(Time::Parse('2:00', $tz)));
     $this->assertTrue($slots[4]->End()->Equals(Time::Parse('6:00', $tz)));
     $this->assertInstanceOf('BufferSlot', $slots[0]);
 }
 public function testSkipsBlockedPeriodsForDailyLayout()
 {
     $tz = 'America/New_York';
     $scheduleLayoutFactory = new ScheduleLayoutFactory($tz);
     $layout = $scheduleLayoutFactory->CreateLayout();
     $layout->AppendPeriod(Time::Parse("00:00", $tz), Time::Parse("00:00", $tz), null, DayOfWeek::SUNDAY);
     $layout->AppendBlockedPeriod(Time::Parse("00:00", $tz), Time::Parse("00:00", $tz), null, DayOfWeek::MONDAY);
     $layout->AppendPeriod(Time::Parse("00:00", $tz), Time::Parse("00:00", $tz), null, DayOfWeek::TUESDAY);
     $layout->AppendPeriod(Time::Parse("00:00", $tz), Time::Parse("00:00", $tz), null, DayOfWeek::WEDNESDAY);
     $layout->AppendPeriod(Time::Parse("00:00", $tz), Time::Parse("00:00", $tz), null, DayOfWeek::THURSDAY);
     $layout->AppendPeriod(Time::Parse("00:00", $tz), Time::Parse("00:00", $tz), null, DayOfWeek::FRIDAY);
     $layout->AppendPeriod(Time::Parse("00:00", $tz), Time::Parse("00:00", $tz), null, DayOfWeek::SATURDAY);
     $sun = Date::Parse('2013-01-06 23:30', $tz);
     $mon = Date::Parse('2013-01-07 00:00', $tz);
     $tue = Date::Parse('2013-01-08 01:00', $tz);
     $wed = Date::Parse('2013-01-09 00:30', $tz);
     $thu = Date::Parse('2013-01-10 23:00', $tz);
     $fri = Date::Parse('2013-01-11 02:30', $tz);
     $sat = Date::Parse('2013-01-12 03:30', $tz);
     $sunPeriods = $layout->GetLayout($sun, true);
     $monPeriods = $layout->GetLayout($mon, true);
     $tuePeriods = $layout->GetLayout($tue, true);
     $wedPeriods = $layout->GetLayout($wed, true);
     $thuPeriods = $layout->GetLayout($thu, true);
     $friPeriods = $layout->GetLayout($fri, true);
     $satPeriods = $layout->GetLayout($sat, true);
     $this->assertEquals(1, count($sunPeriods));
     $this->assertEquals(0, count($monPeriods));
     $this->assertEquals(1, count($tuePeriods));
     $this->assertEquals(1, count($wedPeriods));
     $this->assertEquals(1, count($thuPeriods));
     $this->assertEquals(1, count($friPeriods));
     $this->assertEquals(1, count($satPeriods));
 }