From 8c6c76b329003d5e5dbb8deeb7430ad1c93ef042 Mon Sep 17 00:00:00 2001 From: Tudor Stanciu Date: Wed, 21 Apr 2021 22:52:06 +0300 Subject: [PATCH] msToMinAndSec --- src/features/machines/components/WakeComponent.js | 7 ++++++- src/utils/time.js | 8 ++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 src/utils/time.js diff --git a/src/features/machines/components/WakeComponent.js b/src/features/machines/components/WakeComponent.js index 2193262..97ccb2a 100644 --- a/src/features/machines/components/WakeComponent.js +++ b/src/features/machines/components/WakeComponent.js @@ -5,6 +5,7 @@ import { PowerSettingsNew } from "@material-ui/icons"; import { useTranslation } from "react-i18next"; import { useToast } from "../../../hooks"; import * as api from "../api"; +import { msToMinAndSec } from "../../../utils/time"; const initialState = { on: false }; const defaultPingInterval = 1200000; //20 minutes @@ -43,7 +44,11 @@ const WakeComponent = ({ machine, addLog }) => { success(result.status); //retrigger - log(`Periodic ping will be re-triggered in ${startingTime} ms.`); + log( + `Periodic ping will be re-triggered in ${startingTime} ms [${msToMinAndSec( + startingTime + )}]` + ); setTimeout(() => { setTrigger(prev => !prev); }, startingTime); diff --git a/src/utils/time.js b/src/utils/time.js new file mode 100644 index 0000000..8985a3b --- /dev/null +++ b/src/utils/time.js @@ -0,0 +1,8 @@ +function msToMinAndSec(ms) { + const minutes = Math.floor(ms / 60000); + const seconds = ((ms % 60000) / 1000).toFixed(0); + + return `${minutes}m ${seconds}s`; +} + +export { msToMinAndSec };