timeago updating fuzzy timestamps (e.g. "4 minutes ago" or "about 1 day ago") from ISO 8601 formatted dates and times

  1. Requirements
  2. update history:
  3. Usage
  4. Resources

Timeago is a jQuery plugin that makes it easy to support automatically updating fuzzy timestamps (e.g. "4 minutes ago" or "about 1 day ago") from ISO 8601 formatted dates and times embedded in your HTML

this is the jquery timeago plugin wrapper class . it is useful for such as comment , may be it should go with commentsModule

Requirements

tested on yii 1.8 ; may works well with previous version .

update history:

  • update to a new version 0.11.3 (mainly enhance the locale message supporting ) and you can download here YiiTimeAgo on github , and any suggestions is welcome :)

Usage

download it , and extract it to protected/extensions dir , then in your view file use it as other standard CWidget class .

this widget just replace the text of specified element (abbr or time tag of html5);

...can use code blocks like the following...

<?php

$this->widget('ext.timeago.JTimeAgo', array(
    'selector' => ' .timeago',
   
));

?>

<abbr class="timeago" title="2008-07-17T09:24:17Z">July 17, 2008</abbr>

<abbr class="timeago" title="<?php echo  date(DATE_ISO8601,time());  ?>">will be replaced</abbr>


    <?php echo CHtml::openTag('abbr',array('class'=>'timeago',
                     'title'=>date(DATE_ISO8601,time()),
                    ));?>
        <?php // echo date(DATE_ISO8601,time()); ?>
   <?php echo CHtml::closeTag('label'); ?>

<time class="timeago" datetime="2008-07-17T09:24:17Z">July 17, 2008</time>

<time class="timeago" datetime="2011-07-17">July 17, 2008</time>
    <hr size="2px" />
    <div>
        <p><h3>test settings</h3></p>


        <?php
        $this->widget('ext.timeago.JTimeAgo', array(
            'selector' => ' .cnTime',
            'settings'=>array(
                'allowFuture'=>true,
                'strings'=>'js:{
  prefixAgo: null,
  prefixFromNow: "从现在开始",
  suffixAgo: "之前",
  suffixFromNow: null,
  seconds: "不到 1 分钟",
  minute: "大约 1 分钟",
  minutes: "%d 分钟",
  hour: "大约 1 小时",
  hours: "大约 %d 小时",
  day: "1 天",
  days: "%d 天",
  month: "大约 1 个月",
  months: "%d 月",
  year: "大约 1 年",
  years: "%d 年",
  numbers: []
}
                ',
            )
        ));

        ?>
        <abbr class="cnTime" title="2008-07-17T09:24:17Z">July 17, 2008</abbr>


    </div>

you can specify your language string as my second example showing ( i just use Chinese ) , refer here Locale override and find your own language config there .

Resources

...external resources for this extension...

21 0
29 followers
1 740 downloads
Yii Version: 1.1
License: MIT
Category: Date and Time
Developed by: yiqing95
Created on: Dec 26, 2011
Last updated: 12 years ago

Downloads

show all

Related Extensions