Example #1
0
 public function Create($type, $year, $month, $day, $timezone, $firstDayOfWeek = 0)
 {
     if ($type == CalendarTypes::Day) {
         return new CalendarDay(Date::Create($year, $month, $day, 0, 0, 0, $timezone));
     }
     if ($type == CalendarTypes::Week) {
         return CalendarWeek::FromDate($year, $month, $day, $timezone, $firstDayOfWeek);
     }
     return new CalendarMonth($month, $year, $timezone);
 }
Example #2
0
 public static function FromDate($year, $month, $day, $timezone, $firstDayOfWeek = 0)
 {
     $week = new CalendarWeek($timezone);
     $date = Date::Create($year, $month, $day, 0, 0, 0, $timezone);
     $start = $date->Weekday();
     if ($firstDayOfWeek == Schedule::Today) {
         $firstDayOfWeek = 0;
     }
     $adjustedDays = $firstDayOfWeek - $start;
     if ($start < $firstDayOfWeek) {
         $adjustedDays = $adjustedDays - 7;
     }
     $date = $date->AddDays($adjustedDays);
     for ($i = 0; $i < 7; $i++) {
         $week->AddDay(new CalendarDay($date->AddDays($i)));
     }
     return $week;
 }
Example #3
0
 /**
  * @param $range string|Report_Range
  * @param $startString
  * @param $endString
  * @param string $timezone
  */
 public function __construct($range, $startString, $endString, $timezone = 'UTC')
 {
     $this->range = $range;
     $this->start = empty($startString) ? Date::Min() : Date::Parse($startString, $timezone);
     $this->end = empty($endString) ? Date::Max() : Date::Parse($endString, $timezone);
     $now = Date::Now()->ToTimezone($timezone);
     if ($this->range == self::CURRENT_MONTH) {
         $this->start = Date::Create($now->Year(), $now->Month(), 1, 0, 0, 0, $timezone);
         $this->end = $this->start->AddMonths(1);
     }
     if ($this->range == self::CURRENT_WEEK) {
         $this->start = $now->GetDate()->AddDays(-$now->Weekday());
         $this->end = $this->Start()->AddDays(8);
     }
     if ($this->range == self::TODAY) {
         $this->start = Date::Create($now->Year(), $now->Month(), $now->Day(), 0, 0, 0, $timezone);
         $this->end = $this->start->AddDays(1);
     }
 }
Example #4
0
 public function __construct($month, $year, $timezone)
 {
     $this->month = $month;
     $this->year = $year;
     $this->timezone = $timezone;
     $this->firstDay = Date::Create($this->year, $this->month, 1, 0, 0, 0, $this->timezone);
     $this->lastDay = $this->firstDay->AddMonths(1);
     $daysInMonth = $this->lastDay->AddDays(-1)->Day();
     $weeks = floor(($daysInMonth + $this->firstDay->Weekday() - 1) / 7);
     for ($week = 0; $week <= $weeks; $week++) {
         $this->weeks[$week] = new CalendarWeek($timezone);
     }
     for ($dayOffset = 0; $dayOffset < $daysInMonth; $dayOffset++) {
         $currentDay = $this->firstDay->AddDays($dayOffset);
         $currentWeek = $this->GetWeekNumber($currentDay);
         $calendarDay = new CalendarDay($currentDay);
         $this->weeks[$currentWeek]->AddDay($calendarDay);
     }
 }
 private function GetDateOffsetFromToday($date, $timezone)
 {
     if (empty($date)) {
         return null;
     }
     $today = Date::Create(Date('Y'), Date('m'), Date('d'), 0, 0, 0, $timezone);
     $diff = DateDiff::BetweenDates($today, $date);
     return $diff->Days();
 }
 public function testProvidedStartDateIsUsedIfSpecified()
 {
     $timezone = 'CST';
     // saturday
     $selectedDate = Date::Create(2009, 07, 18, 00, 00, 00, 'CST');
     $startDay = 0;
     $daysVisible = 7;
     // previous sunday
     $expectedStart = Date::Create(2009, 07, 12, 00, 00, 00, $timezone);
     $expectedEnd = $expectedStart->AddDays($daysVisible);
     $expectedScheduleDates = new DateRange($expectedStart, $expectedEnd);
     $user = new UserSession(1);
     $user->Timezone = $timezone;
     $this->fakeConfig->SetTimezone('CST');
     $schedule = $this->getMock('ISchedule');
     $schedulePage = $this->getMock('ISchedulePage');
     $schedulePage->expects($this->once())->method('GetSelectedDate')->will($this->returnValue($selectedDate->Format("Y-m-d")));
     $schedule->expects($this->once())->method('GetWeekdayStart')->will($this->returnValue($startDay));
     $schedule->expects($this->once())->method('GetDaysVisible')->will($this->returnValue($daysVisible));
     $pageBuilder = new SchedulePageBuilder();
     $dates = $pageBuilder->GetScheduleDates($user, $schedule, $schedulePage);
     //echo $expectedScheduleDates->ToString();
     //echo $utcDates->ToString();
     $this->assertEquals($expectedScheduleDates, $dates);
 }
