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


PHP Valid::dateTimeObject方法代码示例

本文整理汇总了PHP中Valid::dateTimeObject方法的典型用法代码示例。如果您正苦于以下问题:PHP Valid::dateTimeObject方法的具体用法?PHP Valid::dateTimeObject怎么用?PHP Valid::dateTimeObject使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Valid的用法示例。


在下文中一共展示了Valid::dateTimeObject方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: occursOn

 public function occursOn($date)
 {
     if (!Valid::dateTimeObject($date)) {
         throw new \InvalidArgumentException("occursOn: Accepts valid DateTime objects");
     }
     // breakdown the date
     $year = $date->format('Y');
     $month = $date->format('n');
     $day = $date->format('j');
     $dayFromEndOfMonth = -((int) $date->format('t') + 1 - (int) $day);
     $leapYear = (int) $date->format('L');
     $yearDay = $date->format('z') + 1;
     $yearDayNeg = -366 + (int) $yearDay;
     if ($leapYear) {
         $yearDayNeg = -367 + (int) $yearDay;
     }
     // this is the nth occurrence of the date
     $occur = ceil($day / 7);
     $occurNeg = -1 * ceil(abs($dayFromEndOfMonth) / 7);
     // starting on a monday
     $week = $date->format('W');
     $weekDay = strtolower($date->format('D'));
     $dayOfWeek = $date->format('l');
     $dayOfWeekAbr = strtolower(substr($dayOfWeek, 0, 2));
     // the date has to be greater then the start date
     if ($date < $this->startDate) {
         return false;
     }
     // if the there is an end date, make sure date is under
     if (isset($this->until)) {
         if ($date > $this->until) {
             return false;
         }
     }
     if (isset($this->bymonths)) {
         if (!in_array($month, $this->bymonths)) {
             return false;
         }
     }
     if (isset($this->bydays)) {
         if (!in_array(0 . $dayOfWeekAbr, $this->bydays) && !in_array($occur . $dayOfWeekAbr, $this->bydays) && !in_array($occurNeg . $dayOfWeekAbr, $this->bydays)) {
             return false;
         }
     }
     if (isset($this->byweeknos)) {
         if (!in_array($week, $this->byweeknos)) {
             return false;
         }
     }
     if (isset($this->bymonthdays)) {
         if (!in_array($day, $this->bymonthdays) && !in_array($dayFromEndOfMonth, $this->bymonthdays)) {
             return false;
         }
     }
     if (isset($this->byyeardays)) {
         if (!in_array($yearDay, $this->byyeardays) && !in_array($yearDayNeg, $this->byyeardays)) {
             return false;
         }
     }
     return true;
 }
开发者ID:solleer,项目名称:framework,代码行数:61,代码来源:When.php

示例2: occursOn

 public function occursOn($date)
 {
     if (!Valid::dateTimeObject($date)) {
         throw new \InvalidArgumentException("occursOn: Accepts valid DateTime objects");
     }
     // breakdown the date
     $year = $date->format('Y');
     $month = $date->format('n');
     $day = $date->format('j');
     $dayFromEndOfMonth = -((int) $date->format('t') + 1 - (int) $day);
     $leapYear = (int) $date->format('L');
     $yearDay = $date->format('z') + 1;
     $yearDayNeg = -366 + (int) $yearDay;
     if ($leapYear) {
         $yearDayNeg = -367 + (int) $yearDay;
     }
     // this is the nth occurrence of the date
     $occur = ceil($day / 7);
     $occurNeg = -1 * ceil(abs($dayFromEndOfMonth) / 7);
     // starting on a monday
     $week = $date->format('W');
     $weekDay = strtolower($date->format('D'));
     $dayOfWeek = $date->format('l');
     $dayOfWeekAbr = strtolower(substr($dayOfWeek, 0, 2));
     // the date has to be greater then the start date
     if ($date < $this->startDate) {
         return false;
     }
     // if the there is an end date, make sure date is under
     if (isset($this->until)) {
         if ($date > $this->until) {
             return false;
         }
     }
     if (isset($this->bymonths)) {
         if (!in_array($month, $this->bymonths)) {
             return false;
         }
     }
     if (isset($this->bydays)) {
         if (!in_array(0 . $dayOfWeekAbr, $this->bydays) && !in_array($occur . $dayOfWeekAbr, $this->bydays) && !in_array($occurNeg . $dayOfWeekAbr, $this->bydays)) {
             return false;
         }
     }
     if (isset($this->byweeknos)) {
         if (!in_array($week, $this->byweeknos)) {
             return false;
         }
     }
     if (isset($this->bymonthdays)) {
         if (!in_array($day, $this->bymonthdays) && !in_array($dayFromEndOfMonth, $this->bymonthdays)) {
             return false;
         }
     }
     if (isset($this->byyeardays)) {
         if (!in_array($yearDay, $this->byyeardays) && !in_array($yearDayNeg, $this->byyeardays)) {
             return false;
         }
     }
     // If there is an interval != 1, check whether this is an nth period.
     if ($this->interval > 1) {
         switch ($this->freq) {
             case 'yearly':
                 $start = new \DateTime($this->startDate->format("Y-1-1\\TH:i:sP"));
                 $sinceStart = $date->diff($start);
                 $numPeriods = $sinceStart->y;
                 break;
             case 'monthly':
                 $start = new \DateTime($this->startDate->format("Y-m-1\\TH:i:sP"));
                 $sinceStart = $date->diff($start);
                 $numYears = $sinceStart->y;
                 $numMonths = $sinceStart->m;
                 $numPeriods = $numYears * 12 + $numMonths;
                 break;
             case 'weekly':
                 if (isset($this->bydays)) {
                     $weekStartDate = self::getFirstWeekStartDate($this->startDate, $this->wkst);
                 } else {
                     $weekStartDate = $this->startDate;
                 }
                 $sinceStart = $date->diff($weekStartDate);
                 $numPeriods = floor($sinceStart->days / 7);
                 break;
             case 'daily':
                 $sinceStart = $date->diff($this->startDate);
                 // Note we "expanded" startDate already.
                 $numPeriods = $sinceStart->days;
                 break;
             case 'hourly':
                 $sinceStart = $date->diff($this->startDate);
                 // Note we "expanded" startDate already.
                 $numDays = $sinceStart->days;
                 $numHours = $sinceStart->h;
                 $numPeriods = 24 * $numDays + $numHours;
                 break;
             case 'minutely':
                 $sinceStart = $date->diff($this->startDate);
                 // Note we "expanded" startDate already.
                 $numDays = $sinceStart->days;
                 $numHours = $sinceStart->h;
//.........这里部分代码省略.........
开发者ID:tplaner,项目名称:when,代码行数:101,代码来源:When.php


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