Skip to content

Instantly share code, notes, and snippets.

@ttepasse
Created May 1, 2010 20:33
Show Gist options
  • Save ttepasse/386637 to your computer and use it in GitHub Desktop.
Save ttepasse/386637 to your computer and use it in GitHub Desktop.
(function (jq) {
var months = ["Jan", "Feb", "Mar", "Apr",
"May", "Jun", "Jul", "Aug",
"Sep", "Oct", "Nov", "Dec"],
monthNumber = {};
months.forEach(function (monthName, index) {
monthNumber[monthName] = index
})
var strangeDatePattern =
/(\w{3})\s(\d\d)\s(\d\d):(\d\d):(\d\d)\s[+-]\d{4}\s(\d{4})/
jq.fn.toStaticDate = function () {
var strangeString = this.attr("data"),
matches = strangeString.match(strangeDatePattern),
month = monthNumber[matches[1]],
date = matches[2],
hours = matches[3],
minutes = matches[4],
seconds = matches[5],
year = matches[6],
timestamp = new Date(Date.UTC(year, month, date, hours, minutes, seconds)),
nYear = timestamp.getFullYear().toString(),
nMonth = timestamp.getMonth().toString(),
nDate = timestamp.getDate().toString(),
nHours = timestamp.getHours().toString(),
nMinutes = timestamp.getMinutes().toString(),
nString = nYear
+ "–"
+ ((nMonth.length > 1) ? nMonth : "0" + nMonth)
+ "–"
+ ((nDate.length > 1) ? nDate : "0" + nDate)
+ " "
+ ((nHours.length > 1) ? nHours : "0" + nHours)
+ ":"
+ ((nMinutes.length > 1) ? nMinutes : "0" + nMinutes);
this.text(nString)
}
// Beim Start des Dokumentes
jq(document).ready(function () {
jq("span.timestamp").toStaticDate()
})
// Nach dem Klicken des More-Buttons und dings | Funzt nicht.
// jq(document.body).delegate(".timestamp", "DOMNodeInserted", function () {
// jq(this).toStaticDate()
// })
})(jQuery)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment