Elapsed time since last sync
This is the common dashboard usage for freshness indicators.
<CwDuration from={device.lastSeenAt} />Live-ticking duration from a timestamp with adaptive formatting and optional countdown mode.
<CwDuration
from={new Date(Date.now() + 60 * 1000)}
countDown={true}
/>
let alarmFireCount = $state(0);
<CwDuration
from={new Date()}
alarmAfterMinutes={1}
alarmCallback={() => (alarmFireCount += 1)}
/>
CwDuration is a live-updating relative time display. Give it a starting timestamp, decide whether it counts up or down, and optionally attach an alarm callback for time-based workflows.
| API | Type | Details |
|---|---|---|
from Required | Date | string | number | Base timestamp to measure from. |
countDown Default: | boolean | When true, counts down toward zero instead of counting up from the past. |
tickMs Default: | number | Refresh cadence in milliseconds. |
alarmAfterMinutes | number | Minutes after `from` when the alarm callbacks should fire. |
alarmCallback | () => void | Runs once when the alarm threshold is reached. |
alarmResetCallback | () => void | Runs when the alarm condition is cleared because the source time changes. |
These snippets intentionally show the full public API surface the live demo relies on.
This is the common dashboard usage for freshness indicators.
<CwDuration from={device.lastSeenAt} />Use a shorter `tickMs` when the UI should feel more animated.
<CwDuration
from={new Date(Date.now() + 5 * 60 * 1000)}
countDown
tickMs={250}
/>Attach callbacks when elapsed time should trigger a workflow.
<script lang="ts">
let timedOut = $state(false);
</script>
<CwDuration
from={lastDeviceMessageAt}
alarmAfterMinutes={30}
alarmCallback={() => (timedOut = true)}
alarmResetCallback={() => (timedOut = false)}
/>