From 20682a653f851cb93063130d130b944f26fea38e Mon Sep 17 00:00:00 2001 From: Made Baruna Date: Tue, 4 Jan 2022 13:27:12 +0700 Subject: [PATCH] Fix upcoming event on home --- src/routes/_index/event.svelte | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/routes/_index/event.svelte b/src/routes/_index/event.svelte index f4e37636..6b38265b 100644 --- a/src/routes/_index/event.svelte +++ b/src/routes/_index/event.svelte @@ -36,12 +36,13 @@ if (start.isBefore(now) && end.isAfter(now)) { const diff = end.diff(now); const timeLeft = dayjs.duration(diff); - event.time = timeLeft.format(diff > 86400000 ? 'D[d] H[h]' : 'H[h]'); + event.time = diff > 86400000 ? `${timeLeft.asDays().toFixed(0)}d ${timeLeft.hours()}h` : `${timeLeft.hours()}h`; current = [...current, event]; } else if (start.isAfter(now)) { const diff = start.diff(now); const timeUpcoming = dayjs.duration(diff); - event.time = timeUpcoming.format(diff > 86400000 ? 'D[d] H[h]' : 'H[h]'); + event.time = + diff > 86400000 ? `${timeUpcoming.asDays().toFixed(0)}d ${timeUpcoming.hours()}h` : `${timeUpcoming.hours()}h`; upcoming = [...upcoming, event]; } } @@ -56,6 +57,9 @@ checkEvent(event); } } + + current.sort((a, b) => (dayjs(a.start).isAfter(dayjs(b.start)) ? 1 : -1)); + upcoming.sort((a, b) => (dayjs(a.start).isAfter(dayjs(b.start)) ? 1 : -1)); } onMount(async () => { @@ -73,7 +77,6 @@ await tick(); dispatch('done'); }); -