-
-
Notifications
You must be signed in to change notification settings - Fork 983
Fix: Prevent negative seconds in submission countdown timer #5025
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -321,28 +321,34 @@ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| vm.eachPhase = details[i]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| vm.phaseRemainingSubmissionsFlags[details[i].id] = "showClock"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| vm.countDownTimer = function () { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| vm.remainingTime = vm.eachPhase.limits.remaining_time; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| vm.days = Math.floor(vm.remainingTime / 24 / 60 / 60); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| vm.hoursLeft = Math.floor((vm.remainingTime) - (vm.days * 86400)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| vm.hours = Math.floor(vm.hoursLeft / 3600); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| vm.minutesLeft = Math.floor((vm.hoursLeft) - (vm.hours * 3600)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| vm.minutes = Math.floor(vm.minutesLeft / 60); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| vm.remainingSeconds = Math.floor(vm.remainingTime % 60); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (vm.remainingSeconds < 10) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| vm.remainingSeconds = "0" + vm.remainingSeconds; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| vm.phaseRemainingSubmissionsCountdown[details[i].id] = { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "days": vm.days, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "hours": vm.hours, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "minutes": vm.minutes, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "seconds": vm.remainingSeconds | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (vm.remainingTime === 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| vm.phaseRemainingSubmissionsFlags[details[i].id] = "showSubmissionNumbers"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| vm.remainingSeconds--; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Check if time has run out | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (vm.eachPhase.limits.remaining_time <= 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| vm.phaseRemainingSubmissionsFlags[details[i].id] = "showSubmissionNumbers"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Calculate time components from remaining_time | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| var totalSeconds = vm.eachPhase.limits.remaining_time; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| vm.days = Math.floor(totalSeconds / 86400); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| vm.hoursLeft = totalSeconds % 86400; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| vm.hours = Math.floor(vm.hoursLeft / 3600); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| vm.minutesLeft = vm.hoursLeft % 3600; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| vm.minutes = Math.floor(vm.minutesLeft / 60); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| vm.seconds = totalSeconds % 60; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Format seconds with leading zero if needed | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| var formattedSeconds = vm.seconds < 10 ? "0" + vm.seconds : vm.seconds; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| vm.phaseRemainingSubmissionsCountdown[details[i].id] = { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "days": vm.days, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "hours": vm.hours, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "minutes": vm.minutes, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "seconds": formattedSeconds | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Decrement the source value (remaining_time) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| vm.eachPhase.limits.remaining_time--; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+349
to
+350
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Decrement the source value (remaining_time) | |
| vm.eachPhase.limits.remaining_time--; | |
| // Decrement the source value (remaining_time) without going below zero | |
| vm.eachPhase.limits.remaining_time = Math.max(0, vm.eachPhase.limits.remaining_time - 1); |
Copilot
AI
Feb 23, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The diff removes the vm.countDownTimer = function () { assignment line but keeps the closing }; at line 351. As-is, this block will either be a syntax error (unmatched };) or will execute immediately instead of defining vm.countDownTimer, breaking setInterval(... $apply(vm.countDownTimer) ...). Add back the function wrapper so vm.countDownTimer is actually a function and the braces/semicolons match.
| // Check if time has run out | |
| if (vm.eachPhase.limits.remaining_time <= 0) { | |
| vm.phaseRemainingSubmissionsFlags[details[i].id] = "showSubmissionNumbers"; | |
| return; | |
| } | |
| // Calculate time components from remaining_time | |
| var totalSeconds = vm.eachPhase.limits.remaining_time; | |
| vm.days = Math.floor(totalSeconds / 86400); | |
| vm.hoursLeft = totalSeconds % 86400; | |
| vm.hours = Math.floor(vm.hoursLeft / 3600); | |
| vm.minutesLeft = vm.hoursLeft % 3600; | |
| vm.minutes = Math.floor(vm.minutesLeft / 60); | |
| vm.seconds = totalSeconds % 60; | |
| // Format seconds with leading zero if needed | |
| var formattedSeconds = vm.seconds < 10 ? "0" + vm.seconds : vm.seconds; | |
| vm.phaseRemainingSubmissionsCountdown[details[i].id] = { | |
| "days": vm.days, | |
| "hours": vm.hours, | |
| "minutes": vm.minutes, | |
| "seconds": formattedSeconds | |
| }; | |
| // Decrement the source value (remaining_time) | |
| vm.eachPhase.limits.remaining_time--; | |
| }; | |
| vm.countDownTimer = function () { | |
| // Check if time has run out | |
| if (vm.eachPhase.limits.remaining_time <= 0) { | |
| vm.phaseRemainingSubmissionsFlags[details[i].id] = "showSubmissionNumbers"; | |
| return; | |
| } | |
| // Calculate time components from remaining_time | |
| var totalSeconds = vm.eachPhase.limits.remaining_time; | |
| vm.days = Math.floor(totalSeconds / 86400); | |
| vm.hoursLeft = totalSeconds % 86400; | |
| vm.hours = Math.floor(vm.hoursLeft / 3600); | |
| vm.minutesLeft = vm.hoursLeft % 3600; | |
| vm.minutes = Math.floor(vm.minutesLeft / 60); | |
| vm.seconds = totalSeconds % 60; | |
| // Format seconds with leading zero if needed | |
| var formattedSeconds = vm.seconds < 10 ? "0" + vm.seconds : vm.seconds; | |
| vm.phaseRemainingSubmissionsCountdown[details[i].id] = { | |
| "days": vm.days, | |
| "hours": vm.hours, | |
| "minutes": vm.minutes, | |
| "seconds": formattedSeconds | |
| }; | |
| // Decrement the source value (remaining_time) | |
| vm.eachPhase.limits.remaining_time--; | |
| }; |
Copilot
AI
Feb 23, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When time runs out, the code switches the flag and returns, but the interval continues to fire every second and forces a digest via $apply. Consider storing the interval handle and clearing it once remaining_time <= 0 to avoid unnecessary work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This returns a string for
< 10but a number for>= 10, which makessecondstype inconsistent for bindings/formatting. Prefer always producing a string (e.g., viaString(vm.seconds).padStart(2, '0')) so the UI doesn't have to handle mixed types.