newStaffLDB-API #48

Merged
fred.boniface merged 85 commits from newStaffLDB-API into main 2023-10-03 21:35:03 +01:00
2 changed files with 20 additions and 2 deletions
Showing only changes of commit 203d5e56b7 - Show all commits

View File

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