本文整理汇总了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;
}