Skip to content

Commit 71e65c8

Browse files
committed
Round video duration properly
1 parent 436a873 commit 71e65c8

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

src/formatters.nim

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# SPDX-License-Identifier: AGPL-3.0-only
2-
import strutils, strformat, times, uri, tables, xmltree, htmlparser, htmlgen
2+
import strutils, strformat, times, uri, tables, xmltree, htmlparser, htmlgen, math
33
import std/[enumerate, re]
44
import types, utils, query
55

@@ -157,15 +157,13 @@ proc getShortTime*(tweet: Tweet): string =
157157
proc getDuration*(video: Video): string =
158158
let
159159
ms = video.durationMs
160-
sec = int(ms / 1000)
161-
min = int(sec / 60)
162-
hour = int(min / 60)
163-
if hour > 1:
160+
sec = int(round(ms / 1000))
161+
min = floorDiv(sec, 60)
162+
hour = floorDiv(min, 60)
163+
if hour > 0:
164164
return &"{hour}:{min mod 60}:{sec mod 60:02}"
165-
elif min > 1:
166-
return &"{min mod 60}:{sec mod 60:02}"
167165
else:
168-
return &"0:{sec mod 60:02}"
166+
return &"{min mod 60}:{sec mod 60:02}"
169167

170168
proc getLink*(tweet: Tweet; focus=true): string =
171169
if tweet.id == 0: return

0 commit comments

Comments
 (0)