本文整理汇总了PHP中Period::getMonths方法的典型用法代码示例。如果您正苦于以下问题:PHP Period::getMonths方法的具体用法?PHP Period::getMonths怎么用?PHP Period::getMonths使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Period
的用法示例。
在下文中一共展示了Period::getMonths方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: format
public function format(Period $period)
{
// this method actually has a pretty bad smell on it.
// it does what it's supposed to, but at one point or another it should be
// refactored to use a combination of
// the strategy and chain of responsibility-pattern
// so the variants can be customized
if ($period->getYears() != 0) {
return $this->doFormat($this->lang, 'years', $period->getYears());
}
if ($period->getMonths() != 0) {
return $this->doFormat($this->lang, 'months', $period->getMonths());
}
if ($period->getDays() != 0) {
$amount = $period->getDays();
// if the amount of days is larger than 6 we'll want to
// express it in weeks instead
if ($amount > 6 || $amount < -6) {
$amount = intval($amount / 7);
return $this->doFormat($this->lang, 'weeks', $amount);
} else {
return $this->doFormat($this->lang, 'days', $amount);
}
}
if ($period->getHours() != 0) {
return $this->doFormat($this->lang, 'hours', $period->getHours());
}
if ($period->getMinutes() != 0) {
return $this->doFormat($this->lang, 'minutes', $period->getMinutes());
}
return $this->doFormat($this->lang, 'justNow', 0);
}