forked from noxious/server
#184: Allow GMs to set time
This commit is contained in:
@ -18,10 +18,28 @@ class DateManager {
|
||||
appLogger.info('Date manager loaded')
|
||||
}
|
||||
|
||||
public stop(): void {
|
||||
if (this.intervalId) {
|
||||
clearInterval(this.intervalId)
|
||||
this.intervalId = null
|
||||
// When a GM sets the time, update the current date and update the world file
|
||||
public async setTime(time: string): Promise<void> {
|
||||
try {
|
||||
let newDate: Date;
|
||||
|
||||
// Check if it's just a time (HH:mm or HH:mm:ss format)
|
||||
if (/^\d{1,2}:\d{2}(:\d{2})?$/.test(time)) {
|
||||
const [hours, minutes] = time.split(':').map(Number);
|
||||
newDate = new Date(this.currentDate); // Clone current date
|
||||
newDate.setHours(hours, minutes);
|
||||
} else {
|
||||
// Treat as full datetime string
|
||||
newDate = new Date(time);
|
||||
if (isNaN(newDate.getTime())) return;
|
||||
}
|
||||
|
||||
this.currentDate = newDate;
|
||||
this.emitDate();
|
||||
await this.saveDate();
|
||||
} catch (error) {
|
||||
appLogger.error(`Failed to set time: ${error instanceof Error ? error.message : String(error)}`);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user