本文整理匯總了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;
//.........這裏部分代碼省略.........