mirror of
https://github.com/KevinMidboe/hivemonitor.git
synced 2025-10-29 01:20:25 +00:00
Helper funcs for formatting telemetry values in consistent way
This commit is contained in:
24
src/lib/telemetryFormatters.ts
Normal file
24
src/lib/telemetryFormatters.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
export function formatWeight(weight: string | undefined) {
|
||||
return weight || 24
|
||||
}
|
||||
|
||||
export function formatTemperature(temp: string | undefined) {
|
||||
return temp ? temp.replace(".00", "") : '-'
|
||||
}
|
||||
|
||||
export function formatHumidity(humidity: string | undefined) {
|
||||
return humidity ? humidity.replace(".00", "") : '-'
|
||||
}
|
||||
|
||||
export function formatBattery(batteryLevel: string | undefined) {
|
||||
return batteryLevel || 89
|
||||
}
|
||||
|
||||
export function diffTime(date: Date | string | undefined): number {
|
||||
if (!date) return new Date().getTime()
|
||||
if (typeof date === 'string') date = new Date(date)
|
||||
|
||||
const seconds = (new Date().getTime() - date.getTime()) / 1000
|
||||
return Math.floor(seconds)
|
||||
// return Math.round(seconds / 10) * 10
|
||||
}
|
||||
Reference in New Issue
Block a user