Skip to content

Commit 431afdf

Browse files
committed
Fix glitch with values equal to 0 and seconds not rounded in elapsed time
1 parent 6456a32 commit 431afdf

File tree

3 files changed

+17
-13
lines changed

3 files changed

+17
-13
lines changed

src/components/Panels/Status.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,22 +27,26 @@ import { espHttpURL } from "../Helpers"
2727

2828
const TimeControl = ({ label, time }) => {
2929
if (!time) return null
30+
time.day = time.day ? time.day.toString() : "0"
31+
time.hour = time.hour ? time.hour.toString() : "0"
32+
time.min = time.min ? time.min.toString() : "0"
33+
time.sec = time.sec ? time.sec.toString() : "0"
3034
return (
3135
<div class="extra-control-value flex-row-between">
3236
<div class="m-1">{T(label)}:</div>
33-
{time.day && time.day > 0 && (
37+
{time.day != "0" && (
3438
<div class="m-1">
3539
{time.day}
3640
{T("P108")}
3741
</div>
3842
)}
39-
{((time.day && time.day > 0) || time.hour > 0) && (
43+
{(time.day != "0" || time.hour != "0") && (
4044
<div class="m-1">
4145
{time.hour}
4246
{T("P109")}
4347
</div>
4448
)}
45-
{((time.day && time.day > 0) || time.hour > 0 || time.min > 0) && (
49+
{(time.day != "0" || time.hour != "0" || time.min != "0") && (
4650
<div class="m-1">
4751
{time.min}
4852
{T("P110")}

src/targets/Printer3D/Marlin-embedded/TargetContext.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -130,17 +130,17 @@ const TargetContextProvider = ({ children }) => {
130130

131131
const estimatedTime = (progress, time) => {
132132
const total =
133-
(time.day ? parseInt(time.day) * 24 * 60 * 60 : 0) +
134-
(time.hour ? parseInt(time.hour) * 60 * 60 : 0) +
135-
(time.min ? parseInt(time.min) * 60 : 0) +
136-
(time.sec ? parseInt(time.sec) : 0)
133+
(time.day ? parseInt(time.day ? time.day : 0) * 24 * 60 * 60 : 0) +
134+
(time.hour ? parseInt(time.hour ? time.hour : 0) * 60 * 60 : 0) +
135+
(time.min ? parseInt(time.min ? time.min : 0) * 60 : 0) +
136+
(time.sec ? parseInt(time.sec ? time.sec : 0) : 0)
137137
const totalSecondsLeft = (total * (100 - progress)) / progress
138138
return {
139139
year: null,
140140
day: Math.floor((totalSecondsLeft % (86400 * 30)) / 86400),
141141
hour: Math.floor((totalSecondsLeft % 86400) / 3600),
142142
min: Math.floor((totalSecondsLeft % 3600) / 60),
143-
sec: totalSecondsLeft % 60,
143+
sec: Math.floor(totalSecondsLeft % 60),
144144
}
145145
}
146146

src/targets/Printer3D/Marlin/TargetContext.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -130,17 +130,17 @@ const TargetContextProvider = ({ children }) => {
130130

131131
const estimatedTime = (progress, time) => {
132132
const total =
133-
(time.day ? parseInt(time.day) * 24 * 60 * 60 : 0) +
134-
(time.hour ? parseInt(time.hour) * 60 * 60 : 0) +
135-
(time.min ? parseInt(time.min) * 60 : 0) +
136-
(time.sec ? parseInt(time.sec) : 0)
133+
(time.day ? parseInt(time.day ? time.day : 0) * 24 * 60 * 60 : 0) +
134+
(time.hour ? parseInt(time.hour ? time.hour : 0) * 60 * 60 : 0) +
135+
(time.min ? parseInt(time.min ? time.min : 0) * 60 : 0) +
136+
(time.sec ? parseInt(time.sec ? time.sec : 0) : 0)
137137
const totalSecondsLeft = (total * (100 - progress)) / progress
138138
return {
139139
year: null,
140140
day: Math.floor((totalSecondsLeft % (86400 * 30)) / 86400),
141141
hour: Math.floor((totalSecondsLeft % 86400) / 3600),
142142
min: Math.floor((totalSecondsLeft % 3600) / 60),
143-
sec: totalSecondsLeft % 60,
143+
sec: Math.floor(totalSecondsLeft % 60),
144144
}
145145
}
146146

0 commit comments

Comments
 (0)