From 09e93779fbd1ad34ca06efed9dabe38d49a84ec5 Mon Sep 17 00:00:00 2001 From: Ian Philips Date: Thu, 26 May 2022 10:29:46 -0600 Subject: [PATCH] Use today's 4pm utc if past already --- functions/src/create-contract.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/functions/src/create-contract.ts b/functions/src/create-contract.ts index 485e3bb1..952d396c 100644 --- a/functions/src/create-contract.ts +++ b/functions/src/create-contract.ts @@ -88,9 +88,11 @@ export const createContract = newEndpoint(['POST'], async (req, _res) => { throw new APIError(400, 'Invalid initial probability') // Uses utc time on server: - const yesterday = new Date() - yesterday.setUTCDate(yesterday.getUTCDate() - 1) - const freeMarketResetTime = yesterday.setUTCHours(16, 0, 0, 0) + const today = new Date() + let freeMarketResetTime = today.setUTCHours(16, 0, 0, 0) + if (today.getTime() < freeMarketResetTime) { + freeMarketResetTime = freeMarketResetTime - 24 * 60 * 60 * 1000 + } const userContractsCreatedTodaySnapshot = await firestore .collection(`contracts`)