Search code examples
jquerytwittertimeago

jquery timeago NaN years ago in firefox


I got my Twitter time who has to be converted to timeago time. It works perfectly in Chrome, but in firefox only the first one on three work and the 2 others return me NaN.

This is the plugin i used. http://timeago.yarp.com/

What can cause this?

// console return

> Fri Jul 11 16:43:21 +0000 2014
> about a month ago
> Tue Jun 17 17:33:19 +0000 2014
> NaN years ago
> Tue Jun 17 16:13:03 +0000 2014
> NaN years ago

I use it with handlebar. I created an Handler to get the job done.

if($.timeago){
    jQuery.timeago.settings.strings = {
       // environ ~= about, it's optional
       prefixAgo: "il y a",
       prefixFromNow: "d'ici",
       seconds: "moins d'une minute",
       minute: "environ une minute",
       minutes: "environ %d minutes",
       hour: "environ une heure",
       hours: "environ %d heures",
       day: "environ un jour",
       days: "environ %d jours",
       month: "environ un mois",
       months: "environ %d mois",
       year: "un an",
       years: "%d ans"
    };
    Handlebars.registerHelper('timeAgo', function(date) {
        console.log(date);
        console.log(jQuery.timeago(date));
        return jQuery.timeago(date);
    });
}

And i use it in an handlebar loop.

{{#each tweets}}
<li class="col-md-4"><div class="tweet"><a href="https://twitter.com/{{user.screen_name}}" class="tweetImg"><img alt="{{user.screen_name}}" src="{{user.profile_image_url}}" /></a><article>{{tweet text}}<span class="date">{{timeAgo created_at}}</span></article></div></li>
{{/each}}

And this is my array of objects

enter image description here


Solution

  • I found the answer.

    It's a parse error on the timeAgo plugin.

    s = s.replace(/T/," ").replace(/Z/," UTC");
    

    This line remove the "T" of tuesday and thursday and gives a date error.

    s = s.replace(/Z/," UTC");
    

    I replaced it with this line above (for my needs it was correct).