Пример #1
0
 public function testAddsReservationsToCalendar()
 {
     $startsBeforeWeek = new ReservationItemView();
     $startsBeforeWeek->StartDate = Date::Parse('2011-07-30 12:00', 'UTC');
     $startsBeforeWeek->EndDate = Date::Parse('2011-07-31 12:00', 'UTC');
     $endsAfterWeek = new ReservationItemView();
     $endsAfterWeek->StartDate = Date::Parse('2011-08-06 12:00', 'UTC');
     $endsAfterWeek->EndDate = Date::Parse('2012-08-08 12:00', 'UTC');
     $firstDayOnly = new ReservationItemView();
     $firstDayOnly->StartDate = Date::Parse('2011-07-31 14:00', 'UTC');
     $firstDayOnly->EndDate = Date::Parse('2011-07-31 16:25', 'UTC');
     $secondAndThirdDay = new ReservationItemView();
     $secondAndThirdDay->StartDate = Date::Parse('2011-08-01 14:00', 'UTC');
     $secondAndThirdDay->EndDate = Date::Parse('2011-08-02 16:25', 'UTC');
     $notInWeek = new ReservationItemView();
     $notInWeek->StartDate = Date::Parse('2011-11-02 14:00', 'UTC');
     $notInWeek->EndDate = Date::Parse('2011-11-03 16:25', 'UTC');
     $reservations = array($startsBeforeWeek, $endsAfterWeek, $firstDayOnly, $secondAndThirdDay, $notInWeek);
     $timezone = 'America/Chicago';
     $week = CalendarWeek::FromDate(2011, 8, 3, $timezone);
     $calendarReservations = CalendarReservation::FromViewList($reservations, $timezone, $this->fakeUser);
     $week->AddReservations($calendarReservations);
     $expectedFirstDay = Date::Parse('2011-07-31', $timezone);
     $expectedLastDay = Date::Parse('2011-08-06', $timezone);
     $this->assertEquals($expectedFirstDay, $week->FirstDay());
     $this->assertEquals($expectedLastDay, $week->LastDay());
     $day1 = new CalendarDay($expectedFirstDay);
     $day1->AddReservation(CalendarReservation::FromView($startsBeforeWeek, $timezone, $this->fakeUser));
     $day1->AddReservation(CalendarReservation::FromView($firstDayOnly, $timezone, $this->fakeUser));
     $day2 = new CalendarDay($expectedFirstDay->AddDays(1));
     $day2->AddReservation(CalendarReservation::FromView($secondAndThirdDay, $timezone, $this->fakeUser));
     $day3 = new CalendarDay($expectedFirstDay->AddDays(2));
     $day3->AddReservation(CalendarReservation::FromView($secondAndThirdDay, $timezone, $this->fakeUser));
     $day4 = new CalendarDay($expectedFirstDay->AddDays(3));
     $day5 = new CalendarDay($expectedFirstDay->AddDays(4));
     $day6 = new CalendarDay($expectedFirstDay->AddDays(5));
     $day7 = new CalendarDay($expectedFirstDay->AddDays(6));
     $day7->AddReservation(CalendarReservation::FromView($endsAfterWeek, $timezone, $this->fakeUser));
     /** @var $actualDays array|CalendarDay[] */
     $actualDays = $week->Days();
     $this->assertEquals(7, count($actualDays));
     $this->assertEquals($day1->Date(), $actualDays[0]->Date());
     $this->assertEquals($day2, $actualDays[1]);
     $this->assertEquals($day3, $actualDays[2]);
     $this->assertEquals($day4, $actualDays[3]);
     $this->assertEquals($day5, $actualDays[4]);
     $this->assertEquals($day6, $actualDays[5]);
     $this->assertEquals($day7, $actualDays[6]);
     $next = Date::Parse('2011-08-07', $timezone);
     $prev = Date::Parse('2011-07-24', $timezone);
     $this->assertEquals($next, $week->GetNextDate());
     $this->assertEquals($prev, $week->GetPreviousDate());
 }
Пример #2
0
 /**
  * @static
  * @return CalendarDay
  */
 public static function Null()
 {
     if (self::$nullInstance == null) {
         self::$nullInstance = new NullCalendarDay();
     }
     return self::$nullInstance;
 }
 public function __construct(Date $base, $weekStart = Timestamp::WEEKDAY_MONDAY)
 {
     $firstDayOfMonth = Date::create($base->getYear() . '-' . $base->getMonth() . '-01');
     $lastDayOfMonth = Date::create($base->getYear() . '-' . $base->getMonth() . '-' . date('t', $base->toStamp()));
     $start = $firstDayOfMonth->getFirstDayOfWeek($weekStart);
     $end = $lastDayOfMonth->getLastDayOfWeek($weekStart);
     $this->monthRange = DateRange::create()->lazySet($firstDayOfMonth, $lastDayOfMonth);
     $this->fullRange = DateRange::create()->lazySet($start, $end);
     $rawDays = $this->fullRange->split();
     $this->fullLength = 0;
     foreach ($rawDays as $rawDay) {
         $day = CalendarDay::create($rawDay->toStamp());
         if ($this->monthRange->contains($day)) {
             $day->setOutside(false);
         } else {
             $day->setOutside(true);
         }
         $this->days[$day->toDate()] = $day;
         $weekNumber = floor($this->fullLength / 7);
         if (!isset($this->weeks[$weekNumber])) {
             $this->weeks[$weekNumber] = CalendarWeek::create();
         }
         $this->weeks[$weekNumber]->addDay($day);
         ++$this->fullLength;
     }
     ++$this->fullLength;
 }
 public function testSleeping()
 {
     $calendarDay = CalendarDay::create('1984-03-25')->setOutside(true)->setSelected(false);
     $serializedDay = serialize($calendarDay);
     $unserializedDay = unserialize($serializedDay);
     $this->assertEquals($calendarDay->getDay(), $unserializedDay->getDay());
     $this->assertEquals($calendarDay->getMonth(), $unserializedDay->getMonth());
     $this->assertEquals($calendarDay->getYear(), $unserializedDay->getYear());
     $this->assertEquals($calendarDay->isOutside(), $unserializedDay->isOutside());
     $this->assertEquals($calendarDay->isSelected(), $unserializedDay->isSelected());
 }
