aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2023-03-11 11:00:11 +0900
committernsfisis <nsfisis@gmail.com>2023-03-11 11:00:11 +0900
commit367dc1ea5ce1548d01688fda6baa5c9861f964e1 (patch)
tree1ac29889ad36e6e0d0f8177cf20392eca8c3f5fb
parentbf5a7df4608a0cdf5b1c145fcf2002560f3ecf44 (diff)
downloadterm-clock-367dc1ea5ce1548d01688fda6baa5c9861f964e1.tar.gz
term-clock-367dc1ea5ce1548d01688fda6baa5c9861f964e1.tar.zst
term-clock-367dc1ea5ce1548d01688fda6baa5c9861f964e1.zip
fix(timer): fix a crash when duration is longer than 1 minute
-rw-r--r--cmd/timer.go12
1 files changed, 6 insertions, 6 deletions
diff --git a/cmd/timer.go b/cmd/timer.go
index 0e0ff48..aca2380 100644
--- a/cmd/timer.go
+++ b/cmd/timer.go
@@ -21,18 +21,18 @@ func drawTimer(scr *term.Screen, leftTime time.Duration, bgStyle, fgStyle term.S
squareW, squareH, xOffset, yOffset := calcSquareSize(scr)
// Minute
- minute := leftTime.Minutes()
- term.DrawNumber(scr, int(minute)/10, xOffset+squareW*0, yOffset, squareW, squareH, fgStyle)
- term.DrawNumber(scr, int(minute)%10, xOffset+squareW*4, yOffset, squareW, squareH, fgStyle)
+ minute := int(leftTime.Minutes())
+ term.DrawNumber(scr, minute/10, xOffset+squareW*0, yOffset, squareW, squareH, fgStyle)
+ term.DrawNumber(scr, minute%10, xOffset+squareW*4, yOffset, squareW, squareH, fgStyle)
// Colon
term.DrawSquare(scr, xOffset+squareW*8, yOffset+squareH*1, squareW, squareH, fgStyle)
term.DrawSquare(scr, xOffset+squareW*8, yOffset+squareH*3, squareW, squareH, fgStyle)
// Second
- second := leftTime.Seconds()
- term.DrawNumber(scr, int(second)/10, xOffset+squareW*10, yOffset, squareW, squareH, fgStyle)
- term.DrawNumber(scr, int(second)%10, xOffset+squareW*14, yOffset, squareW, squareH, fgStyle)
+ second := int(leftTime.Seconds()) % 60
+ term.DrawNumber(scr, second/10, xOffset+squareW*10, yOffset, squareW, squareH, fgStyle)
+ term.DrawNumber(scr, second%10, xOffset+squareW*14, yOffset, squareW, squareH, fgStyle)
}
func cmdTimer(cmd *cobra.Command, args []string) {