-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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")); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Refactoring, for fun... :P