since-time-ago-typescript
Version:
typescript package to convert time stamp into a readable format
51 lines • 2.21 kB
JavaScript
;
// import since from "./index";
exports.__esModule = true;
var index_1 = require("./index");
var second = 1000;
var minute = 60 * 1000;
var hour = 60 * minute;
var day = 24 * hour;
var month = 30 * day;
var year = 12 * month;
var nowTimestamp = new Date().getTime();
var fiveMinutesAgoTimestamp = nowTimestamp - 5 * minute;
var fiveSecondsAgoTimestamp = nowTimestamp - 5 * second;
var fiveHoursAgoTimestamp = nowTimestamp - 5 * hour;
var fiveDaysAgoTimestamp = nowTimestamp - 5 * day;
var fiveMonthsAgoTimestamp = nowTimestamp - 5 * month;
var fiveYearsAgoTimestamp = nowTimestamp - 5 * year;
it("returns undefined if no input argument provided", function () {
expect((0, index_1["default"])()).toBeUndefined();
});
it("returns error if input is invalid timestamp", function () {
expect.assertions(1);
try {
(0, index_1["default"])("randomString");
}
catch (e) {
expect(e.message).toBe("Invalid timestamp passed to 'since()'");
}
});
it("returns just now if time stamp is less than 2 seconds ago", function () {
expect((0, index_1["default"])(nowTimestamp)).toBe("just now");
});
it("returns num seconds ago if time stamp is of a few seconds ago", function () {
expect((0, index_1["default"])(fiveSecondsAgoTimestamp)).toBe("5 seconds ago");
});
it("returns num minutes ago if time stamp is of a few minutes ago", function () {
expect((0, index_1["default"])(fiveMinutesAgoTimestamp)).toBe("5 minutes ago");
});
it("returns num hours ago if time stamp is of a few hours ago", function () {
expect((0, index_1["default"])(fiveHoursAgoTimestamp)).toBe("5 hours ago");
});
it("returns num days ago if time stamp is of a few days ago", function () {
expect((0, index_1["default"])(fiveDaysAgoTimestamp)).toBe("5 days ago");
});
it("returns num months ago if time stamp is of a few months ago", function () {
expect((0, index_1["default"])(fiveMonthsAgoTimestamp)).toBe("5 months ago");
});
it("returns num years ago if time stamp is of a few years ago", function () {
expect((0, index_1["default"])(fiveYearsAgoTimestamp)).toBe("5 years ago");
});
//# sourceMappingURL=test.js.map