Use today's 4pm utc if past already

This commit is contained in:
Ian Philips 2022-05-26 10:29:46 -06:00
parent 7b0be014eb
commit 09e93779fb

View File

@ -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`)