💄 Fix passage delay format when waiting time > 1h

When waiting time is less than 1h, the duration shall be displayed, the arrival time otherwise.
This commit is contained in:
2023-02-12 22:54:52 +01:00
parent 40b2704a15
commit 11c62e5795

View File

@@ -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}
</Motion.text>
</svg>
</div>