diff --git a/isso/js/isso.js b/isso/js/isso.js index d197cbf..0eec7bb 100644 --- a/isso/js/isso.js +++ b/isso/js/isso.js @@ -22,40 +22,28 @@ function read(cookie){ }; -function zfill(arg, i) { - var res = String(arg); - if (res.length < i) { - for (var j = 0; j <= (i - res.length); j++) { - res = '0' + res; - }; - }; +function format(date){ + /*! + * JavaScript Pretty Date + * Copyright (c) 2011 John Resig (ejohn.org) + * Licensed under the MIT and GPL licenses. + */ + var diff = (((new Date()).getTime() - date.getTime()) / 1000), + day_diff = Math.floor(diff / 86400); - return res; -}; - - -// pythonic strftime -var format = function(date, lang, fmt) { - - var months = {'de': [ - 'Januar', 'Februar', 'März', 'April', 'Mai', 'Juni', 'Juli', - 'August', 'September', 'Oktober', 'November', 'Dezember'], - 'en': [ - 'January', 'February', 'March', 'April', 'May', 'June', 'July', - 'August', 'September', 'October', 'November', 'December'], - }; - - var conversions = [ - ['%Y', date.getFullYear()], ['%m', zfill(date.getMonth(), 2)], - ['%B', months[lang][date.getMonth() - 1]], - ['%d', zfill(date.getDate(), 2)], ['%H', zfill(date.getHours(), 2)], - ['%H', zfill(date.getHours(), 2)], ['%M', zfill(date.getMinutes(), 2)], - ]; - - conversions.map(function(item) { fmt = fmt.replace(item[0], item[1]) }); - return fmt; -}; + if ( isNaN(day_diff) || day_diff < 0 || day_diff >= 31 ) + return; + return day_diff == 0 && ( + diff < 60 && "just now" || + diff < 120 && "1 minute ago" || + diff < 3600 && Math.floor( diff / 60 ) + " minutes ago" || + diff < 7200 && "1 hour ago" || + diff < 86400 && Math.floor( diff / 3600 ) + " hours ago") || + day_diff == 1 && "Yesterday" || + day_diff < 7 && day_diff + " days ago" || + day_diff < 31 && Math.ceil( day_diff / 7 ) + " weeks ago"; +} /* * isso specific helpers to create, modify, delete and receive comments @@ -161,8 +149,8 @@ function insert(post) { ' ' + ''); diff --git a/isso/static/style.css b/isso/static/style.css index 33037c7..7b648eb 100644 --- a/isso/static/style.css +++ b/isso/static/style.css @@ -12,9 +12,8 @@ font-weight: bold; } -.isso .date { +.isso time { color: lightgray; - padding-left: 12px; } .isso > header {