diff --git a/client/css/style.css b/client/css/style.css index d74baf61..23e2e5a5 100644 --- a/client/css/style.css +++ b/client/css/style.css @@ -841,7 +841,6 @@ kbd { #chat .unread-marker { position: relative; text-align: center; - opacity: .5; margin: 0 10px; z-index: 0; font-weight: bold; @@ -855,13 +854,13 @@ kbd { left: 0; right: 0; top: 50%; - border-top: 1px solid #e74c3c; + border-top: 1px solid rgba(231, 76, 60, .5); } #chat .unread-marker-text:before { content: "New messages"; background-color: white; - color: #e74c3c; + color: rgba(231, 76, 60, .5); padding: 0 10px; } @@ -872,7 +871,6 @@ kbd { #chat .date-marker { position: relative; text-align: center; - opacity: .5; margin: 0 10px; z-index: 0; font-weight: bold; @@ -886,13 +884,13 @@ kbd { left: 0; right: 0; top: 50%; - border-top: 1px solid #006b3b; + border-top: 1px solid rgba(0, 107, 59, .5); } #chat .date-marker-text:before { - content: attr(data-date); + content: attr(data-label); background-color: white; - color: #006b3b; + color: rgba(0, 107, 59, .5); padding: 0 10px; } diff --git a/client/js/libs/handlebars/friendlydate.js b/client/js/libs/handlebars/friendlydate.js new file mode 100644 index 00000000..92e81080 --- /dev/null +++ b/client/js/libs/handlebars/friendlydate.js @@ -0,0 +1,13 @@ +"use strict"; + +const moment = require("moment"); + +module.exports = function(time) { + // See http://momentjs.com/docs/#/displaying/calendar-time/ + return moment(new Date(time)).calendar(null, { + sameDay: "[Today]", + lastDay: "[Yesterday]", + lastWeek: "L", // Locale + sameElse: "L" + }); +}; diff --git a/client/themes/morning.css b/client/themes/morning.css index 9698330c..d5ca62e9 100644 --- a/client/themes/morning.css +++ b/client/themes/morning.css @@ -155,11 +155,6 @@ body { border-color: #333c4a; } -#chat .unread-marker, -#chat .date-marker { - opacity: 1; -} - #chat .unread-marker-text:before { background-color: #333c4a; } diff --git a/client/themes/zenburn.css b/client/themes/zenburn.css index 2c075412..b4abd4ed 100644 --- a/client/themes/zenburn.css +++ b/client/themes/zenburn.css @@ -181,11 +181,6 @@ body { border-color: #3f3f3f; } -#chat .unread-marker, -.date-marker { - opacity: 1; -} - #chat .unread-marker-text:before { background-color: #3f3f3f; } diff --git a/client/views/date-marker.tpl b/client/views/date-marker.tpl index bf9d89c7..3e5ec60d 100644 --- a/client/views/date-marker.tpl +++ b/client/views/date-marker.tpl @@ -1,3 +1,5 @@ -
- +
+
+ +
diff --git a/test/client/js/libs/handlebars/friendlydateTest.js b/test/client/js/libs/handlebars/friendlydateTest.js new file mode 100644 index 00000000..16f335c3 --- /dev/null +++ b/test/client/js/libs/handlebars/friendlydateTest.js @@ -0,0 +1,24 @@ +"use strict"; + +const expect = require("chai").expect; +const moment = require("moment"); +const friendlydate = require("../../../../../client/js/libs/handlebars/friendlydate"); + +describe("friendlydate Handlebars helper", () => { + it("should render 'Today' as a human-friendly date", () => { + const time = new Date().getTime(); + expect(friendlydate(time)).to.equal("Today"); + }); + + it("should render 'Yesterday' as a human-friendly date", () => { + const time = new Date().getTime() - 24 * 3600 * 1000; + expect(friendlydate(time)).to.equal("Yesterday"); + }); + + it("should not render any friendly dates prior to the day before", () => { + [2, 7, 30, 365, 1000].forEach(day => { + const time = new Date().getTime() - 24 * 3600 * 1000 * day; + expect(friendlydate(time)).to.equal(moment(time).format("L")); + }); + }); +}); diff --git a/webpack.config.js b/webpack.config.js index c71979f4..93514dca 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -14,6 +14,7 @@ let config = { "handlebars/runtime", "jquery", "jquery-ui/ui/widgets/sortable", + "moment", "mousetrap", "socket.io-client", "urijs",