getNextHourTime zu shared library hinzugefügt
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import { getPublicUser, prisma, User } from "@repo/db";
|
||||
import { addRolesToMember, removeRolesFromMember, renameMember } from "modules/discord";
|
||||
import { getNextDateWithTime } from "@repo/shared-components";
|
||||
import { DISCORD_ROLES } from "@repo/db";
|
||||
import { Server, Socket } from "socket.io";
|
||||
|
||||
@@ -55,22 +56,6 @@ export const handleConnectPilot =
|
||||
});
|
||||
}
|
||||
|
||||
let parsedLogoffDate = null;
|
||||
if (logoffTime.length > 0) {
|
||||
const now = new Date();
|
||||
const [hours, minutes] = logoffTime.split(":").map(Number);
|
||||
if (!hours || !minutes) {
|
||||
throw new Error("Invalid logoffTime format");
|
||||
}
|
||||
parsedLogoffDate = new Date(now);
|
||||
parsedLogoffDate.setHours(hours, minutes, 0, 0);
|
||||
|
||||
// If the calculated time is earlier than now, add one day to make it tomorrow
|
||||
if (parsedLogoffDate <= now) {
|
||||
parsedLogoffDate.setDate(parsedLogoffDate.getDate() + 1);
|
||||
}
|
||||
}
|
||||
|
||||
// Set "now" to 2 hours in the future
|
||||
const nowPlus2h = new Date();
|
||||
nowPlus2h.setHours(nowPlus2h.getHours() + 2);
|
||||
@@ -87,11 +72,13 @@ export const handleConnectPilot =
|
||||
}
|
||||
|
||||
const randomPos = debug ? getRandomGermanPosition() : undefined;
|
||||
const [logoffHours, logoffMinutes] = logoffTime.split(":").map(Number);
|
||||
|
||||
const connectedAircraftEntry = await prisma.connectedAircraft.create({
|
||||
data: {
|
||||
publicUser: getPublicUser(user) as any,
|
||||
esimatedLogoutTime: parsedLogoffDate?.toISOString() || null,
|
||||
esimatedLogoutTime:
|
||||
logoffHours && logoffMinutes ? getNextDateWithTime(logoffHours, logoffMinutes) : null,
|
||||
userId: userId,
|
||||
stationId: parseInt(stationId),
|
||||
lastHeartbeat: debug ? nowPlus2h.toISOString() : undefined,
|
||||
|
||||
Reference in New Issue
Block a user