Server/project/tests/utils/TimeUtil.test.ts
Refringe 4ac12ef70a Formatting/Linting Changes (!168)
These are the formatting & linting configuration changes from the `3.8.0` branch and the changes that they make to the overall project.

The majority of these changes are from running two commands:

`npm run lint:fix`
`npm run style:fix`

This has already been run on the `3.8.0` branch and this PR should make `master` play nicer when it comes to merges going forward.

There are now four VSCode plugins recommended for server development. They've been added to the workspace file and a user should get a UI notification when the workspace is opened if they're not installed.

The four plugins are:
https://marketplace.visualstudio.com/items?itemName=EditorConfig.EditorConfig
https://marketplace.visualstudio.com/items?itemName=dprint.dprint
https://marketplace.visualstudio.com/items?itemName=dbaeumer.vscode-eslint
https://marketplace.visualstudio.com/items?itemName=biomejs.biome

Once installed they should just work within the workspace.

Also, be sure to `npm i` to get the new dprint application.

Co-authored-by: Refringe <brownelltyler@gmail.com>
Reviewed-on: https://dev.sp-tarkov.com/SPT-AKI/Server/pulls/168
2023-11-16 21:42:06 +00:00

75 lines
2.1 KiB
TypeScript

import "reflect-metadata";
import { beforeEach, describe, expect, it } from "@jest/globals";
import { TimeUtil } from "@spt-aki/utils/TimeUtil";
describe("test text", () =>
{
let timeUtil: TimeUtil;
beforeEach(() =>
{
timeUtil = new TimeUtil();
});
it("BotHelper type check", () =>
{
expect(timeUtil).toBeInstanceOf(TimeUtil);
});
it("formatTime()", () =>
{
expect(timeUtil.formatTime(new Date(2020, 1, 1, 15, 24, 0))).toBe("15-24-00");
});
it("formatDate()", () =>
{
expect(timeUtil.formatDate(new Date(2020, 4, 13))).toBe("2020-05-13");
});
it("getDate()", () =>
{
const currentDate = timeUtil.formatDate(new Date());
expect(timeUtil.getDate()).toBe(currentDate);
});
it("getTime()", () =>
{
const currentTime = timeUtil.formatTime(new Date());
expect(timeUtil.getTime()).toBe(currentTime);
});
it("getHoursAsSeconds() one hour", () =>
{
expect(timeUtil.getHoursAsSeconds(1)).toBe(3600);
});
it("getHoursAsSeconds() three hours", () =>
{
expect(timeUtil.getHoursAsSeconds(3)).toBe(10800);
});
it("getTimestamp()", () =>
{
const currentTimestampSecondsFloored = Math.floor(new Date().getTime() / 1000);
expect(timeUtil.getTimestamp()).toBe(currentTimestampSecondsFloored);
});
it("getTimeMailFormat()", () =>
{
const currentTime = new Date();
const currentTimeMinutes = (currentTime.getMinutes()).toString().padStart(2, "0");
const currentTimeHours = (currentTime.getHours()).toString().padStart(2, "0");
expect(timeUtil.getTimeMailFormat()).toBe(`${currentTimeHours}:${currentTimeMinutes}`);
});
it("getDateMailFormat()", () =>
{
const currentTime = new Date();
const currentDay = (currentTime.getDate()).toString().padStart(2, "0");
const currentMonth = (currentTime.getMonth() + 1).toString().padStart(2, "0");
const currentYear = currentTime.getFullYear();
expect(timeUtil.getDateMailFormat()).toBe(`${currentDay}.${currentMonth}.${currentYear}`);
});
});