sonnyt / tweetie

Simple jQuery Twitter feed plugin
https://sonnyt.com/tweetie
312 stars 117 forks source link

How to add feature like "2 days ago" per tweet. #89

Closed MoradHamdy closed 6 years ago

MoradHamdy commented 6 years ago

@sonnyt

Hello there,

I didn't find this feature available in the "Date Format" formula to show since how much time a single tweet is made, like '2 days ago', '27 minutes ago' or '30 seconds ago'.

Also including the template feature like {{tweeted_since}}.

If someone can provide a change for that, then it will be much appreciated!

ghost commented 6 years ago

Change relative_time(tweet.created_at) and add function below.

function relative_time(time_value) { var values = time_value.split(" "); time_value = values[1] + " " + values[2] + ", " + values[5] + " " + values[3]; var parsed_date = Date.parse(time_value); var relative_to = (arguments.length > 1) ? arguments[1] : new Date(); var delta = parseInt((relative_to.getTime() - parsed_date) / 1000); delta = delta + (relative_to.getTimezoneOffset() * 60);

var r = ''; if (delta < 60) { r = 'a minute ago'; } else if(delta < 120) { r = 'couple of minutes ago'; } else if(delta < (4560)) { r = (parseInt(delta / 60)).toString() + ' minutes ago'; } else if(delta < (9060)) { r = 'an hour ago'; } else if(delta < (246060)) { r = '' + (parseInt(delta / 3600)).toString() + ' hours ago'; } else if(delta < (486060)) { r = '1 day ago'; } else { r = (parseInt(delta / 86400)).toString() + ' days ago'; }

  return r;

}

MoradHamdy commented 6 years ago

@keverett

I have added your function in the end of the plugin file. What to do then?

I also want to include the template feature like {{tweeted_since}}.

ghost commented 6 years ago

@MoradHamdy Inside the plugin file (tweetie.js) change tweet.created_at to relative_time(tweet.created_at)

Create a new variable the same as .create_at and only use the function for that variable. {{tweeted_since}}