本文整理汇总了PHP中DateRange::create方法的典型用法代码示例。如果您正苦于以下问题:PHP DateRange::create方法的具体用法?PHP DateRange::create怎么用?PHP DateRange::create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DateRange
的用法示例。
在下文中一共展示了DateRange::create方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
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;
}
示例2: testOverlaps
public function testOverlaps()
{
$this->assertTrue(DateRange::create()->lazySet(Date::create('2007-03-28'), Date::create('2008-03-27'))->overlaps(DateRange::create()->lazySet(Date::create('2007-05-14'), Date::create('2008-03-29'))));
$this->assertFalse(DateRange::create()->lazySet(Date::create('2007-03-28'), Date::create('2008-03-27'))->overlaps(DateRange::create()->lazySet(Date::create('2005-05-14'), Date::create('2006-03-29'))));
}
示例3: lightCopyOnClip
/**
* result is read-only, no error checking
*
* @return DateRange
**/
public function lightCopyOnClip(DateRange $range)
{
$copy = DateRange::create();
if ($range->start && ($this->start && $range->start->toStamp() > $this->start->toStamp() || !$this->start)) {
$copy->start = $range->start;
} else {
$copy->start = $this->start;
}
if ($range->end && ($this->end && $range->end->toStamp() < $this->end->toStamp() || !$this->end)) {
$copy->end = $range->end;
} else {
$copy->end = $this->end;
}
return $copy;
}
示例4: makeRange
/**
* @throws WrongArgumentException
* @return DateRange
**/
public static function makeRange($string)
{
if (substr_count($string, ' - ') === 1 || substr_count($string, '-') === 1) {
$delimiter = ' - ';
if (substr_count($string, '-') === 1) {
$delimiter = '-';
}
list($start, $finish) = explode($delimiter, $string, 2);
$start = self::toDate(trim($start));
$finish = self::toDate(trim($finish));
if ($start || $finish) {
$range = new DateRange();
$range = DateRange::create()->lazySet($start, $finish);
return $range;
} elseif (trim($string) == '-') {
return DateRange::create();
}
} elseif ($single = self::toDate(trim($string))) {
return DateRange::create()->setStart($single)->setEnd($single);
}
throw new WrongArgumentException("unknown string format '{$string}'");
}