It has two functions you can call: inWords() which gives you the "time ago in words" between two dates. dateDifference() which returns an array of years,months,days,hours,minutes and seconds between the two dates.
Since: 0.2.0 (2010/05/05)
Author: jimmiw
Ejemplo n.º 1
0
/**
 * Theme related functions. 
 *
 */
function getTimeAgo($timestamp)
{
    $date = date("Y-m-d H:i:s", $timestamp);
    $timeAgo = new TimeAgo();
    $time = $timeAgo->inWords($date);
    return $time;
}
 private function build_success_headers($modified)
 {
     $cache_time = 3600;
     $modified = gmdate('D, d M Y H:i:s', strtotime($modified)) . ' GMT';
     $etag = '"' . md5($modified) . '"';
     $headers['Cache-Control'] = "max-age: {$cache_time}";
     $headers['Expires'] = gmdate('D, d M Y H:i:s', time() + $cache_time) . ' GMT';
     $headers['Last-Modified'] = $modified;
     $headers['Etag'] = $etag;
     $time_go = new \TimeAgo();
     $post_time = gmdate("Y\\/n\\/j\\ H:i:s", strtotime($modified));
     $last_update = $time_go->inWords($post_time);
     $headers['X-pugpig-LM-Ago'] = $last_update;
     return $headers;
 }
Ejemplo n.º 3
0
 /**
  * Generates html block with question info.
  *
  * @todo also get count and N first
  * followers
  * Followers to be selected from USERS collection
  * using find() by a_f_q and using limit 5
  * and then link to 'show more' if i_flwrs in Question is > 5
  *
  *
  * @param Question $Question
  * @return string
  */
 public function getHtml(Question $Question)
 {
     $this->Question = $Question;
     $tagsBlock = \tplBoxrecent::parse(array('title' => '@@Question tags@@', 'id' => 'question_tags', $this->getTags()), false);
     $ret = \tplQuestionInfo::parse(array('tags' => $tagsBlock, 'asked' => TimeAgo::format(new \DateTime(str_replace(' AEST', ' UTC+10', $Question['hts']))) . ' ago', 'updated' => TimeAgo::format(new \DateTime(date('r', $Question['i_lm_ts']))) . ' ago', 'views' => $this->Question['i_views'], 'ans_count' => $this->Question->getAnswerCount(), 'asked_label' => '@@Asked@@', 'updated_label' => '@@Last updated@@', 'ans_count_label' => '@@Number of Answers@@', 'views_label' => '@@Number of Views@@'));
     return $ret;
 }
function add_apple_news_status_column($post_type)
{
    \Jigsaw::add_column($post_type, 'Apple News Status', function ($pid) {
        $apple_id = get_post_meta($pid, 'apple_news_api_id');
        if ($apple_id) {
            $last_modified = get_post_meta($pid, 'apple_news_api_modified_at')[0];
            $post_created = get_post_meta($pid, 'apple_news_api_created_at')[0];
            $time_ago = new \TimeAgo();
            $last_update = $time_ago->inWords($last_modified);
            $created = $time_ago->inWords($post_created);
            echo "<strong>Status:</strong></br>";
            echo "<span style='color:green;'>Synced</span></br>";
            echo "<hr>";
            echo "<strong>Created:</strong></br>";
            echo "<span title='{$post_created}'> {$created}</span></br>";
            echo "<hr>";
            echo "<strong>Last Modified:</strong></br>";
            echo "<span title='{$last_modified}'>{$last_update}</span></br>";
        } else {
            echo "<span>Not synced</span>";
        }
    }, 5);
}
 /**
  * Generates html block with question info.
  *
  * @todo also get count and N first
  * followers
  * Followers to be selected from USERS collection
  * using find() by a_f_q and using limit 5
  * and then link to 'show more' if i_flwrs in Question is > 5
  *
  *
  * @param Question $Question
  */
 public function getHtml(Question $Question)
 {
     $this->Question = $Question;
     $Tr = $this->Registry->Tr;
     /**
      * @todo translate Title string
      */
     $tagsBlock = \tplBoxrecent::parse(array('title' => $Tr['Topic tags'], 'id' => 'question_tags', $this->getTags()), false);
     /**
      * @todo translate labels used
      * in tplQuestionsInfo template
      *
      */
     $ret = \tplQuestionInfo::parse(array('tags' => $tagsBlock, 'asked' => TimeAgo::format(new \DateTime($Question['hts'])) . ' ago', 'updated' => TimeAgo::format(new \DateTime(date('r', $Question['i_lm_ts']))) . ' ago', 'views' => $this->Question['i_views'], 'ans_count' => $this->Question->getAnswerCount(), 'asked_label' => $Tr['Posted'], 'updated_label' => $Tr['Last updated'], 'ans_count_label' => $Tr['Number of posts'], 'views_label' => $Tr['Number of Views']));
     d('$ret: ' . $ret);
     return $ret;
 }
 * JUDownload for Joomla 2.5, 3.x
 * ------------------------------------------------------------------------
 *
 * @copyright      Copyright (C) 2010-2015 JoomUltra Co., Ltd. All Rights Reserved.
 * @license        GNU General Public License version 2 or later; see LICENSE.txt
 * @author         JoomUltra Co., Ltd
 * @website        http://www.joomultra.com
 * @----------------------------------------------------------------------@
 */

