mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-04 10:24:02 +00:00
fix(transit): count a 90-second report as one minute
The card kept seconds through 89s, then rounded 90s up to 2 minutes.
This commit is contained in:
1 parent
9d3548c27c
commit
0309a58643
2 files changed
+23
-1
No files matched your search
@@ -442,10 +442,12 @@ export function buildTransitSelectionCopy(
|
||||
? entry.sample.latestReportAgeMs
|
||||
: vehicleFixAgeMs(record, nowMs, fetchedAtMs)) / 1000,
|
||||
);
|
||||
// Seconds through 89s, then whole minutes. Rounding 90s up would skip
|
||||
// "1 min" and call a minute-and-a-half-old report two minutes old.
|
||||
const reported =
|
||||
ageS < 90
|
||||
? t('Reported {seconds} s ago', { seconds: ageS })
|
||||
: t('Reported {minutes} min ago', { minutes: Math.round(ageS / 60) });
|
||||
: t('Reported {minutes} min ago', { minutes: Math.floor(ageS / 60) });
|
||||
// A time the feed did not give for THIS vehicle is labelled, so the card
|
||||
// never presents a borrowed or inferred time as the vehicle's own report.
|
||||
const ownTime =
|
||||
|
||||
@@ -39,6 +39,26 @@ test('en: the copy is unchanged with and without the i18n t()', () => {
|
||||
]);
|
||||
});
|
||||
|
||||
test('a report 90 seconds old reads as 1 minute, not 2', () => {
|
||||
setLocale('en');
|
||||
const line = (ageMs) =>
|
||||
buildTransitSelectionCopy(
|
||||
feed,
|
||||
{
|
||||
id: 'age',
|
||||
lat: 1,
|
||||
lon: 1,
|
||||
timestamp: Math.floor((now - ageMs) / 1000),
|
||||
timestampSource: 'vehicle',
|
||||
},
|
||||
'bus',
|
||||
now,
|
||||
).details[1];
|
||||
assert.equal(line(89_000), 'Reported 89 s ago');
|
||||
assert.equal(line(90_000), 'Reported 1 min ago');
|
||||
assert.equal(line(120_000), 'Reported 2 min ago');
|
||||
});
|
||||
|
||||
for (const locale of ['es', 'ru']) {
|
||||
test(`${locale}: the Transit card is in the UI language`, () => {
|
||||
setLocale(locale);
|
||||
|
||||
Reference in new issue
Block a user