Close time label: show relative time iff same day. Show year iff not same year.

This commit is contained in:
James Grugett 2022-04-19 12:55:22 -05:00
parent 24a9a79f16
commit d19debfd19

View File

@ -331,6 +331,9 @@ function EditableCloseDate(props: {
closeTime && dayjs(closeTime).format('YYYY-MM-DDT23:59') closeTime && dayjs(closeTime).format('YYYY-MM-DDT23:59')
) )
const isSameYear = dayjs(closeTime).isSame(dayjs(), 'year')
const isSameDay = dayjs(closeTime).isSame(dayjs(), 'day')
const onSave = () => { const onSave = () => {
const newCloseTime = dayjs(closeDate).valueOf() const newCloseTime = dayjs(closeDate).valueOf()
if (newCloseTime === closeTime) setIsEditingCloseTime(false) if (newCloseTime === closeTime) setIsEditingCloseTime(false)
@ -366,7 +369,10 @@ function EditableCloseDate(props: {
text={closeTime > Date.now() ? 'Trading ends:' : 'Trading ended:'} text={closeTime > Date.now() ? 'Trading ends:' : 'Trading ended:'}
time={closeTime} time={closeTime}
> >
{dayjs(closeTime).format('MMM D')} ({fromNow(closeTime)}) {isSameYear
? dayjs(closeTime).format('MMM D')
: dayjs(closeTime).format('MMM D, YYYY')}
{isSameDay && <> ({fromNow(closeTime)})</>}
</DateTimeTooltip> </DateTimeTooltip>
)} )}