mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-20 10:12:18 +00:00
fix(weather): weather cards measure from the timeline time and know when wind follows it
At a past time the radar, lightning and satellite cards aged the shown frame and judged the source delayed against the wall clock, so a frame from years back read "Source observations delayed" and an age in the millions of minutes. Frame ages, the delayed status and the stale stat now count from the timeline time at a past time, and from now while live, as before. The observed timeline's readout and preview show the time alone at a past time, since its age from the timeline time is always zero. The wind card noted that it does not follow the timeline whenever the observed clock was at a past time, even when a host follows the world clock for wind. The weather clock now reports whether a layer follows the world clock (weatherClock.follows(id), the world clock's follows), and the wind row and card drop that note when its source follows the timeline.
This commit is contained in:
1 parent
7b4b4d4184
commit
6e23a73283
8 files changed
+151
-21
No files matched your search
+26
-15
@@ -21,11 +21,12 @@ const utc = (time) =>
|
||||
? `${formatUtcDayMonth(time)} ${utcClock(time)}`
|
||||
: t('Unavailable');
|
||||
const clockTime = (time) => utcClock(time) || t('Unavailable');
|
||||
const age = (time) => {
|
||||
const minutes = Math.max(
|
||||
0,
|
||||
Math.floor((Date.now() - Date.parse(time)) / 60_000),
|
||||
);
|
||||
// Ages are measured from `nowMs`: the world clock's time at a past time, the
|
||||
// wall clock while live.
|
||||
const minutesBefore = (time, nowMs = Date.now()) =>
|
||||
Math.max(0, Math.floor((nowMs - Date.parse(time)) / 60_000));
|
||||
const age = (time, nowMs) => {
|
||||
const minutes = minutesBefore(time, nowMs);
|
||||
return minutes >= 60
|
||||
? t('{hours}h {minutes}m ago', {
|
||||
hours: Math.floor(minutes / 60),
|
||||
@@ -33,12 +34,21 @@ const age = (time) => {
|
||||
})
|
||||
: t('{minutes}m ago', { minutes });
|
||||
};
|
||||
const historyTime = (time) =>
|
||||
t('{time} · {minutes} min ago', {
|
||||
time: clockTime(time),
|
||||
minutes: Math.max(0, Math.floor((Date.now() - Date.parse(time)) / 60_000)),
|
||||
});
|
||||
const dated = (time) => `${utc(time)} · ${age(time)}`;
|
||||
// A frame's time on the timeline: its age while live; at a past time, the
|
||||
// clock time alone, as the timeline time is the one it is measured from.
|
||||
const historyTime = (time, state) =>
|
||||
state?.mode === 'history'
|
||||
? clockTime(time)
|
||||
: t('{time} · {minutes} min ago', {
|
||||
time: clockTime(time),
|
||||
minutes: minutesBefore(time),
|
||||
});
|
||||
const dated = (time, nowMs) => `${utc(time)} · ${age(time, nowMs)}`;
|
||||
/** The time the observed products show: the timeline time, or now while live. */
|
||||
const shownNow = (state) =>
|
||||
state?.mode === 'history' && Number.isFinite(Date.parse(state.target))
|
||||
? Date.parse(state.target)
|
||||
: Date.now();
|
||||
const set = (node, key, value) => {
|
||||
if (node[key] !== value) node[key] = value;
|
||||
};
|
||||
@@ -90,7 +100,7 @@ export function createWeatherPanel({
|
||||
},
|
||||
transport: {
|
||||
onCommit: (tick) => clock?.setTarget(tick),
|
||||
onPreview: historyTime,
|
||||
onPreview: (time) => historyTime(time, clock?.getState()),
|
||||
onStep: (direction) => clock?.step(direction),
|
||||
onLatest: () => clock?.latest(),
|
||||
onPlay: () => clock?.togglePlay(),
|
||||
@@ -149,7 +159,7 @@ export function createWeatherPanel({
|
||||
readout:
|
||||
state.mode === 'latest'
|
||||
? t('LATEST · newest per product')
|
||||
: historyTime(state.target),
|
||||
: historyTime(state.target, state),
|
||||
};
|
||||
const models = active.map((entry) => {
|
||||
const { id, icon, summary, legend = [], list } = entry;
|
||||
@@ -167,7 +177,7 @@ export function createWeatherPanel({
|
||||
? t('No frame within {gap} min of {time}', { gap, time })
|
||||
: t('No frame within {gap} h of {time}', { gap: gap / 60, time });
|
||||
} else if (shown) {
|
||||
detail = dated(shown);
|
||||
detail = dated(shown, shownNow(state));
|
||||
if (state.mode === 'history')
|
||||
detail =
|
||||
Date.parse(shown) === Date.parse(state.target)
|
||||
@@ -179,7 +189,8 @@ export function createWeatherPanel({
|
||||
valid: utc(summary.validTime),
|
||||
issued: utc(summary.issuedTime),
|
||||
});
|
||||
if (state.mode === 'history')
|
||||
// Unless its source follows the timeline, wind stays at the live edge.
|
||||
if (state.mode === 'history' && !clock?.follows?.(id))
|
||||
detail = t('{detail} · Does not follow history', { detail });
|
||||
}
|
||||
const lines = [
|
||||
|
||||
Reference in new issue
Block a user