Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save nomatteus/1104435 to your computer and use it in GitHub Desktop.
Save nomatteus/1104435 to your computer and use it in GitHub Desktop.
Change the dates returned by Tumblr's tweet.js callback to something like 12:00 PM Oct. 27th
var prettyTweetDate = function(tweetDateFromJSON) {
var tweetDate = new Date(Date.parse(tweetDateFromJSON)),
tweetHours = tweetDate.getHours();
tweetHours = (tweetHours < 13) ? tweetHours : tweetHours - 12;
var tweetDateSuffix = function(day) {
switch (day) {
case 1: case 21: case 31:
return "st"; break;
case 2: case 22:
return "nd"; break;
case 3: case 23:
return "rd"; break;
default:
return "th";
}
};
return tweetHours + ":" +
tweetDate.getMinutes() + " " +
((tweetHours < 12) ? "AM" : "PM") + " " +
["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"][tweetDate.getMonth()] + " " +
tweetDate.getDate() +
tweetDateSuffix(tweetDate.getDate());
};
// For testing...
console.log(prettyTweetDate("Jan 3, 1975 2:14 AM"));
console.log(prettyTweetDate("Feb 4, 1975 2:14 AM"));
console.log(prettyTweetDate("March 22, 1975 2:14 PM"));
console.log(prettyTweetDate("April 19, 1975 2:14 AM"));
@nomatteus
Copy link
Author

Refactoring, for fun... :P

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment