Skip to content

A spy satellite simulator in your browser, except the data is real. Live open source spatial intelligence on a photorealistic 3D globe.

fix(transit): count a 90-second report as one minute

Rudy Celekli0309a58643d5
diff --git a/src/layers/transit/policy.js b/src/layers/transit/policy.js
index 010a2efc2..5dc17daeb 100644
--- a/src/layers/transit/policy.js
+++ b/src/layers/transit/policy.js
@@ -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 =
diff --git a/src/layers/transit/selectionCopy.i18n.test.mjs b/src/layers/transit/selectionCopy.i18n.test.mjs
index 81fdfa0bb..26de5d28a 100644
--- a/src/layers/transit/selectionCopy.i18n.test.mjs
+++ b/src/layers/transit/selectionCopy.i18n.test.mjs
@@ -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);