We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

Plugin: Time Since 2

Development and Programming

anonymous60114's avatar
anonymous60114
11 posts
16 years ago
anonymous60114's avatar anonymous60114

Time Since 2 is a small and tells you how long ago a entry or comment was made in english “1 month ago” or french “il y a 1 mois”. Portions of the code are borrowed from Steve P. Sharpe.

You can donwload it here: http://benoitmeunier.info/ee/plugins/timesince2/

This is my first plugin. Be kind.

Usage

Here a example how you can integrate it:

{exp:timesince}{entry_date}{/exp:timesince}

Here the best way to do it:

<abbr title="{entry_date format=&#039;%Y/%m/%d&#039;}EDT{entry_date format=&#039;%g:%i:%s&#039;}-05:00">{exp:timesince}{entry_date}{/exp:timesince}</abbr>

Files

pi.timesince.php /french/lang.timesince.php /english/lang.timesince.php

Sequence

1 hour ago 2 hours ago X hours ago 23 hours ago 1 day ago 2 days ago 3 days ago 4 days ago 5 days ago 6 days ago 1 week ago 2 weeks ago 3 weeks ago 1 month ago Day, Month XX, 200

I have to thanks the Kindo team for helping me getting this plugin out.

       
PixelGrinch's avatar
PixelGrinch
48 posts
16 years ago
PixelGrinch's avatar PixelGrinch

BMeunier: Using your plugin as described: {exp:timesince}{entry_date}{/exp:timesince} puts out only the date of the entry for me and nothing else. Might wanna look into it a bit more. 1.6.7 is the version of EE that I am currently using.

       
anonymous60114's avatar
anonymous60114
11 posts
16 years ago
anonymous60114's avatar anonymous60114

PixelGrinch: if you entry is older than one month, you only have the date. I’ve built it that way because I don’t think it’s relevant to have something like “1 year and 3 months ago…” I think after one month, it’s easier to understand with a date.

       
Chuck Norton's avatar
Chuck Norton
106 posts
16 years ago
Chuck Norton's avatar Chuck Norton

BMeunier, this is a great addon.. I was looking for a way to do it, and this is perfect.

One request, can it do minutes underneith the hour? So if it’s been 5 minutes, it says ‘5 minutes ago’..

Besides that, this is nice little plugin. The best ones are usually the simplest & easiest to use in my opinion!

Thanks! Chuck

       
Jabbler's avatar
Jabbler
59 posts
16 years ago
Jabbler's avatar Jabbler

Here is a little dirty hack to make it EE2 compatible.

EDIT pi.timesince

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

$plugin_info = array(
                        'pi_name'            => 'Timesince',
                        'pi_version'        => '2.0',
                        'pi_author'            => 'Benoit Meunier',
                        'pi_author_url'        => 'http://www.benoitmeunier.info/ee/plugins/timesince2/',
                        'pi_description'    => 'Tells you how long ago a comment or entry was made in english or french',
                        'pi_usage'            => Timesince::usage()
                    );


