本文整理汇总了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;
}
示例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;
//.........这里部分代码省略.........