newStaffLDB-API #48
@ -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,
|
||||||
|
17
test/utils/timeConvert.utils.test.ts
Normal file
17
test/utils/timeConvert.utils.test.ts
Normal 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);
|
||||||
|
})
|
||||||
|
});
|
Loading…
Reference in New Issue
Block a user