add desk text sensor and change detection

This commit is contained in:
Darius
2025-10-03 13:46:07 +02:00
parent fd420fa59a
commit 31b9ba105f
5 changed files with 52 additions and 31 deletions

View File

@@ -30,19 +30,25 @@ export async function promptForInput(prompt: string): Promise<string> {
export function calculateSecondsBetween(
start: number,
end: number,
): { seconds: number; toReadable: () => string } {
): { seconds: number; toReadable: (roundToMinutes?: boolean) => string } {
const seconds = (end - start) / 1000;
return {
seconds,
toReadable: () => secondsToReadable(seconds),
toReadable: (roundToMinutes?: boolean) =>
secondsToReadable(seconds, roundToMinutes),
};
}
export function secondsToReadable(secs: number): string {
var days = Math.floor(secs / (3600 * 24));
var hours = Math.floor((secs % (3600 * 24)) / 3600);
var minutes = Math.floor((secs % 3600) / 60);
var seconds = Math.floor(secs % 60);
export function secondsToReadable(
secs: number,
roundToMinutes: boolean = false,
): string {
const totalSeconds = roundToMinutes ? Math.round(secs / 60) * 60 : secs;
var days = Math.floor(totalSeconds / (3600 * 24));
var hours = Math.floor((totalSeconds % (3600 * 24)) / 3600);
var minutes = Math.floor((totalSeconds % 3600) / 60);
var seconds = Math.floor(totalSeconds % 60);
var dayDisplay = days > 0 ? days + (days === 1 ? " day, " : " days, ") : "";
var hourDisplay =
@@ -56,3 +62,9 @@ export function secondsToReadable(secs: number): string {
"",
);
}
function meterToCentimeters(length: string): number {
const meters = parseFloat(length);
const centimeters = Math.round(meters * 100);
return centimeters;
}