diff --git a/app/utils/periodic_inform.ts b/app/utils/periodic_inform.ts new file mode 100644 index 0000000..30126d3 --- /dev/null +++ b/app/utils/periodic_inform.ts @@ -0,0 +1,27 @@ +/** + * Computes the estimated next periodic inform date. + * + * @param lastPeriodicInformAt - Date of the last periodic inform + * @param periodicInformInterval - Interval in seconds (from device parameter) + * @returns The estimated next connection date, or null if cannot be computed + */ +export function computeNextPeriodicInform( + lastPeriodicInformAt: Date | string | null | undefined, + periodicInformInterval: number | string | null | undefined +): Date | null { + if (!lastPeriodicInformAt) return null + + const intervalSeconds = typeof periodicInformInterval === 'string' + ? parseInt(periodicInformInterval, 10) + : periodicInformInterval + + if (!intervalSeconds || intervalSeconds <= 0) return null + + const lastDate = lastPeriodicInformAt instanceof Date + ? lastPeriodicInformAt + : new Date(lastPeriodicInformAt) + + if (isNaN(lastDate.getTime())) return null + + return new Date(lastDate.getTime() + intervalSeconds * 1000) +} diff --git a/inertia/pages/DeviceDetail.vue b/inertia/pages/DeviceDetail.vue index b1206c4..e554cba 100644 --- a/inertia/pages/DeviceDetail.vue +++ b/inertia/pages/DeviceDetail.vue @@ -310,11 +310,11 @@ async function resolveAllProviders() { - +