feat: add Night Shift layer (boot intro, ops strip, headlight, chapter numerals, film grain)
This commit is contained in:
38
src/lib/operations.ts
Normal file
38
src/lib/operations.ts
Normal file
@@ -0,0 +1,38 @@
|
||||
export interface Uptime {
|
||||
readonly months: number;
|
||||
readonly days: number;
|
||||
}
|
||||
|
||||
/** Whole calendar months plus remaining days since `start`, clamped to zero. */
|
||||
export function uptimeSince(start: Date, now: Date): Uptime {
|
||||
if (now.getTime() <= start.getTime()) return { months: 0, days: 0 };
|
||||
let months = (now.getUTCFullYear() - start.getUTCFullYear()) * 12 + (now.getUTCMonth() - start.getUTCMonth());
|
||||
let anchor = addMonths(start, months);
|
||||
if (anchor.getTime() > now.getTime()) {
|
||||
months -= 1;
|
||||
anchor = addMonths(start, months);
|
||||
}
|
||||
const days = Math.floor((now.getTime() - anchor.getTime()) / 86_400_000);
|
||||
return { months, days };
|
||||
}
|
||||
|
||||
function addMonths(date: Date, months: number): Date {
|
||||
return new Date(Date.UTC(
|
||||
date.getUTCFullYear(),
|
||||
date.getUTCMonth() + months,
|
||||
date.getUTCDate(),
|
||||
date.getUTCHours(),
|
||||
date.getUTCMinutes(),
|
||||
));
|
||||
}
|
||||
|
||||
const clockFormat = new Intl.DateTimeFormat('en-GB', {
|
||||
hour: '2-digit',
|
||||
minute: '2-digit',
|
||||
hourCycle: 'h23',
|
||||
timeZone: 'Europe/Bucharest',
|
||||
});
|
||||
|
||||
export function bucharestClock(now: Date): string {
|
||||
return clockFormat.format(now);
|
||||
}
|
||||
Reference in New Issue
Block a user