refacto: Changing actions reset windows + display
This commit is contained in:
+2
-2
@@ -1,7 +1,7 @@
|
||||
import { pool } from "./pools.js";
|
||||
import { loadConfigFile, getConfig } from "../configLoader.js";
|
||||
import { computeWorldSeedState } from "../worldSeed.js";
|
||||
import { nextNoonUtc, resetAllUserActions, getUsersByIds } from "./usersDb.js";
|
||||
import { nextResetUtc, resetAllUserActions, getUsersByIds } from "./usersDb.js";
|
||||
|
||||
let lastSeedSlot = null;
|
||||
|
||||
@@ -187,7 +187,7 @@ export async function ensureSeedEpoch() {
|
||||
await pool.query("DELETE FROM team_cell_visibility WHERE world_seed != $1", [worldSeed]);
|
||||
// Reset both team and user quotas to server defaults (no bonuses) for the new period
|
||||
const cfg = getConfig();
|
||||
const nextNoon = nextNoonUtc().toISOString();
|
||||
const nextNoon = nextResetUtc(cfg.actionsResetIntervalHours ?? 12).toISOString();
|
||||
await pool.query(
|
||||
`INSERT INTO team_action_quota (team, actions_remaining, quota_reset_at)
|
||||
VALUES ('blue', $1, $2), ('red', $1, $2)
|
||||
|
||||
+20
-4
@@ -29,12 +29,28 @@ export async function initUserActionQuotaSchema() {
|
||||
|
||||
/** Returns the next noon (12:00:00) UTC after the current moment. */
|
||||
export function nextNoonUtc() {
|
||||
return nextResetUtc(12);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the next reset timestamp UTC based on a repeating interval.
|
||||
* @param {number} intervalHours - must be a divisor of 24 (1,2,3,4,6,8,12,24)
|
||||
*/
|
||||
export function nextResetUtc(intervalHours) {
|
||||
const now = new Date();
|
||||
const noon = new Date(Date.UTC(
|
||||
now.getUTCFullYear(), now.getUTCMonth(), now.getUTCDate(), 12, 0, 0, 0
|
||||
const utcHours = now.getUTCHours();
|
||||
const slotsPassed = Math.floor(utcHours / intervalHours);
|
||||
const nextSlotHour = (slotsPassed + 1) * intervalHours;
|
||||
if (nextSlotHour < 24) {
|
||||
return new Date(Date.UTC(
|
||||
now.getUTCFullYear(), now.getUTCMonth(), now.getUTCDate(),
|
||||
nextSlotHour, 0, 0, 0
|
||||
));
|
||||
}
|
||||
return new Date(Date.UTC(
|
||||
now.getUTCFullYear(), now.getUTCMonth(), now.getUTCDate() + 1,
|
||||
0, 0, 0, 0
|
||||
));
|
||||
if (noon <= now) noon.setUTCDate(noon.getUTCDate() + 1);
|
||||
return noon;
|
||||
}
|
||||
|
||||
// ── Queries ───────────────────────────────────────────────────────────────────
|
||||
|
||||
Reference in New Issue
Block a user