本文整理汇总了PHP中MWTimestamp::offsetForUser方法的典型用法代码示例。如果您正苦于以下问题:PHP MWTimestamp::offsetForUser方法的具体用法?PHP MWTimestamp::offsetForUser怎么用?PHP MWTimestamp::offsetForUser使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MWTimestamp
的用法示例。
在下文中一共展示了MWTimestamp::offsetForUser方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getHumanTimestamp
/**
* Get the timestamp in a human-friendly relative format, e.g., "3 days ago".
*
* Determine the difference between the timestamp and the current time, and
* generate a readable timestamp by returning "<N> <units> ago", where the
* largest possible unit is used.
*
* @since 1.26 (Prior to 1.26 method existed but was not meant to be used directly)
*
* @param MWTimestamp $time
* @param MWTimestamp|null $relativeTo The base timestamp to compare to (defaults to now)
* @param User|null $user User the timestamp is being generated for (or null to use main context's user)
* @return string Formatted timestamp
*/
public function getHumanTimestamp(MWTimestamp $time, MWTimestamp $relativeTo = null, User $user = null)
{
if ($relativeTo === null) {
$relativeTo = new MWTimestamp();
}
if ($user === null) {
$user = RequestContext::getMain()->getUser();
}
// Adjust for the user's timezone.
$offsetThis = $time->offsetForUser($user);
$offsetRel = $relativeTo->offsetForUser($user);
$ts = '';
if (Hooks::run('GetHumanTimestamp', array(&$ts, $time, $relativeTo, $user, $this))) {
$ts = $this->getHumanTimestampInternal($time, $relativeTo, $user);
}
// Reset the timezone on the objects.
$time->timestamp->sub($offsetThis);
$relativeTo->timestamp->sub($offsetRel);
return $ts;
}
示例2: getUserLocalTime
/**
* Internal helper function for converting UTC timezone to a user's timezone
* @param $user User
* @param $ts string
* @param $format output format
*/
private static function getUserLocalTime($user, $ts, $format = TS_MW)
{
$timestamp = new MWTimestamp($ts);
$timestamp->offsetForUser($user);
return $timestamp->getTimestamp($format);
}