Permalink
Browse files

Added timestamps to the UI.

  • Loading branch information...
1 parent cbac38e commit d0a3c4869adce557cf8d0af2a94318b8712a098f @dustin dustin committed Aug 30, 2011
View
56 _attachments/js/readme.js
@@ -1,3 +1,59 @@
+function rm_parseISO8601(timestamp) {
+ var regex = new RegExp("^([\\d]{4})-([\\d]{2})-([\\d]{2})T([\\d]{2}):([\\d]{2}):([\\d]{2})Z?$");
+ var matches = regex.exec(timestamp);
+ var rv = null;
+ if(matches != null) {
+ rv = new Date(
+ Date.UTC(
+ parseInt(matches[1], 10),
+ parseInt(matches[2], 10) - 1,
+ parseInt(matches[3], 10),
+ parseInt(matches[4], 10),
+ parseInt(matches[5], 10),
+ parseInt(matches[6], 10)
+ )
+ );
+ } else {
+ rv = new Date(timestamp);
+ }
+ if (rv === null) {
+ console.log("Failed to parse", timestamp);
+ }
+ return rv;
+}
+
+// Mostly stolen from utils, but my timestamps are slightly different.
+function myPretty(ts) {
+ var date = rm_parseISO8601(ts),
+ diff = (((new Date()).getTime() - date.getTime()) / 1000),
+ day_diff = Math.floor(diff / 86400);
+
+ if (isNaN(day_diff)) {
+ return ts;
+ }
+ return day_diff < 1 && (
+ 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 < 21 && day_diff + " days ago" ||
+ day_diff < 45 && Math.ceil( day_diff / 7 ) + " weeks ago" ||
+ date.toString();
+}
+
+function rm_refreshTimestamps() {
+ rm_updateTimestamps();
+ setTimeout(rm_refreshTimestamps, 60000);
+}
+
+function rm_updateTimestamps(app) {
+ $('.timestamp').each(function() {
+ $(this).text(myPretty($(this).attr("title")));
+ });
+}
+
function rm_init_update_links(app) {
var baseUri = app.db.uri;
var ddoc = app.ddoc._id;
View
2 evently/items/_changes/after.js
@@ -17,4 +17,6 @@ function(me, args) {
return false;
});
});
+
+ rm_refreshTimestamps();
}
View
1 evently/items/_changes/mustache.html
@@ -13,6 +13,7 @@
title="important" /></a>]
<span class="name">{{author}}</span>
<a href="{{link}}" class="title">{{title}}</a>
+ <span class="timestamp" title="{{updated}}">{{updated}}</span>
</div>
<div id="message">{{{summary}}}</div>
<div style="clear:left;"></div>
View
1 templates/item.html
@@ -10,6 +10,7 @@
title="important" /></a>]
<span class="name">{{author}}</span>
- <a href="{{link}}" class="title">{{title}}</a>
+ <span class="timestamp" title="{{updated}}">{{updated}}</span>
</div>
<div id="message">{{{summary}}}</div>
<div style="clear:left;"></div>
View
1 templates/tail.html
@@ -18,6 +18,7 @@
$.couch.app(function(app) {
rm_init_update_links(app);
rm_init_list_links(app);
+ rm_refreshTimestamps();
});
</script>
</body>

0 comments on commit d0a3c48

Please sign in to comment.