From 73ebeca0954a049f9f10e41666a84e60cd1d751a Mon Sep 17 00:00:00 2001 From: Refringe Date: Thu, 9 Jan 2025 15:44:59 -0500 Subject: [PATCH] Removes `date-fns` Removes `date-fns` dependency and replace date formatting with custom implementation. --- project/package.json | 2 -- project/src/helpers/BotHelper.ts | 1 - project/src/utils/TimeUtil.ts | 12 +++++++++--- .../tests/__factories__/ProfileInsurance.factory.ts | 13 ++++++++++--- 4 files changed, 19 insertions(+), 9 deletions(-) diff --git a/project/package.json b/project/package.json index 6a4f16b4..de9f2fed 100644 --- a/project/package.json +++ b/project/package.json @@ -36,8 +36,6 @@ }, "dependencies": { "atomically": "2.0.3", - "date-fns": "~3.6", - "date-fns-tz": "~3.1", "fs-extra": "11.2.0", "i18n": "~0.15", "json5": "~2.2", diff --git a/project/src/helpers/BotHelper.ts b/project/src/helpers/BotHelper.ts index de6009ed..db7d0ded 100644 --- a/project/src/helpers/BotHelper.ts +++ b/project/src/helpers/BotHelper.ts @@ -7,7 +7,6 @@ import type { ILogger } from "@spt/models/spt/utils/ILogger"; import { ConfigServer } from "@spt/servers/ConfigServer"; import { DatabaseService } from "@spt/services/DatabaseService"; import { RandomUtil } from "@spt/utils/RandomUtil"; -import { max } from "date-fns"; import { inject, injectable } from "tsyringe"; @injectable() diff --git a/project/src/utils/TimeUtil.ts b/project/src/utils/TimeUtil.ts index acdafb68..8f98177f 100644 --- a/project/src/utils/TimeUtil.ts +++ b/project/src/utils/TimeUtil.ts @@ -1,4 +1,3 @@ -import { formatInTimeZone } from "date-fns-tz"; import { injectable } from "tsyringe"; /** @@ -110,7 +109,10 @@ export class TimeUtil { * @returns {string} The current time as 'HH:MM' in UTC. */ public getTimeMailFormat(): string { - return formatInTimeZone(new Date(), "UTC", "HH:mm"); + const now = new Date(); + const utcHours = now.getUTCHours().toString().padStart(2, "0"); + const utcMinutes = now.getUTCMinutes().toString().padStart(2, "0"); + return `${utcHours}:${utcMinutes}`; } /** @@ -119,7 +121,11 @@ export class TimeUtil { * @returns {string} The current date as 'DD.MM.YYYY' in UTC. */ public getDateMailFormat(): string { - return formatInTimeZone(new Date(), "UTC", "dd.MM.yyyy"); + const now = new Date(); + const utcDay = now.getUTCDate().toString().padStart(2, "0"); + const utcMonth = (now.getUTCMonth() + 1).toString().padStart(2, "0"); + const utcYear = now.getUTCFullYear().toString(); + return `${utcDay}.${utcMonth}.${utcYear}`; } /** diff --git a/project/tests/__factories__/ProfileInsurance.factory.ts b/project/tests/__factories__/ProfileInsurance.factory.ts index 810beef0..512da037 100644 --- a/project/tests/__factories__/ProfileInsurance.factory.ts +++ b/project/tests/__factories__/ProfileInsurance.factory.ts @@ -3,7 +3,6 @@ import "reflect-metadata"; import { ItemHelper } from "@spt/helpers/ItemHelper"; import { IInsurance } from "@spt/models/eft/profile/ISptProfile"; import { profileInsuranceFixture } from "@tests/__fixture__/profileInsurance.fixture"; -import { format } from "date-fns"; import { container } from "tsyringe"; type DateInput = number | number[] | { [index: number]: number }; @@ -36,9 +35,17 @@ export class ProfileInsuranceFactory { date = dateInput || defaultDate; } + const dateObject = new Date(date * 1000); // Convert UNIX timestamp to milliseconds + + const month = (dateObject.getUTCMonth() + 1).toString().padStart(2, "0"); + const day = dateObject.getUTCDate().toString().padStart(2, "0"); + const year = dateObject.getUTCFullYear(); + const hours = dateObject.getUTCHours().toString().padStart(2, "0"); + const minutes = dateObject.getUTCMinutes().toString().padStart(2, "0"); + insurance.scheduledTime = date; - insurance.systemData.date = format(date, "MM.dd.yyyy"); - insurance.systemData.time = format(date, "HH:mm"); + insurance.systemData.date = `${month}.${day}.${year}`; + insurance.systemData.time = `${hours}:${minutes}`; return insurance; });