Parse the close time as just before midnight
This commit is contained in:
parent
21ac0ed304
commit
d1603de641
|
@ -12,7 +12,8 @@ export async function createContract(
|
||||||
question: string,
|
question: string,
|
||||||
description: string,
|
description: string,
|
||||||
initialProb: number,
|
initialProb: number,
|
||||||
creator: User
|
creator: User,
|
||||||
|
closeTime?: number
|
||||||
) {
|
) {
|
||||||
const proposedSlug = slugify(question).substring(0, 35)
|
const proposedSlug = slugify(question).substring(0, 35)
|
||||||
|
|
||||||
|
@ -45,6 +46,9 @@ export async function createContract(
|
||||||
createdTime: Date.now(),
|
createdTime: Date.now(),
|
||||||
lastUpdatedTime: Date.now(),
|
lastUpdatedTime: Date.now(),
|
||||||
}
|
}
|
||||||
|
if (closeTime) {
|
||||||
|
contract.closeTime = closeTime
|
||||||
|
}
|
||||||
|
|
||||||
return await pushNewContract(contract)
|
return await pushNewContract(contract)
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,6 +10,7 @@ import { createContract } from '../lib/service/create-contract'
|
||||||
import { Page } from '../components/page'
|
import { Page } from '../components/page'
|
||||||
import { Row } from '../components/layout/row'
|
import { Row } from '../components/layout/row'
|
||||||
import clsx from 'clsx'
|
import clsx from 'clsx'
|
||||||
|
import dayjs from 'dayjs'
|
||||||
|
|
||||||
// Allow user to create a new contract
|
// Allow user to create a new contract
|
||||||
export default function NewContract() {
|
export default function NewContract() {
|
||||||
|
@ -22,9 +23,23 @@ export default function NewContract() {
|
||||||
const [initialProb, setInitialProb] = useState(50)
|
const [initialProb, setInitialProb] = useState(50)
|
||||||
const [question, setQuestion] = useState('')
|
const [question, setQuestion] = useState('')
|
||||||
const [description, setDescription] = useState('')
|
const [description, setDescription] = useState('')
|
||||||
|
const [closeDate, setCloseDate] = useState('')
|
||||||
const [isSubmitting, setIsSubmitting] = useState(false)
|
const [isSubmitting, setIsSubmitting] = useState(false)
|
||||||
const [collapsed, setCollapsed] = useState(true)
|
const [collapsed, setCollapsed] = useState(true)
|
||||||
|
|
||||||
|
// Given a date string like '2022-04-02',
|
||||||
|
// return the time just before midnight on that date (in the user's local time), as millis since epoch
|
||||||
|
function dateToMillis(date: string) {
|
||||||
|
return dayjs(date)
|
||||||
|
.set('hour', 23)
|
||||||
|
.set('minute', 59)
|
||||||
|
.set('second', 59)
|
||||||
|
.valueOf()
|
||||||
|
}
|
||||||
|
const closeTime = dateToMillis(closeDate)
|
||||||
|
// We'd like this to look like "Apr 2, 2022, 23:59:59 PM PT" but timezones are hard with dayjs
|
||||||
|
const formattedCloseTime = new Date(closeTime).toString()
|
||||||
|
|
||||||
async function submit() {
|
async function submit() {
|
||||||
// TODO: add more rigorous error handling for question
|
// TODO: add more rigorous error handling for question
|
||||||
if (!creator || !question) return
|
if (!creator || !question) return
|
||||||
|
@ -35,7 +50,8 @@ export default function NewContract() {
|
||||||
question,
|
question,
|
||||||
description,
|
description,
|
||||||
initialProb,
|
initialProb,
|
||||||
creator
|
creator,
|
||||||
|
closeTime
|
||||||
)
|
)
|
||||||
await router.push(path(contract))
|
await router.push(path(contract))
|
||||||
}
|
}
|
||||||
|
@ -78,6 +94,7 @@ export default function NewContract() {
|
||||||
className="input input-bordered input-md"
|
className="input input-bordered input-md"
|
||||||
min={1}
|
min={1}
|
||||||
max={99}
|
max={99}
|
||||||
|
// TODO: validate that this is a number between 1 and 99
|
||||||
onChange={(e) => setInitialProb(parseInt(e.target.value))}
|
onChange={(e) => setInitialProb(parseInt(e.target.value))}
|
||||||
/>
|
/>
|
||||||
<span>%</span>
|
<span>%</span>
|
||||||
|
@ -121,19 +138,23 @@ export default function NewContract() {
|
||||||
|
|
||||||
<div className="form-control">
|
<div className="form-control">
|
||||||
<label className="label">
|
<label className="label">
|
||||||
<span className="label-text">
|
<span className="label-text">Close date (optional)</span>
|
||||||
Close date (optional; trading ends on 4pm EST of this day)
|
|
||||||
</span>
|
|
||||||
</label>
|
</label>
|
||||||
<input
|
<input
|
||||||
type="date"
|
type="date"
|
||||||
className="input input-bordered"
|
className="input input-bordered"
|
||||||
onClick={(e) => e.stopPropagation()}
|
onClick={(e) => e.stopPropagation()}
|
||||||
value="2012-07-22"
|
onChange={(e) => setCloseDate(e.target.value || '')}
|
||||||
min="2022-01-01"
|
value={closeDate}
|
||||||
max="2022-12-31"
|
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
<label>
|
||||||
|
{closeDate && (
|
||||||
|
<span className="label-text text-gray-400 ml-1">
|
||||||
|
No new trades will be allowed after {formattedCloseTime}
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
|
</label>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user