inWords() public method

public inWords ( $past, $time_language, $now = "now" )
Beispiel #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;
}
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);
}
 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;
 }
function timeAgoInWords($timestring, $timezone = NULL, $language = 'en')
{
    $timeAgo = new TimeAgo($timezone, $language);
    return $timeAgo->inWords($timestring, "now");
}
Beispiel #5
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?...
 }
function timeAgoInWords($timestring, $timezone = NULL)
{
    $timeAgo = new TimeAgo($timezone);
    return $timeAgo->inWords($timestring, "now");
}
							<?php
							if (isset($this->item->fields['rating']) && $this->commentObj->parent_id == $this->root_comment->id)
							{
								echo $this->item->fields['rating']->getOutput(array("view" => "details", "template" => $this->template, "type" => "comment", "comment_object" => $this->commentObj));
							}
							?>
						</div>
						<!-- /.comment-user -->

						<div class="comment-text">
							<h4 class="comment-title" itemprop="name"><?php echo $this->commentObj->title; ?></h4>

							<div class="comment-metadata clearfix">
								<div itemprop="datePublished" class="comment-created">
									<i class="fa fa-calendar"></i>
									<?php echo JText::_('COM_JUDOWNLOAD_POST_ON') . ": " . $timeAgo->inWords(JHtml::_('date', $this->commentObj->created, 'Y-m-d H:i:s')); ?>
								</div>

								<?php if ($this->commentObj->website != '')
								{
									?>
									<div class="comment-website">
										<?php
										echo JText::_('COM_JUDOWNLOAD_COMMENT_WEBSITE') . ": " . $this->commentObj->website;
										?>
									</div>
								<?php
								} ?>
								<!-- /.comment-rating -->
							</div>
							<!-- /.comment-metadata -->
Beispiel #8
0
function mediaphase_time_ago_in_words($timestring, $timezone = null)
{
    $time_ago = new TimeAgo($timezone);
    return $time_ago->inWords($timestring, "now");
}
        }
        ?>
						</div>
						<!-- /.comment-user -->

						<div class="comment-text">
							<h4 class="comment-title" itemprop="name"><?php 
        echo $this->commentObj->title;
        ?>
</h4>

							<div class="comment-metadata clearfix">
								<div itemprop="datePublished" class="comment-created">
									<i class="fa fa-calendar"></i>
									<?php 
        echo JText::_('COM_JUDIRECTORY_POST_ON') . ": " . $timeAgo->inWords(JHtml::_('date', $this->commentObj->created, 'Y-m-d H:i:s'));
        ?>
								</div>

								<?php 
        if ($this->commentObj->website != '') {
            ?>
									<div class="comment-website">
										<?php 
            echo JText::_('COM_JUDIRECTORY_COMMENT_WEBSITE') . ": " . $this->commentObj->website;
            ?>
									</div>
								<?php 
        }
        ?>
								<!-- /.comment-rating -->
 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();
     });
 }
						<?php
						if ($commentObj->parent_id == $this->root_comment->id)
						{
							$fieldRating = JUDownloadFrontHelperField::getField('rating', $commentObj->doc_id);
							echo $fieldRating->getOutput(array('view' => 'details', 'template' => $this->template, 'type' => 'comment', 'comment_object' => $commentObj));
						}
						?>
					</div>

					<div class="comment-text">
						<h4 class="comment-title" itemprop="name"><?php echo $commentObj->title; ?></h4>

						<div class="comment-metadata clearfix">
							<div class="comment-created" itemprop="datePublished">
								<i class="fa fa-calendar"></i> <?php echo JText::_('COM_JUDOWNLOAD_POST_ON') . ': ' . $timeAgo->inWords(JHtml::_('date', $commentObj->created, 'Y-m-d H:i:s')); ?>
							</div>
						</div>
						<?php
						$commentObj->comment = JUDownloadFrontHelper::BBCode2Html($commentObj->comment);
						$commentObj->comment = JUDownloadFrontHelperComment::parseCommentText($commentObj->comment, $commentObj->doc_id);
						?>
						<div class="comment-content" itemprop="description">
							<?php echo $commentObj->comment; ?>
						</div>
					</div>
				</div>
			</div>
		</li>
	<?php
	} ?>
Beispiel #12
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;
echo "<br/>";
$timeAgo = new TimeAgo();
echo $timeAgo->inWords("2009/01/01 00:00:00", "2010/5/01 00:00:00");
echo "<br/>";
$timeAgo = new TimeAgo();
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);
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>";
 /**
 * @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;
 }
Beispiel #16
0
 public function dateAgo($date)
 {
     $timeAgo = new TimeAgo();
     return $timeAgo->inWords(date("r", $date));
 }