From c02c6cc954b6ea8a4e67e85fd2f97e83b0d7341d Mon Sep 17 00:00:00 2001 From: Tim Abbott Date: Fri, 5 Oct 2012 14:44:29 -0400 Subject: [PATCH] Display the date when either it or the recipient changes. This is somewhat experimental and we may need to work on the condition when it shows up (or move it elsewhere). Also, maybe it should say "Today/Yesterday" for times super close to now -- the main issue with doing this is whether it needs to update without your reloading the page to avoid being super confusing. (imported from commit e29faf30c83b9574e5d233213f42a24175f9a616) --- tools/jslint/check-all.js | 2 +- zephyr/jstemplates/zephyr.html | 2 +- zephyr/static/js/zephyr.js | 29 +++++++++++++++++++++++------ 3 files changed, 25 insertions(+), 8 deletions(-) diff --git a/tools/jslint/check-all.js b/tools/jslint/check-all.js index e8796cc1ca..f6bccf8d8f 100644 --- a/tools/jslint/check-all.js +++ b/tools/jslint/check-all.js @@ -3,7 +3,7 @@ // Global variables, categorized by place of definition. var globals = // Third-party libraries - ' $ jQuery Spinner Handlebars' + ' $ jQuery Spinner Handlebars XDate' // index.html + ' initial_pointer email class_list people_list have_initial_messages' diff --git a/zephyr/jstemplates/zephyr.html b/zephyr/jstemplates/zephyr.html index f5799c801d..661ce20432 100644 --- a/zephyr/jstemplates/zephyr.html +++ b/zephyr/jstemplates/zephyr.html @@ -54,7 +54,7 @@ {{/include_sender}} - {{timestr}} + {{{timestr}}}
{{{content}}}
diff --git a/zephyr/static/js/zephyr.js b/zephyr/static/js/zephyr.js index 10feee1ea1..74fe9ba314 100644 --- a/zephyr/static/js/zephyr.js +++ b/zephyr/static/js/zephyr.js @@ -229,6 +229,27 @@ function clear_table(table_name) { message_groups[table_name] = []; } +function add_display_time(zephyr, prev) { + var two_digits = function (x) { return ('0' + x).slice(-2); }; + var time = new XDate(zephyr.timestamp * 1000); + var include_date = zephyr.include_recipient; + + if (prev !== undefined) { + var prev_time = new XDate(prev.timestamp * 1000); + if (time.toDateString() !== prev_time.toDateString()) { + include_date = true; + } + } + + if (include_date) { + zephyr.timestr = time.toString("MMM dd") + "  " + + time.toString("HH:mm"); + } else { + zephyr.timestr = time.toString("HH:mm"); + } + zephyr.full_date_str = time.toLocaleString(); +} + function add_to_table(zephyrs, table_name, filter_function, where) { if (zephyrs.length === 0) return; @@ -291,6 +312,8 @@ function add_to_table(zephyrs, table_name, filter_function, where) { ids_where_next_is_same_sender.push(prev.id); } + add_display_time(zephyr, prev); + zephyr.dom_id = table_name + zephyr.id; zephyrs_to_render.push(zephyr); @@ -381,12 +404,6 @@ function add_zephyr_metadata(dummy, zephyr) { break; } - var time = new Date(zephyr.timestamp * 1000); - var two_digits = function (x) { return ('0' + x).slice(-2); }; - zephyr.timestr = two_digits(time.getHours()) - + ':' + two_digits(time.getMinutes()); - zephyr.full_date_str = time.toLocaleString(); - zephyr_dict[zephyr.id] = zephyr; }