class Timesince
{
    var $return_data = "";
    function Timesince()
    {
        global $TMPL, $LOC, $LANG;
        $this->EE =& get_instance();
        $this->EE->lang->loadfile('timesince');
        $date = $this->EE->TMPL->tagdata;
        $chunks = array(array(60 * 60 * 24 * 365 , $this->EE->lang->line('year')),
                        array(60 * 60 * 24 * 30 , $this->EE->lang->line('month')),
                        array(60 * 60 * 24 * 7, $this->EE->lang->line('week')),
                        array(60 * 60 * 24 , $this->EE->lang->line('day')),
                        array(60 * 60 , $this->EE->lang->line('hour')),
                        array(60 , $this->EE->lang->line('minute'))
                        );

        $newer_date = $this->EE->localize->now;
        $since = $newer_date - $date;

        // step one: the first chunk
        for ($i = 0, $j = count($chunks); $i < $j; $i++) {
            $seconds = $chunks[$i][0];
            $name = $chunks[$i][1];

            // finding the biggest chunk (if the chunk fits, break)
            if (($count = floor($since / $seconds)) != 0) {
                break;
            }
        }

        // set output var

        $output = "";
        //setlocale(LC_TIME, $this->EE->lang->line('locale'));
        if (($name == $this->EE->lang->line('day')) && ($count == 1)) { $name = $this->EE->lang->line('one_day'); }

        if ($this->EE->lang->line('since') == ' ago') {
            $output = ($count == 1) ? '1 '.$name : "$count {$name}s";
            $output .= $this->EE->lang->line('since');
        }
        else {
            $output = $this->EE->lang->line('since');
            $output .= ($count == 1) ? '1 '.$name : "$count {$name}s";
        }

        if (($name == $this->EE->lang->line('minute')) && ($count == 0)) { $output = $this->EE->lang->line('since_short'); }
        //if (($name == $this->EE->lang->line('month')) && ($count == 1)) { $output = $this->EE->lang->line('since_long'); }
        if ((($name == $this->EE->lang->line('month')) && ($count > 1)) || ($name == $this->EE->lang->line('year'))) {
            $output = $LOC->decode_date($this->EE->lang->line('date'), $date);
        //    $output = strftime($this->EE->lang->line('date'), $date);
        }


        $this->return_data = $output;
    }// function



// ----------------------------------------
//  Plugin Usage
// ----------------------------------------

// This function describes how the plugin is used.
// Make sure and use output buffering

function usage()
{
ob_start();


?>
/***********************************************/
Description:

Tells you how long ago a comment or entry was made in english or french.

/***********************************************/
Example:

Simply put the following code where you want the timesince text to appear, you can use either in entries or comments:

{exp:timesince}
{entry_date}
{/exp:timesince}


{exp:timesince}
{comment_date}
{/exp:timesince}

/***********************************************/
Credits:

This plugin is modified from the original code from Steve P. Sharpe.
http://stevepsharpe.com/blog/permalink/ee-timesince-plugin/
http://expressionengine.com/downloads/details/timesince/


<?php
    $buffer = ob_get_contents();

    ob_end_clean();

    return $buffer;
    }
    // END

} // class

?>
       
anonymous60114's avatar
anonymous60114
11 posts
16 years ago
anonymous60114's avatar anonymous60114

Wow, thank you Jabbler!

       
scottdevries's avatar
scottdevries
103 posts
16 years ago
scottdevries's avatar scottdevries

Fantastic, this was just what I was looking for! Thanks!

       
scottdevries's avatar
scottdevries
103 posts
16 years ago
scottdevries's avatar scottdevries

Just for future reference, the language file will also need to be updated to be compatible with EE 2.0. Here’s the code to replace lang.timesince.php:

<?php

$lang = array(

//----------------------------
// Timesince (english)
//----------------------------

'year' =>
'year',

'month' =>
'month',

'week' =>
'week',

'day' =>
'day',

'hour' =>
'hour',

'minute' =>
'minute',

'since' =>
' ago',

'since_short' =>
'less than a minute ago',

'since_long' =>
'more than 1 month ago',

'one_day' =>
'day',

'date' =>
'%l, %F %d, %Y',

'locale' =>
'en_US',


//----------------------------------------


''=>''
);

/* End of file lang.timesince.php */
/* Location: ./system/expressionengine/language/english/lang.timesince.php */
       
JmanPro's avatar
JmanPro
49 posts
16 years ago
JmanPro's avatar JmanPro

I modified both files as per the posted instructions, but am having no luck using the plugin. I am receiving the following error whenever I try to call the plugin:

Fatal error: Call to a member function decode_date() on a non-object in /home/jrich/jeremiahrich_system/expressionengine/third_party/timesince/pi.timesince.php on line 62

I am on EE 2.01 build 20100215. Any ideas?

       
Davor's avatar
Davor
114 posts
15 years ago
Davor's avatar Davor

BMeunier’s page is offline, is there any other download page available?

thanx

edit: solved

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.