From 11c62e57958dec998a4a13e23c3c940034374bc3 Mon Sep 17 00:00:00 2001 From: Adrien Date: Sun, 12 Feb 2023 22:54:52 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=92=84=20Fix=20passage=20delay=20format?= =?UTF-8?q?=20when=20waiting=20time=20>=201h?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When waiting time is less than 1h, the duration shall be displayed, the arrival time otherwise. --- frontend/src/passagesPanel.tsx | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/frontend/src/passagesPanel.tsx b/frontend/src/passagesPanel.tsx index 3a7cdde..8e1c067 100644 --- a/frontend/src/passagesPanel.tsx +++ b/frontend/src/passagesPanel.tsx @@ -1,9 +1,9 @@ import { VoidComponent, createResource, onMount, ParentComponent, ParentProps, Show, useContext, For } from 'solid-js'; import { createDateNow, getTime } from '@solid-primitives/date'; - import { timeline } from '@motionone/dom'; import { AnimationOptions } from '@motionone/types'; import { Motion } from "@motionone/solid"; +import { format } from "date-fns"; import { Line, TrafficStatus } from './types'; import { renderLineTransportMode, renderLinePicto } from './utils'; @@ -43,6 +43,7 @@ const TtwPassage: VoidComponent<{ line: Line, destination: string, index: number const refTs = passage !== undefined ? (passage.expectedDepartTs !== null ? passage.expectedDepartTs : passage.expectedArrivalTs) : 0; const ttwSec = refTs - (getTime(dateNow()) / 1000); + const ttwRepr = ttwSec < 3600 ? `${Math.floor(ttwSec / 60)} min` : format(refTs * 1000, "HH:mm"); const isApproaching = ttwSec <= 60; return ( @@ -56,7 +57,7 @@ const TtwPassage: VoidComponent<{ line: Line, destination: string, index: number initial={isApproaching ? undefined : false} animate={{ opacity: [1, 0, 1] }} transition={transition}> - {Math.floor(ttwSec / 60)} min + {ttwRepr}