extraceted from http://ejohn.org/files/pretty.js
authorDobrica Pavlinusic <dpavlin@rot13.org>
Wed, 26 May 2010 15:31:27 +0000 (17:31 +0200)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Wed, 26 May 2010 15:31:27 +0000 (17:31 +0200)
public/js/date_pretty.js [new file with mode: 0644]

diff --git a/public/js/date_pretty.js b/public/js/date_pretty.js
new file mode 100644 (file)
index 0000000..bf852f1
--- /dev/null
@@ -0,0 +1,25 @@
+/*
+ * extraceted from http://ejohn.org/files/pretty.js
+ * JavaScript Pretty Date
+ * Copyright (c) 2008 John Resig (jquery.com)
+ * Licensed under the MIT license.
+ */
+
+function date_pretty(date) {
+       var
+               diff = (((new Date()).getTime() - date.getTime()) / 1000),
+               day_diff = Math.floor(diff / 86400);
+                       
+       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";
+}