本文整理汇总了PHP中Date::Create方法的典型用法代码示例。如果您正苦于以下问题:PHP Date::Create方法的具体用法?PHP Date::Create怎么用?PHP Date::Create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Date
的用法示例。
在下文中一共展示了Date::Create方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: Create
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);
}
示例2: FromDate
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;
}
示例3: __construct
/**
* @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);
}
}
示例4: __construct
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);
}
}
示例5: GetDateOffsetFromToday
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();
}
示例6: testProvidedStartDateIsUsedIfSpecified
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);
}
示例7: Compare
/**
* 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());
}
示例8: SetTime
/**
* @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;
}
示例9: GetPeriod
/**
* @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;
}
示例10: GetFirstOfYear
/**
* @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());
}
示例11: GetFirstOfMonth
/**
* @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());
}
示例12: testDateRangeReturnsAllDatesForRangeWithoutTime
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");
}
示例13: GetDates
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;
}