fixed up automation time

This commit is contained in:
ari committed 2022-05-18 10:37:41 -04:00
1 parent 5192c09681
commit ea47b3e1eb
13 files changed
+313 -33

No files matched your search

+20 -2
View File
@@ -1,8 +1,8 @@
import { AutomationTime } from "types/automations/common";
import { AutomationTimeObject, AutomationTimeString } from "types/automations/common";
const cleanTime = (t: number) => Math.max(0, Math.floor(t))
export const milisecondsToObject = (total_miliseconds: number): AutomationTime => {
export const milisecondsToObject = (total_miliseconds: number): AutomationTimeObject => {
const hours = cleanTime(total_miliseconds / (60 * 60 * 1000));
const minutes = cleanTime((total_miliseconds - hours * 60 * 60 * 1000) / (60 * 1000));
const seconds = cleanTime((total_miliseconds - hours * 60 * 60 * 1000 - minutes * 60 * 1000) / 1000);
@@ -10,4 +10,22 @@ export const milisecondsToObject = (total_miliseconds: number): AutomationTime =
return {
hours, minutes, seconds, milliseconds,
}
}
export const convertStringToAutomationTimeObject = (t: AutomationTimeString): AutomationTimeObject => {
const bits = t.split(':')
return {
hours: Number(bits[0]),
minutes: Number(bits[1]),
seconds: bits.length === 3 ? Number(bits[2]) : 0,
}
}
export const convertObjectToAutomationTimeString = (t: AutomationTimeObject): AutomationTimeString => {
const {
hours = 0,
minutes = 0,
seconds = 0
} = t
return [hours, minutes, seconds].map(x => String(x).padStart(2, '0')).join(':')
}