コード例 #1
0
ファイル: Language.php プロジェクト: nanasess/mediawiki
 /**
  * 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
0
 /**
  * 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);
 }