Use moment on the client to display friendly dates
Also, unread and date markers are now half-transparent based on their colors and not parent opacity. This is necessary to display a non-translucide tooltip.
This commit is contained in:
parent
bc5b03d2fc
commit
648cfd12db
@ -841,7 +841,6 @@ kbd {
|
|||||||
#chat .unread-marker {
|
#chat .unread-marker {
|
||||||
position: relative;
|
position: relative;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
opacity: .5;
|
|
||||||
margin: 0 10px;
|
margin: 0 10px;
|
||||||
z-index: 0;
|
z-index: 0;
|
||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
@ -855,13 +854,13 @@ kbd {
|
|||||||
left: 0;
|
left: 0;
|
||||||
right: 0;
|
right: 0;
|
||||||
top: 50%;
|
top: 50%;
|
||||||
border-top: 1px solid #e74c3c;
|
border-top: 1px solid rgba(231, 76, 60, .5);
|
||||||
}
|
}
|
||||||
|
|
||||||
#chat .unread-marker-text:before {
|
#chat .unread-marker-text:before {
|
||||||
content: "New messages";
|
content: "New messages";
|
||||||
background-color: white;
|
background-color: white;
|
||||||
color: #e74c3c;
|
color: rgba(231, 76, 60, .5);
|
||||||
padding: 0 10px;
|
padding: 0 10px;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -872,7 +871,6 @@ kbd {
|
|||||||
#chat .date-marker {
|
#chat .date-marker {
|
||||||
position: relative;
|
position: relative;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
opacity: .5;
|
|
||||||
margin: 0 10px;
|
margin: 0 10px;
|
||||||
z-index: 0;
|
z-index: 0;
|
||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
@ -886,13 +884,13 @@ kbd {
|
|||||||
left: 0;
|
left: 0;
|
||||||
right: 0;
|
right: 0;
|
||||||
top: 50%;
|
top: 50%;
|
||||||
border-top: 1px solid #006b3b;
|
border-top: 1px solid rgba(0, 107, 59, .5);
|
||||||
}
|
}
|
||||||
|
|
||||||
#chat .date-marker-text:before {
|
#chat .date-marker-text:before {
|
||||||
content: attr(data-date);
|
content: attr(data-label);
|
||||||
background-color: white;
|
background-color: white;
|
||||||
color: #006b3b;
|
color: rgba(0, 107, 59, .5);
|
||||||
padding: 0 10px;
|
padding: 0 10px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
13
client/js/libs/handlebars/friendlydate.js
Normal file
13
client/js/libs/handlebars/friendlydate.js
Normal file
@ -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"
|
||||||
|
});
|
||||||
|
};
|
@ -155,11 +155,6 @@ body {
|
|||||||
border-color: #333c4a;
|
border-color: #333c4a;
|
||||||
}
|
}
|
||||||
|
|
||||||
#chat .unread-marker,
|
|
||||||
#chat .date-marker {
|
|
||||||
opacity: 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
#chat .unread-marker-text:before {
|
#chat .unread-marker-text:before {
|
||||||
background-color: #333c4a;
|
background-color: #333c4a;
|
||||||
}
|
}
|
||||||
|
@ -181,11 +181,6 @@ body {
|
|||||||
border-color: #3f3f3f;
|
border-color: #3f3f3f;
|
||||||
}
|
}
|
||||||
|
|
||||||
#chat .unread-marker,
|
|
||||||
.date-marker {
|
|
||||||
opacity: 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
#chat .unread-marker-text:before {
|
#chat .unread-marker-text:before {
|
||||||
background-color: #3f3f3f;
|
background-color: #3f3f3f;
|
||||||
}
|
}
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
<div class="tooltipped tooltipped-s" aria-label="{{localedate msgDate}}">
|
||||||
<div class="date-marker">
|
<div class="date-marker">
|
||||||
<span class="date-marker-text" data-date="{{localedate msgDate}}"></span>
|
<span class="date-marker-text" data-label="{{friendlydate msgDate}}"></span>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
24
test/client/js/libs/handlebars/friendlydateTest.js
Normal file
24
test/client/js/libs/handlebars/friendlydateTest.js
Normal file
@ -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"));
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
@ -14,6 +14,7 @@ let config = {
|
|||||||
"handlebars/runtime",
|
"handlebars/runtime",
|
||||||
"jquery",
|
"jquery",
|
||||||
"jquery-ui/ui/widgets/sortable",
|
"jquery-ui/ui/widgets/sortable",
|
||||||
|
"moment",
|
||||||
"mousetrap",
|
"mousetrap",
|
||||||
"socket.io-client",
|
"socket.io-client",
|
||||||
"urijs",
|
"urijs",
|
||||||
|
Loading…
Reference in New Issue
Block a user