Пример #5
0
 /**
  * @return CalendarWeek
  **/
 public function addDay(CalendarDay $day)
 {
     $this->days[$day->toDate()] = $day;
     return $this;
 }
Пример #6
0
 public function testAddsReservationsToCalendar()
 {
     $startsBeforeMonth = new ReservationItemView();
     $startsBeforeMonth->StartDate = Date::Parse('2011-11-25', 'UTC');
     $startsBeforeMonth->EndDate = Date::Parse('2011-12-01 12:25', 'UTC');
     $startsBeforeMonth->ResourceName = 'Something Fun';
     $startsBeforeMonth->UserLevelId = ReservationUserLevel::OWNER;
     $endsAfterMonth = new ReservationItemView();
     $endsAfterMonth->StartDate = Date::Parse('2011-12-25', 'UTC');
     $endsAfterMonth->EndDate = Date::Parse('2012-01-25', 'UTC');
     $endsAfterMonth->ResourceName = 'Something Fun';
     $endsAfterMonth->UserLevelId = ReservationUserLevel::PARTICIPANT;
     $firstDayOnly = new ReservationItemView();
     $firstDayOnly->StartDate = Date::Parse('2011-12-01 14:00', 'UTC');
     $firstDayOnly->EndDate = Date::Parse('2011-12-01 16:25', 'UTC');
     $firstDayOnly->ResourceName = 'Something Fun';
     $firstDayOnly->UserLevelId = ReservationUserLevel::OWNER;
     $secondAndThirdDay = new ReservationItemView();
     $secondAndThirdDay->StartDate = Date::Parse('2011-12-02 14:00', 'UTC');
     $secondAndThirdDay->EndDate = Date::Parse('2011-12-03 16:25', 'UTC');
     $secondAndThirdDay->ResourceName = 'Something Fun';
     $secondAndThirdDay->UserLevelId = ReservationUserLevel::INVITEE;
     $notInMonth = new ReservationItemView();
     $notInMonth->StartDate = Date::Parse('2011-11-02 14:00', 'UTC');
     $notInMonth->EndDate = Date::Parse('2011-11-03 16:25', 'UTC');
     $notInMonth->ResourceName = 'Something Fun';
     $notInMonth->UserLevelId = ReservationUserLevel::OWNER;
     $reservations = array($startsBeforeMonth, $endsAfterMonth, $firstDayOnly, $secondAndThirdDay, $notInMonth);
     $timezone = 'America/Chicago';
     $calendarReservations = CalendarReservation::FromViewList($reservations, $timezone, $this->fakeUser);
     $month = new CalendarMonth(12, 2011, $timezone);
     $month->AddReservations($calendarReservations);
     $expectedFirstDay = Date::Parse('2011-12-01', $timezone);
     $expectedLastDay = Date::Parse('2012-01-01', $timezone);
     $this->assertEquals($expectedFirstDay, $month->FirstDay());
     $this->assertEquals($expectedLastDay, $month->LastDay());
     $nullDay = CalendarDay::Null();
     $day1 = new CalendarDay($expectedFirstDay);
     $day1->AddReservation(CalendarReservation::FromView($startsBeforeMonth, $timezone, $this->fakeUser));
     $day1->AddReservation(CalendarReservation::FromView($firstDayOnly, $timezone, $this->fakeUser));
     $day2 = new CalendarDay($expectedFirstDay->AddDays(1));
     $day2->AddReservation(CalendarReservation::FromView($secondAndThirdDay, $timezone, $this->fakeUser));
     $day3 = new CalendarDay($expectedFirstDay->AddDays(2));
     $day3->AddReservation(CalendarReservation::FromView($secondAndThirdDay, $timezone, $this->fakeUser));
     $weeks = $month->Weeks();
     /** @var $actualWeek1 CalendarWeek */
     $actualWeek1 = $weeks[0];
     /** @var $actualDays array|CalendarDay[] */
     $actualDays = $actualWeek1->Days();
     $this->assertEquals(5, count($weeks));
     $this->assertEquals(7, count($actualDays));
     $this->assertEquals($nullDay, $actualDays[0]);
     $this->assertEquals($nullDay, $actualDays[1]);
     $this->assertEquals($nullDay, $actualDays[2]);
     $this->assertEquals($nullDay, $actualDays[3]);
     $this->assertEquals(2, count($actualDays[4]->Reservations()));
     $this->assertEquals($day1, $actualDays[4]);
     $this->assertEquals($day2, $actualDays[5]);
     $this->assertEquals($day3, $actualDays[6]);
     $lastWeekDays = $weeks[4]->Days();
     $lastDayReservations = $lastWeekDays[6]->Reservations();
     $this->assertEquals(CalendarReservation::FromView($endsAfterMonth, $timezone, $this->fakeUser), $lastDayReservations[0]);
     $next = Date::Parse('2012-01-01', $timezone);
     $prev = Date::Parse('2011-11-01', $timezone);
     $this->assertEquals($next, $month->GetNextDate());
     $this->assertEquals($prev, $month->GetPreviousDate());
 }
Пример #7
0
 public function AddDay(CalendarDay $day)
 {
     $this->days[] = $day;
     $this->indexedDays[$day->Weekday()] = $day;
 }