Add app
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
// Shared 1 Hz clock. Module-level $state + a single interval, so every consumer
|
||||
// (status bar, footer) shares one timer. Read `clock.now` reactively.
|
||||
|
||||
let _now = $state(new Date())
|
||||
|
||||
if (typeof window !== 'undefined') {
|
||||
setInterval(() => { _now = new Date() }, 1000)
|
||||
}
|
||||
|
||||
export const clock = {
|
||||
get now() { return _now },
|
||||
}
|
||||
|
||||
// Playful "stardate" derived from the wall clock, purely cosmetic.
|
||||
export function stardate(d) {
|
||||
const epoch = Date.UTC(2350, 0, 1)
|
||||
const days = (d.getTime() - epoch) / 86_400_000
|
||||
return (47000 + days / 3.65).toFixed(1)
|
||||
}
|
||||
|
||||
export function hhmmss(d) {
|
||||
const p = (n) => String(n).padStart(2, '0')
|
||||
return `${p(d.getHours())}:${p(d.getMinutes())}:${p(d.getSeconds())}`
|
||||
}
|
||||
Reference in New Issue
Block a user