a blog by @gregavola
There was a time when you wanted to figure out how to something better. Usually that involved you searching through numerous Google sites to find out the shortcut to do a certain activity on your keyboard. It took time and when you finally found it - it didn't work. Introducing shrtcuts.org - a nice easy way to learn new and helpful shortcuts that will help you do things better. If you have a shortcut that you want us to write about - send us a message @shrtcuts. Enjoy!
So today - instead of shopping and getting in the holiday sprit - I coded. Why? Well because its fun. I ran into an issue that I though I would share. Currently - I'm working a social networking site than run their own home grown Twitter Application. I wanted it to be in a real time - and adjust the timestamps as it performs an AJAX call to see if there any new messages.
// usage
var rel = relativeTime("Thu, 24 Dec 2009 09:45:33 -0800");
// returns
"One Hour Ago"
// code
function relativeTime(pastTime)
{
var origStamp = Date.parse(pastTime);
var cDate = new Date();
var currentStamp = cDate.getTime();
var difference = parseInt((currentStamp - origStamp)/1000);
if(difference < 0) return false;
if(difference <= 5) return "Just now";
if(difference <= 20) return "Just Seconds ago";
if(difference <= 60) return "A minute ago";
if(difference < 3600) return parseInt(difference/60)+" minutes ago";
if(difference <= 1.5*3600) return "One hour ago";
if(difference < 23.5*3600) return Math.round(difference/3600)+" hours ago";
if(difference < 1.5*24*3600) return "One day ago";
var days = difference / (1.5*24*3600);
if (days <= 10)
{
return Math.round(days) + " days ago";
}
else
{
var dateArr = pastTime.split(' ');
var t = dateArr[4].split(":");
var time_format = "";
if (parseInt(t[0]) > 12)
{
var a = parseInt(t) - 12
time_format = dateArr[2] + " " + dateArr[1] + " " + a + ":" + t[1] + " PM";
}
else
{
var first = "";
if (t[0].substring(0, 1) == "0")
{
first = t[0].substring(1, 2);
}
else
{
first = t[0];
}
time_format = dateArr[2] + " " + dateArr[1] + " " + first + ":" + t[1] + " AM";
}
return time_format;
}
}
So the past couple of days - I've been pretty bored - so I decided to create a stupid website. Something that was so dumb - that no one would use it. Well - today, I launch that service - greg.in. It's not really a service per say - but more like fun productivity decreases.
The site is called greg.in - and it basically puts my picture into anything you can imagine.Like i said - its pretty simple and stupid - but it hella fun making it. Go ahead and try it and search your favorite topic and see what happens!
I hope you enjoy. Feel free to leave a comment or catch me on twitter, @gregavola, and leave some feedback.
- Greg