@tdb/util
Version:
Shared helpers and utilities.
29 lines • 1.21 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
var chai_1 = require("chai");
var libs_1 = require("../../libs");
var _1 = require(".");
describe('toTimestamp', function () {
it('returns a timestamp when no date is passed', function () {
var now = _1.time.toTimestamp(new Date());
chai_1.expect(_1.time.toTimestamp()).to.eql(now);
});
it('returns a timestamp from the given date', function () {
var date = new Date('Thu Mar 22 2018 14:35:10 GMT+1300 (NZDT)');
var timestamp = _1.time.toTimestamp(date);
chai_1.expect(timestamp).to.be.a('number');
chai_1.expect(timestamp).to.eql(_1.time.toTimestamp(date));
chai_1.expect(timestamp).to.eql(libs_1.moment(date)
.utc()
.unix());
});
});
describe('fromTimestamp', function () {
it('converts timestamp number into a Date', function () {
var date = new Date('Thu Mar 22 2018 14:35:10 GMT+1300 (NZDT)');
var timestamp = _1.time.toTimestamp(date);
var res = _1.time.fromTimestamp(timestamp);
chai_1.expect(res.toISOString()).to.eql('2018-03-22T01:35:10.000Z');
});
});
//# sourceMappingURL=util.test.js.map