/** * 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) }