Merge pull request #1114 from thelounge/xpaw/moment
Use moment to render dates everywhere
This commit is contained in:
commit
fe77563cdb
@ -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"
|
||||
});
|
||||
};
|
||||
|
@ -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");
|
||||
};
|
||||
|
@ -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");
|
||||
};
|
||||
|
@ -1,17 +1,7 @@
|
||||
"use strict";
|
||||
|
||||
const moment = require("moment");
|
||||
|
||||
module.exports = function(time) {
|
||||
time = new Date(time);
|
||||
var h = time.getHours();
|
||||
var m = time.getMinutes();
|
||||
|
||||
if (h < 10) {
|
||||
h = "0" + h;
|
||||
}
|
||||
|
||||
if (m < 10) {
|
||||
m = "0" + m;
|
||||
}
|
||||
|
||||
return h + ":" + m;
|
||||
return moment(time).format("HH:mm");
|
||||
};
|
||||
|
@ -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"));
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -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");
|
||||
});
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user