0
0
mirror of https://github.com/sp-tarkov/server.git synced 2025-02-13 06:50:43 -05:00

Removes date-fns

Removes `date-fns` dependency and replace date formatting with custom implementation.
This commit is contained in:
Refringe 2025-01-09 15:44:59 -05:00
parent 17a614aa03
commit 73ebeca095
Signed by: Refringe
SSH Key Fingerprint: SHA256:t865XsQpfTeqPRBMN2G6+N8wlDjkgUCZF3WGW6O9N/k
4 changed files with 19 additions and 9 deletions

View File

@ -36,8 +36,6 @@
}, },
"dependencies": { "dependencies": {
"atomically": "2.0.3", "atomically": "2.0.3",
"date-fns": "~3.6",
"date-fns-tz": "~3.1",
"fs-extra": "11.2.0", "fs-extra": "11.2.0",
"i18n": "~0.15", "i18n": "~0.15",
"json5": "~2.2", "json5": "~2.2",

View File

@ -7,7 +7,6 @@ import type { ILogger } from "@spt/models/spt/utils/ILogger";
import { ConfigServer } from "@spt/servers/ConfigServer"; import { ConfigServer } from "@spt/servers/ConfigServer";
import { DatabaseService } from "@spt/services/DatabaseService"; import { DatabaseService } from "@spt/services/DatabaseService";
import { RandomUtil } from "@spt/utils/RandomUtil"; import { RandomUtil } from "@spt/utils/RandomUtil";
import { max } from "date-fns";
import { inject, injectable } from "tsyringe"; import { inject, injectable } from "tsyringe";
@injectable() @injectable()

View File

@ -1,4 +1,3 @@
import { formatInTimeZone } from "date-fns-tz";
import { injectable } from "tsyringe"; import { injectable } from "tsyringe";
/** /**
@ -110,7 +109,10 @@ export class TimeUtil {
* @returns {string} The current time as 'HH:MM' in UTC. * @returns {string} The current time as 'HH:MM' in UTC.
*/ */
public getTimeMailFormat(): string { 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. * @returns {string} The current date as 'DD.MM.YYYY' in UTC.
*/ */
public getDateMailFormat(): string { 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}`;
} }
/** /**

View File

@ -3,7 +3,6 @@ import "reflect-metadata";
import { ItemHelper } from "@spt/helpers/ItemHelper"; import { ItemHelper } from "@spt/helpers/ItemHelper";
import { IInsurance } from "@spt/models/eft/profile/ISptProfile"; import { IInsurance } from "@spt/models/eft/profile/ISptProfile";
import { profileInsuranceFixture } from "@tests/__fixture__/profileInsurance.fixture"; import { profileInsuranceFixture } from "@tests/__fixture__/profileInsurance.fixture";
import { format } from "date-fns";
import { container } from "tsyringe"; import { container } from "tsyringe";
type DateInput = number | number[] | { [index: number]: number }; type DateInput = number | number[] | { [index: number]: number };
@ -36,9 +35,17 @@ export class ProfileInsuranceFactory {
date = dateInput || defaultDate; 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.scheduledTime = date;
insurance.systemData.date = format(date, "MM.dd.yyyy"); insurance.systemData.date = `${month}.${day}.${year}`;
insurance.systemData.time = format(date, "HH:mm"); insurance.systemData.time = `${hours}:${minutes}`;
return insurance; return insurance;
}); });