Add additional tests

Signed-off-by: Fred Boniface <fred@fjla.uk>
This commit is contained in:
Fred Boniface 2023-09-20 14:07:29 +01:00
parent 68f92c41b8
commit 203d5e56b7
2 changed files with 20 additions and 2 deletions

View File

@ -5,10 +5,11 @@ function unixLocal(unix: number) {
} }
function jsUnix(js: number) { function jsUnix(js: number) {
var preRound = js / 1000; return Math.floor(js / 1000);
return Math.round(preRound);
} }
export { jsUnix, unixLocal }
module.exports = { module.exports = {
unixLocal, unixLocal,
jsUnix, jsUnix,

View File

@ -0,0 +1,17 @@
import { jsUnix, unixLocal } from "../../src/utils/timeConvert.utils";
describe("Time Conversion", () => {
test('Should return unix time (seconds)', () => {
const now = new Date();
const nowJs = now.getTime();
const nowUnix = Math.floor(now.getTime() / 1000);
expect(jsUnix(nowJs)).toEqual(nowUnix);
})
test('Should return locale date string', () => {
const now = new Date();
const nowUnix = Math.floor(now.getTime() / 1000);
const result = now.toLocaleString();
expect(unixLocal(nowUnix)).toEqual(result);
})
});