本文整理匯總了PHP中Tinebase_DateTime::subDay方法的典型用法代碼示例。如果您正苦於以下問題:PHP Tinebase_DateTime::subDay方法的具體用法?PHP Tinebase_DateTime::subDay怎麽用?PHP Tinebase_DateTime::subDay使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Tinebase_DateTime
的用法示例。
在下文中一共展示了Tinebase_DateTime::subDay方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: skipWday
/**
* skips date to (n'th next/previous) occurance of $_wday
*
* @param Tinebase_DateTime $_date
* @param int|string $_wday
* @param int $_n
* @param bool $_considerDateItself
*/
public static function skipWday($_date, $_wday, $_n = +1, $_considerDateItself = FALSE)
{
$wdayDigit = is_int($_wday) ? $_wday : self::$WEEKDAY_DIGIT_MAP[$_wday];
$wdayOffset = $_date->get('w') - $wdayDigit;
if ($_n == 0) {
throw new Exception('$_n must not be 0');
}
$direction = $_n > 0 ? 'forward' : 'backward';
$weeks = abs($_n);
if ($_considerDateItself && $wdayOffset == 0) {
$weeks--;
}
switch ($direction) {
case 'forward':
if ($wdayOffset >= 0) {
$_date->addDay($weeks * 7 - $wdayOffset);
} else {
$_date->addDay(abs($wdayOffset) + ($weeks - 1) * 7);
}
break;
case 'backward':
if ($wdayOffset > 0) {
$_date->subDay(abs($wdayOffset) + ($weeks - 1) * 7);
} else {
$_date->subDay($weeks * 7 + $wdayOffset);
}
break;
}
return $_date;
}