Problem with timestamp on NH_API_twitteruser [SOLVED]

Have a question or a suggestion about a 3rd party addon module or plugin?
Let us know here.
Post Reply
rubberglover
Forum Members
Forum Members
Posts: 53
Joined: Mon Jul 23, 2007 5:30 pm

Problem with timestamp on NH_API_twitteruser [SOLVED]

Post by rubberglover »

Hi all,

I'm using the nh_api_twitteruser plugin to show a single user's tweets on a website (followed instructions here http://forum.cmsmadesimple.org/index.php/topic,35226.0.html ).

All working well, but the timestamp object variable on every returned 'tweet' object is showing up empty. I've dug into the plug in and echoed out the time stamp as unix before it get's processed into a human readable format, and that shows up fine. It get's set to undefined when the strftime() function is called on the unix timestamp (line 36 in the plugin file).

Unfortunately I am stuck using a Windows server for this website, so don't know if that is making any difference, but I did read a few posts on forums where people were having problems using strftime() on dates that were in the past on Windows servers?

Anyway, as a quick fix I can get the time stamp out as a unix timestamp no problem, and I have confirmed that it is the right date and time, so does anyone know of a simple PHP function that will process a Unix timestamp into human readable format without using strftime()?
Last edited by rubberglover on Sat Nov 13, 2010 1:22 pm, edited 1 time in total.
rubberglover
Forum Members
Forum Members
Posts: 53
Joined: Mon Jul 23, 2007 5:30 pm

Re: Problem with timestamp on NH_API_twitteruser [SOLVED]

Post by rubberglover »

Found a solution to this, ended up adding a little function to the plugin. If anyone has the same problem, here's you can fix it and have your post dates displayed in a similar fashion to Twitter...

Add the following function to the top of the 'function.nh_api_twitteruser.php' file:

Code: Select all

function tweet_time($date,$breakdown=2) {
    $date = strtotime($date);
    $difference = time() - $date;
    $periods = array('decade' => 315360000,
        'year' => 31536000,
        'month' => 2628000,
        'week' => 604800, 
        'day' => 86400,
        'hour' => 3600,
        'minute' => 60,
        'second' => 1);
                                 
    foreach ($periods as $key => $value) {
        if ($difference >= $value) {
            $time = floor($difference/$value);
            $difference %= $value;
            $retval .= ($retval ? ' ' : '').$time.' ';
            $retval .= (($time > 1) ? $key.'s' : $key);
            $breakdown--;
        }
        if ($breakdown == '0') { break; }
    }
    return 'Posted '.$retval.' ago';      
}
...then find the following line in the same file:

Code: Select all

$tweet->timestamp = strftime($date_format,strtotime((string)$item->created_at));
And change it to this...

Code: Select all

$tweet->timestamp = tweet_time($item->created_at);
This does make the 'date_format' parameter redundant, but the existing function wasn't outputting anything at all for me, so I just made the 'time_ago' function output data as I wanted. It will appear in the following style format:

'Posted 1 day 2 hours ago' or 'Posted 2 weeks 2 days ago' or 'Posted 29 seconds ago' etc. etc.

Hope someone finds it useful :)
Post Reply

Return to “Modules/Add-Ons”