本文整理汇总了PHP中DateTimeValue::isYesterday方法的典型用法代码示例。如果您正苦于以下问题:PHP DateTimeValue::isYesterday方法的具体用法?PHP DateTimeValue::isYesterday怎么用?PHP DateTimeValue::isYesterday使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DateTimeValue
的用法示例。
在下文中一共展示了DateTimeValue::isYesterday方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: friendly_date
function friendly_date(DateTimeValue $date, $timezone = null)
{
if ($timezone == null) {
$timezone = logged_user()->getTimezone();
}
//TODO: 7 days before: "Dom at 13:43", older: "Oct, 06 at 15:20"
$dateControl = new DateTimeValue($date->getTimestamp() + $timezone * 3600);
if ($date->isToday()) {
$now = DateTimeValueLib::now();
$diff = DateTimeValueLib::get_time_difference($date->getTimestamp(), $now->getTimestamp());
if ($diff['hours'] == 0) {
if ($diff['minutes'] >= 0) {
return lang('minutes ago', $diff['minutes']);
} else {
return format_descriptive_date($date);
}
} else {
if ($diff['hours'] > 0) {
return lang('about hours ago', round($diff['hours'] + ($diff['minutes'] > 30 ? 1 : 0)));
} else {
return format_descriptive_date($date);
}
}
} else {
if ($dateControl->isYesterday()) {
return lang('yesterday at', format_time($date));
} else {
$now = DateTimeValueLib::now();
$diff = DateTimeValueLib::get_time_difference($date->getTimestamp(), $now->getTimestamp());
if ($diff['days'] < 7) {
return lang('day at', Localization::dateByLocalization("D", $dateControl->getTimestamp()), format_time($date));
} else {
if ($now->getYear() != $date->getYear()) {
return lang('day at', Localization::dateByLocalization("M d, Y", $dateControl->getTimestamp()), format_time($date));
} else {
return lang('day at', Localization::dateByLocalization("M, d", $dateControl->getTimestamp()), format_time($date));
}
}
}
}
}