当前位置: 首页>>代码示例>>PHP>>正文


PHP DateRange::create方法代码示例

本文整理汇总了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;
 }
开发者ID:onphp-framework,项目名称:onphp-framework,代码行数:27,代码来源:CalendarMonthWeekly.class.php

示例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'))));
 }
开发者ID:onphp-framework,项目名称:onphp-framework,代码行数:5,代码来源:DateRangeTest.class.php

示例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;
 }
开发者ID:onphp-framework,项目名称:onphp-framework,代码行数:20,代码来源:DateRange.class.php

示例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}'");
 }
开发者ID:onphp-framework,项目名称:onphp-framework,代码行数:26,代码来源:DateRangeList.class.php


注:本文中的DateRange::create方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。