Maybe free market countdown will work now, beats me

This commit is contained in:
Ian Philips 2022-05-25 15:55:50 -06:00
parent d117ff600a
commit f3be3b1f3c

View File

@ -1,17 +1,36 @@
import { listContracts } from 'web/lib/firebase/contracts' import { listContracts } from 'web/lib/firebase/contracts'
import { useEffect, useState } from 'react' import { useEffect, useState } from 'react'
import { User } from 'common/user' import { User } from 'common/user'
import dayjs from 'dayjs'
import utc from 'dayjs/plugin/utc'
dayjs.extend(utc)
let sessionCreatedContractToday = true let sessionCreatedContractToday = true
export function getUtcFreeMarketResetTime(yesterday: boolean) { export function getUtcFreeMarketResetTime(previous: boolean) {
// Uses utc time like the server. const localTimeNow = new Date()
const utcFreeMarketResetTime = new Date() const utc4pmToday = dayjs()
utcFreeMarketResetTime.setUTCDate( .utc()
utcFreeMarketResetTime.getUTCDate() - (yesterday ? 1 : 0) .set('hour', 16)
) .set('minute', 0)
const utcFreeMarketMS = utcFreeMarketResetTime.setUTCHours(16, 0, 0, 0) .set('second', 0)
return utcFreeMarketMS .set('millisecond', 0)
// if it's after 4pm UTC today
if (localTimeNow.getTime() > utc4pmToday.valueOf()) {
return previous
? // Return it as it is
utc4pmToday.valueOf()
: // Or add 24 hours to get the next 4pm UTC time:
utc4pmToday.valueOf() + 24 * 60 * 60 * 1000
}
// 4pm UTC today is coming up
return previous
? // Subtract 24 hours to get the previous 4pm UTC time:
utc4pmToday.valueOf() - 24 * 60 * 60 * 1000
: // Return it as it is
utc4pmToday.valueOf()
} }
export const useHasCreatedContractToday = (user: User | null | undefined) => { export const useHasCreatedContractToday = (user: User | null | undefined) => {