Example #7
0
 /**
  * Compares this time to the one passed in
  * Returns:
  * -1 if this time is less than the passed in time
  * 0 if the times are equal
  * 1 if this time is greater than the passed in time
  * @param Time $time
  * @param Date|null $comparisonDate date to be used for time comparison
  * @return int comparison result
  */
 public function Compare(Time $time, $comparisonDate = null)
 {
     if ($comparisonDate != null) {
         $myDate = Date::Create($comparisonDate->Year(), $comparisonDate->Month(), $comparisonDate->Day(), $this->Hour(), $this->Minute(), $this->Second(), $this->Timezone());
         $otherDate = Date::Create($comparisonDate->Year(), $comparisonDate->Month(), $comparisonDate->Day(), $time->Hour(), $time->Minute(), $time->Second(), $time->Timezone());
         return $myDate->Compare($otherDate);
     }
     return $this->GetDate()->Compare($time->GetDate());
 }
Example #8
0
 /**
  * @param Time $time
  * @param bool $isEndTime
  * @return Date
  */
 public function SetTime(Time $time, $isEndTime = false)
 {
     $date = Date::Create($this->Year(), $this->Month(), $this->Day(), $time->Hour(), $time->Minute(), $time->Second(), $this->Timezone());
     if ($isEndTime) {
         if ($time->Hour() == 0 && $time->Minute() == 0 && $time->Second() == 0) {
             return $date->AddDays(1);
         }
     }
     return $date;
 }
Example #9
0
 /**
  * @param Date $date
  * @return SchedulePeriod period which occurs at this datetime. Includes start time, excludes end time
  */
 public function GetPeriod(Date $date)
 {
     $timezone = $this->layoutTimezone;
     $tempDate = $date->ToTimezone($timezone);
     $periods = $this->getPeriods($tempDate);
     /** @var $period LayoutPeriod */
     foreach ($periods as $period) {
         $start = Date::Create($tempDate->Year(), $tempDate->Month(), $tempDate->Day(), $period->Start->Hour(), $period->Start->Minute(), 0, $timezone);
         $end = Date::Create($tempDate->Year(), $tempDate->Month(), $tempDate->Day(), $period->End->Hour(), $period->End->Minute(), 0, $timezone);
         if ($end->IsMidnight()) {
             $end = $end->AddDays(1);
         }
         if ($start->Compare($date) <= 0 && $end->Compare($date) > 0) {
             return $this->BuildPeriod($period->PeriodTypeClass(), $start, $end, $period->Label);
         }
     }
     return null;
 }
Example #10
0
 /**
  * @param Date $date
  * @param int $yearOffset
  * @return Date
  */
 private function GetFirstOfYear(Date $date, $yearOffset = 0)
 {
     return Date::Create($date->Year() + $yearOffset, 1, 1, 0, 0, 0, $date->Timezone());
 }
Example #11
0
 /**
  * @param Date $date
  * @param int $monthOffset
  * @return Date
  */
 private function GetFirstOfMonth(Date $date, $monthOffset = 0)
 {
     return Date::Create($date->Year(), $date->Month() + $monthOffset, 1, 0, 0, 0, $date->Timezone());
 }
Example #12
0
 public function testDateRangeReturnsAllDatesForRangeWithoutTime()
 {
     $begin = Date::Create(2008, 9, 9, 10, 11, 12, 'UTC');
     $end = Date::Create(2008, 9, 12, 10, 11, 12, 'UTC');
     $range = new DateRange($begin, $end);
     $expected[] = $begin->GetDate();
     $expected[] = $begin->AddDays(1)->GetDate();
     $expected[] = $begin->AddDays(2)->GetDate();
     $expected[] = $begin->AddDays(3)->GetDate();
     $actual = $range->Dates();
     //		foreach ($expected as $d)
     //		{
     //			echo $d->ToString();
     //			echo "\n";
     //		}
     //
     //		echo "\n";
     //
     //		foreach ($actual as $d)
     //		{
     //			echo $d->ToString();
     //			echo "\n";
     //		}
     //		$this->assertEquals($expected, $actual);
     $this->assertEquals(count($expected), count($actual));
     $this->assertTrue($expected[0]->Equals($actual[0]), "Dates[0] are not equal");
     $this->assertTrue($expected[1]->Equals($actual[1]), "Dates[1] are not equal");
     $this->assertTrue($expected[2]->Equals($actual[2]), "Dates[2] are not equal");
     $this->assertTrue($expected[3]->Equals($actual[3]), "Dates[3] are not equal");
 }
Example #13
0
 public function GetDates(DateRange $startingRange)
 {
     $dates = array();
     $begin = $startingRange->GetBegin();
     $end = $startingRange->GetEnd();
     $nextStartYear = $begin->Year();
     $nextEndYear = $end->Year();
     $timezone = $begin->Timezone();
     $startDate = $begin;
     while ($startDate->DateCompare($this->_terminationDate) <= 0) {
         $nextStartYear = $nextStartYear + $this->_interval;
         $nextEndYear = $nextEndYear + $this->_interval;
         $startDate = Date::Create($nextStartYear, $begin->Month(), $begin->Day(), $begin->Hour(), $begin->Minute(), $begin->Second(), $timezone);
         $endDate = Date::Create($nextEndYear, $end->Month(), $end->Day(), $end->Hour(), $end->Minute(), $end->Second(), $timezone);
         if ($startDate->DateCompare($this->_terminationDate) <= 0) {
             $dates[] = new DateRange($startDate->ToUtc(), $endDate->ToUtc());
         }
     }
     return $dates;
 }