// No direct access to this file
defined('_JEXEC') or die('Restricted access');

require_once JPATH_SITE . '/components/com_judownload/helpers/avatar.php';
require_once JPATH_SITE . '/components/com_judownload/helpers/timeago.php';
$timeAgo = new TimeAgo();
$parent_id = $this->item->comment->parent_id;
?>
<ul class="comment-list clearfix">
	<?php
	foreach ($this->item->comment->items AS $this->commentObj)
	{
		if ($this->commentObj->parent_id == $parent_id)
		{
			?>
			<li class="comment-item <?php echo ($this->commentObj->published == 1) ? 'published' : 'unpublished'; ?> level-<?php echo $this->commentObj->level; ?>"
			    id="comment-item-<?php echo $this->commentObj->id; ?>">
				<div itemscope="" itemtype="http://schema.org/Review">
					<div id="<?php echo "comment-box-".$this->commentObj->id; ?>" class="comment-box clearfix">
						<div class="comment-user">
							<?php
Ejemplo n.º 7
0
function timeAgoInWords($timestring, $timezone = NULL)
{
    $timeAgo = new TimeAgo($timezone);
    return $timeAgo->inWords($timestring, "now");
}
Ejemplo n.º 8
0
 public function dateAgo($date)
 {
     $timeAgo = new TimeAgo();
     return $timeAgo->inWords(date("r", $date));
 }
Ejemplo n.º 9
0
function mediaphase_time_ago_in_words($timestring, $timezone = null)
{
    $time_ago = new TimeAgo($timezone);
    return $time_ago->inWords($timestring, "now");
}
 function add_status()
 {
     \Jigsaw::add_column('pugpig_edition', 'Status', function ($pid) {
         $edition = new \TimberPost($pid);
         $post_status = get_post_status($pid);
         if ($post_status === 'publish') {
             $post_status = '<em>published</em>';
         } else {
             $post_status = "<strong>{$post_status}</strong>";
         }
         $custom = get_post_custom($pid);
         $page_count = false;
         if ($edition->flatplan) {
             $page_count = count($edition->flatplan);
         }
         $timeAgo = new \TimeAgo();
         $post_time = get_post_modified_time('G', true, $pid);
         $post_time = date("Y\\/n\\/j\\ H:i:s", $post_time);
         $last_update = $timeAgo->inWords($post_time);
         echo view('@AgreablePugpigPlugin/status-column.twig', array('post_status' => $post_status, 'custom' => $page_count ? $page_count : 0, 'last_updated' => $last_update))->getBody();
     });
 }
/**
 * ------------------------------------------------------------------------
 * JUDirectory for Joomla 2.5, 3.x
 * ------------------------------------------------------------------------
 *
 * @copyright      Copyright (C) 2010-2015 JoomUltra Co., Ltd. All Rights Reserved.
 * @license        GNU General Public License version 2 or later; see LICENSE.txt
 * @author         JoomUltra Co., Ltd
 * @website        http://www.joomultra.com
 * @----------------------------------------------------------------------@
 */
// No direct access to this file
defined('_JEXEC') or die('Restricted access');
require_once JPATH_SITE . '/components/com_judirectory/helpers/avatar.php';
require_once JPATH_SITE . '/components/com_judirectory/helpers/timeago.php';
$timeAgo = new TimeAgo();
$parent_id = $this->item->comment->parent_id;
?>
<ul class="comment-list clearfix">
	<?php 
foreach ($this->item->comment->items as $this->commentObj) {
    if ($this->commentObj->parent_id == $parent_id) {
        ?>
			<li class="comment-item <?php 
        echo $this->commentObj->published == 1 ? 'published' : 'unpublished';
        ?>
 level-<?php 
        echo $this->commentObj->level;
        ?>
"
			    id="comment-item-<?php 
 /**
 * @param string $path
 * @return array
 *      Get all directories / files ("items") of given path (path could be dir or file).
 * An item follows this format:
 * array(
 * 'type' => ['dir' or 'file' or 'entry'],
 * 'name' => ['admin' or '_adminLang.json' or 'title'],
 * 'value' => [only give a value when type is 'entry'],
 * 'path' => [path to dir or file, entry does not need this],
 * 'UpdatedAt' => [updated at in timestamp]
 * )
     path is 'stuff/morestuff' for dir, or '[language]/stuff/morestuff/file.json' for file.
 */
 public function getItems($path)
 {
     $path = $this->sanitizePath($path);
     $items = array();
     // If path is dir, glob it.
     if (is_dir($this->getCompletePath($path))) {
         $filepaths = glob($this->getCompletePath($path) . DIRECTORY_SEPARATOR . '*');
         $timeAgo = new \TimeAgo($this->getConfig('timezone'));
         $dirs = [];
         $files = [];
         foreach ($filepaths as $filepath) {
             $timestring = date('Y/m/d h:m:i', filemtime($filepath));
             $timeAgoString = $timeAgo->inWords($timestring, "now");
             $name = substr($filepath, strrpos($filepath, DIRECTORY_SEPARATOR) + 1);
             if (is_dir($filepath)) {
                 $dirs[] = array('type' => 'dir', 'name' => $name, 'path' => $path . DIRECTORY_SEPARATOR . $name, 'updatedAt' => $timeAgoString . ' ago');
             } elseif (is_file($filepath)) {
                 $files[] = array('type' => 'file', 'name' => $name, 'path' => $path . DIRECTORY_SEPARATOR . $name, 'updatedAt' => $timeAgoString . ' ago');
             }
         }
         $items = array_merge($dirs, $files);
     } else {
         if (is_file($this->getCompletePath($path))) {
             $entries = $this->readFile($this->getCompletePath($path));
             ksort($entries);
             foreach ($entries as $key => $value) {
                 $items[] = array('type' => 'entry', 'name' => $key, 'value' => $value, 'path' => $path);
             }
         }
     }
     return $items;
 }
Ejemplo n.º 13
0
 * JUDownload for Joomla 2.5, 3.x
 * ------------------------------------------------------------------------
 *
 * @copyright      Copyright (C) 2010-2015 JoomUltra Co., Ltd. All Rights Reserved.
 * @license        GNU General Public License version 2 or later; see LICENSE.txt
 * @author         JoomUltra Co., Ltd
 * @website        http://www.joomultra.com
 * @----------------------------------------------------------------------@
 */

// No direct access to this file
defined('_JEXEC') or die('Restricted access');
?>
<ul class="comment-list">
	<?php
	$timeAgo = new TimeAgo();
	$avatar = new JUDownloadAvatarHelper ();

	foreach ($this->items AS $commentObj)
	{
		$userAvatar = $avatar->getAvatar(JFactory::getUser($commentObj->user_id), $this->params);
		?>
		<li class="comment-item level-<?php echo $commentObj->level; ?>"
		    id="comment-item-<?php echo $commentObj->id; ?>">
			<div itemscope="" itemtype="http://schema.org/Review">
				<div class="comment-box clearfix">
					<div class="comment-user">
						<img class="comment-avatar" itemprop="image" src="<?php echo $userAvatar; ?>" alt="Avatar"
							 style="max-width: <?php echo $this->params->get("avatar_width", 120); ?>px;max-height: <?php echo $this->params->get("avatar_height", 120); ?>px;"/>

						<h3 class="comment-username" itemprop="creator" itemscope=""
Ejemplo n.º 14
0
 /**
  * Tests the old core functionality, by being in the same timezone and not changing language.
  */
 public function testTimeAgoInWords()
 {
     $timeAgo = new TimeAgo();
     // testing "less than a minute"
     $this->assertEquals('less than a minute ago', $timeAgo->inWords("now"));
     $this->assertEquals('less than a minute ago', $timeAgo->inWords("-1 second"));
     $this->assertEquals('less than a minute ago', $timeAgo->inWords("-29 second"));
     $this->assertNotEquals('less than a minute ago', $timeAgo->inWords("-30 second"));
     // testing "1 minute"
     $this->assertEquals('1 minute ago', $timeAgo->inWords("-30 second"));
     $this->assertEquals('1 minute ago', $timeAgo->inWords("-60 second"));
     $this->assertEquals('1 minute ago', $timeAgo->inWords("-89 second"));
     $this->assertNotEquals('1 minute ago', $timeAgo->inWords("-90 second"));
     // testing 2..44 minutes
     $this->assertContains('minutes ago', $timeAgo->inWords("-2 minute"));
     $this->assertContains('minutes ago', $timeAgo->inWords("-44 minute"));
     $this->assertContains('minutes ago', $timeAgo->inWords("-44 minute -29 second"));
     $this->assertNotContains('minutes ago', $timeAgo->inWords("-44 minute -30 second"));
     // testing about 1 hour
     $this->assertEquals('about 1 hour ago', $timeAgo->inWords("-44 minute -30 second"));
     $this->assertEquals('about 1 hour ago', $timeAgo->inWords("-89 minute -29 second"));
     $this->assertNotEquals('about 1 hour ago', $timeAgo->inWords("-90 minute"));
     // testing about 2..24 hours
     $this->assertContains('hours ago', $timeAgo->inWords("-90 minute"));
     $this->assertContains('hours ago', $timeAgo->inWords("-23 hour -59 minute -29 second"));
     $this->assertNotContains('hours ago', $timeAgo->inWords("-23 hour -59 minute -30 second"));
     $this->assertNotContains('hours ago', $timeAgo->inWords("-24 hour"));
     // testing 1 day
     $this->assertEquals('1 day ago', $timeAgo->inWords("-23 hour -59 minute -30 second"));
     $this->assertEquals('1 day ago', $timeAgo->inWords("-47 hour -59 minute -29 second"));
     $this->assertNotEquals('1 day ago', $timeAgo->inWords("-47 hour -59 minute -30 second"));
     // testing 2..24 days
     $this->assertContains('days ago', $timeAgo->inWords("-47 hour -59 minute -30 second"));
     $this->assertContains('days ago', $timeAgo->inWords("-29 day -23 hour -59 minute -29 second"));
     $this->assertNotContains('days ago', $timeAgo->inWords("-29 day -23 hour -59 minute -30 second"));
     // testing 1 month
     $this->assertEquals('about 1 month ago', $timeAgo->inWords("-29 day -23 hour -59 minute -30 second"));
     $this->assertEquals('about 1 month ago', $timeAgo->inWords("-59 day -23 hour -59 minute -29 second"));
     $this->assertNotEquals('about 1 month ago', $timeAgo->inWords("-59 day -23 hour -59 minute -30 second"));
     // testing 2..12 months
     $this->assertContains('months ago', $timeAgo->inWords("-59 day -23 hour -59 minute -30 second"));
     // seemed to be the easiest way to get 1 year - 1 second, which should be the day before 1 year ago :)
     $oneYearAgo = strtotime("-1 year");
     // NOTE: this fails around leap years... so... -2 days must be accurate enough
     $twoDays = 2 * 86400;
     // 2 days in seconds
     $this->assertContains('months ago', $timeAgo->inWords(date('c', $oneYearAgo + $twoDays)));
     $this->assertNotContains('months ago', $timeAgo->inWords($oneYearAgo));
     // testing 1 year
     $this->assertContains('1 year ago', $timeAgo->inWords(date('c', $oneYearAgo - $twoDays)));
     $twoYearsAgo = strtotime("-2 year");
     $this->assertContains('1 year ago', $timeAgo->inWords(date('c', $twoYearsAgo + $twoDays)));
     $this->assertNotContains('1 year ago', $timeAgo->inWords($twoYearsAgo));
     // testing 2 years or more
     $this->assertEquals('over 2 years ago', $timeAgo->inWords("-2 year"));
     $this->assertEquals('over 2 years ago', $timeAgo->inWords("-2 year - 59 day"));
     $this->assertEquals('over 3 years ago', $timeAgo->inWords("-3 year"));
     $this->assertEquals('over 4 years ago', $timeAgo->inWords("-4 year"));
     $this->assertEquals('over 5 years ago', $timeAgo->inWords("-5 year"));
     $this->assertEquals('over 6 years ago', $timeAgo->inWords("-6 year"));
     $this->assertEquals('over 7 years ago', $timeAgo->inWords("-7 year"));
     $this->assertEquals('over 8 years ago', $timeAgo->inWords("-8 year"));
     $this->assertEquals('over 9 years ago', $timeAgo->inWords("-9 year"));
     $this->assertEquals('over 10 years ago', $timeAgo->inWords("-10 year"));
     // you get the point right?...
 }
Ejemplo n.º 15
0
 public function getHtml()
 {
     $edit = '';
     $lastActive = $this->User['i_lm_ts'];
     $lastActive = !empty($lastActive) ? $lastActive : $this->User['i_reg_ts'];
     $pp = $this->User->getProfitPoint();
     d('pp: ' . $pp);
     $uid = $this->User->getUid();
     $isSameUser = $this->Registry->Viewer->getUid() === $uid;
     if ($isSameUser || $this->Registry->Viewer->isModerator()) {
         $edit = '<div class="fl middle"><span class="icoc key">&nbsp;</span><a href="/editprofile/' . $uid . '" class="edit middle">Edit profile</a></div>';
     }
     $desc = \trim($this->User['description']);
     $desc = empty($desc) ? '' : Utf8String::factory($desc, 'utf-8', true)->linkify()->valueOf();
     $vars = array('editLink' => $edit, 'username' => $this->User->username, 'avatar' => $this->User->getAvatarImgSrc(), 'profitpoint' => $pp, 'name' => $this->User->getDisplayName(), 'genderLabel' => 'Gender', 'gender' => $this->getGender(), 'since' => date('F j, Y', $this->User->i_reg_ts), 'lastActivity' => TimeAgo::format(new \DateTime(date('r', $lastActive))), 'website' => $this->User->getUrl(), 'twitter' => '<div id="my_tw">' . $this->getTwitterAccount($isSameUser) . '</div>', 'age' => $this->User->getAge(), 'facebook' => '<div id="my_fb">' . $this->getFacebookAccount($isSameUser) . '</div>', 'tumblr' => '<div id="my_tm">' . $this->getTumblrAccount($isSameUser) . '</div>', 'blogger' => '<div id="my_bg">' . $this->getBloggerAccount($isSameUser) . '</div>', 'linkedin' => '<div id="my_li">' . $this->getLinkedInAccount($isSameUser) . '</div>', 'location' => $this->User->getLocation(), 'description' => \wordwrap($desc, 50), 'editRole' => Usertools::getHtml($this->Registry, $this->User), 'followButton' => $this->makeFollowButton(), 'followers' => ShowFollowers::factory($this->Registry)->getUserFollowers($this->User), 'following' => ShowFollowers::factory($this->Registry)->getUserFollowing($this->User));
     return \tplUserInfo::parse($vars);
 }
Ejemplo n.º 16
0
echo $this->post->title ?: preg_replace('/^https?:\\/\\//', '', $this->post->href);
?>
</a></div>
    <div class="details">
      <span class="p-author h-card"><a href="<?php 
echo $this->post->post_author;
?>
" class="u-url"><?php 
echo friendly_url($this->post->post_author);
?>
</a></span> | 
      <?php 
echo $this->post->post_date ? '<time class="dt-published" datetime="' . date('c', strtotime($this->post->post_date)) . '">' . date('Y-m-d H:i T', strtotime($this->post->post_date)) . '</time> |' : '';
?>
      submitted <?php 
echo TimeAgo::inWords($this->post->date_submitted);
?>
 
      <?php 
echo $this->post->source_url != $this->post->href ? ' from <a href="' . $this->post->source_url . '">' . parse_url($this->post->source_url, PHP_URL_HOST) . '</a>' : '';
?>
 | 
      <a href="/post/<?php 
echo preg_replace('/^https?:\\/\\//', '', $this->post->href);
?>
">permalink</a>
      <?php 
if ($this->post->in_reply_to) {
    ?>
        | <a href="<?php 
    echo $this->post->in_reply_to;
Ejemplo n.º 17
0
echo $timeAgo->inWords("2010/4/26 00:00:00", "2011/4/26 23:59:59");
echo "<br/>";
echo "<br/><strong>rule 11</strong> (2 yrs <-> max time or date # => over [2..X] years)<br/>";
$timeAgo = new TimeAgo();
echo $timeAgo->inWords("2009/4/26 00:00:00", "2011/4/26 00:00:00");
echo "<br/>";
$timeAgo = new TimeAgo();
echo $timeAgo->inWords("2005/4/26 00:00:00", "2011/4/26 00:00:00");
echo "<br/>";
$timeAgo = new TimeAgo();
echo $timeAgo->inWords("1999/4/26 00:00:00", "2011/4/26 00:00:00");
echo "<br/>";
echo "</p>";
echo "<h2>TimeAgo class tests (dateDifference)</h2>";
echo "<p>";
$timeAgo = new TimeAgo();
echo "<pre>";
print_r($timeAgo->dateDifference("2010/4/01 00:00:00", "2010/5/12 03:05:30"));
echo "</pre>";
echo "</p>";
echo "<h1>WWDateTime class tests!</h1>";
function test_time($timeAgo, $timeAsItShouldBe)
{
    echo "<p>";
    $datetime = new WWDateTime($timeAgo);
    echo $datetime->format(DATE_RFC3339);
    echo " = ";
    echo $datetime->timeAgoInWords();
    echo " === ";
    echo $timeAsItShouldBe;
    echo "</p>";
Ejemplo n.º 18
0
test_time("-1 day", "1 day");
timeAgoInWords("-1 day");
test_time("-2 day", "2 days");
timeAgoInWords("-2 day");
test_time("-1 hour", "about 1 hour");
timeAgoInWords("-1 hour");
test_time("-2 hour", "about 2 hours");
timeAgoInWords("-2 hour");
test_time("-1 minute", "about 1 minute");
timeAgoInWords("-1 minute");
test_time("-2 minute", "about 2 minutes");
timeAgoInWords("-2 minute");
test_time("-44 minute", "about 44 minutes");
timeAgoInWords("-44 minute");
test_time("-45 minute", "about 1 hour");
timeAgoInWords("-45 minute");
test_time("-1 second", "less than a minute");
timeAgoInWords("-1 second");
test_time("-31 second", "1 minute");
timeAgoInWords("-31 second");
echo "<h2>Language testing</h2>";
echo "<p>";
echo "<br/><strong>English</strong><br/>";
$timeAgo = new TimeAgo();
echo $timeAgo->inWords("2015/5/26 10:00:10", "2015/5/26 10:00:20");
echo "<br/>";
echo "<br/><strong>Danish</strong><br/>";
$timeAgo = new TimeAgo(NULL, 'da');
echo $timeAgo->inWords("2015/5/26 10:00:10", "2015/5/26 10:00:20");
echo "<br/>";
echo "</p>";
Ejemplo n.º 19
0
 /**
  * Loads the translations into the system.
  */
 private static function _loadTranslations($language)
 {
     // no time strings loaded? load them and store it all in static variables
     if (self::$timeAgoStrings == NULL || self::$language != $language) {
         include __DIR__ . '/translations/' . $language . '.php';
         // storing the time strings in the current object
         self::$timeAgoStrings = $timeAgoStrings;
         // loads the language files
         if (self::$timeAgoStrings == NULL) {
             error_log('Could not load language file for language ' . $language . '. Please ensure that the file exists in ' . __DIR__ . 'translations/' . $language . '.php');
         }
     }
     // storing the language
     self::$language = $language;
 }
Ejemplo n.º 20
0
function timeAgoInWords($timestring, $timezone = NULL, $language = 'en')
{
    $timeAgo = new TimeAgo($timezone, $language);
    return $timeAgo->inWords($timestring, "now");
}