From 83fd853c75b1303a58ca2fc1a11189628784667c Mon Sep 17 00:00:00 2001 From: TheHolyRoger Date: Fri, 8 Jul 2022 15:48:45 +0100 Subject: [PATCH] Fix for MQTT remaining time --- src/Components/Stats/TimeStat.tsx | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/Components/Stats/TimeStat.tsx b/src/Components/Stats/TimeStat.tsx index 3d2d6fa..ad583d6 100644 --- a/src/Components/Stats/TimeStat.tsx +++ b/src/Components/Stats/TimeStat.tsx @@ -54,8 +54,15 @@ const getTotalSeconds = ( result = parseInt(timeEntity.state) || 0; } else { if(timeEntity.state){ - const [hours, minutes, seconds] = timeEntity.state.split(':'); - result = (+hours) * 60 * 60 + (+minutes) * 60 + (+seconds); + if(timeEntity.state.includes(", ")){ + const [days_string, time_string] = timeEntity.state.split(', '); + const [hours, minutes, seconds] = time_string.split(':'); + const days = days_string.match(/\d+/)[0]; + result = (+days) * 60 * 60 * 24 + (+hours) * 60 * 60 + (+minutes) * 60 + (+seconds); + } else { + const [hours, minutes, seconds] = timeEntity.state.split(':'); + result = (+hours) * 60 * 60 + (+minutes) * 60 + (+seconds); + } } else { result = 0;