Skip to content

Commit

Permalink
Merge pull request #1114 from thelounge/xpaw/moment
Browse files Browse the repository at this point in the history
Use moment to render dates everywhere
  • Loading branch information
xPaw authored May 6, 2017
2 parents 57d7616 + 700d3c1 commit fe77563
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 20 deletions.
6 changes: 3 additions & 3 deletions client/js/libs/handlebars/friendlydate.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ const moment = require("moment");

module.exports = function(time) {
// See http://momentjs.com/docs/#/displaying/calendar-time/
return moment(new Date(time)).calendar(null, {
return moment(time).calendar(null, {
sameDay: "[Today]",
lastDay: "[Yesterday]",
lastWeek: "L", // Locale
sameElse: "L"
lastWeek: "D MMMM YYYY",
sameElse: "D MMMM YYYY"
});
};
4 changes: 3 additions & 1 deletion client/js/libs/handlebars/localedate.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"use strict";

const moment = require("moment");

module.exports = function(time) {
return new Date(time).toLocaleDateString();
return moment(time).format("D MMMM YYYY");
};
4 changes: 3 additions & 1 deletion client/js/libs/handlebars/localetime.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"use strict";

const moment = require("moment");

module.exports = function(time) {
return new Date(time).toLocaleString();
return moment(time).format("D MMMM YYYY, HH:mm:ss");
};
16 changes: 3 additions & 13 deletions client/js/libs/handlebars/tz.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,7 @@
"use strict";

module.exports = function(time) {
time = new Date(time);
var h = time.getHours();
var m = time.getMinutes();

if (h < 10) {
h = "0" + h;
}
const moment = require("moment");

if (m < 10) {
m = "0" + m;
}

return h + ":" + m;
module.exports = function(time) {
return moment(time).format("HH:mm");
};
2 changes: 1 addition & 1 deletion test/client/js/libs/handlebars/friendlydateTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ describe("friendlydate Handlebars helper", () => {
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"));
expect(friendlydate(time)).to.equal(moment(time).format("D MMMM YYYY"));
});
});
});
2 changes: 1 addition & 1 deletion test/client/js/libs/handlebars/localetimeTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ describe("localetime Handlebars helper", () => {
// Pretend local timezone is UTC by moving the clock of that offset
const time = date.getTime() + offset;

expect(localetime(time)).to.equal("5/22/2014, 12:00:00 PM");
expect(localetime(time)).to.equal("22 May 2014, 12:00:00");
});
});

0 comments on commit fe77563

Please sign in to comment.