diff --git a/CHANGELOG.md b/CHANGELOG.md
index 42c2bff8..3dfe6b36 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed
- A crash where the saved auth token is not in a valid format
+- Video duration formatting for long videos
## [0.10.0] - 2023-06-25
diff --git a/playlet-lib/src/components/VideoRowCell/VideoRowCell.bs b/playlet-lib/src/components/VideoRowCell/VideoRowCell.bs
index f20dee61..fc597433 100644
--- a/playlet-lib/src/components/VideoRowCell/VideoRowCell.bs
+++ b/playlet-lib/src/components/VideoRowCell/VideoRowCell.bs
@@ -33,7 +33,7 @@ function OnContentSet() as void
else
m.top.FindNode("liveRect").visible = false
if content.lengthSeconds <> invalid and content.lengthSeconds <> 0
- m.top.FindNode("durationLabel").text = TimeUtils.GetFormattedTime(content.lengthSeconds)
+ SetDurationText(TimeUtils.GetFormattedTime(content.lengthSeconds))
m.top.FindNode("durationRect").visible = true
else
m.top.FindNode("durationRect").visible = false
@@ -42,6 +42,18 @@ function OnContentSet() as void
end function
+function SetDurationText(text as string)
+ label = m.top.FindNode("durationLabel")
+ rect = m.top.FindNode("durationRect")
+ rectParent = rect.getParent()
+
+ label.text = text
+ size = label.localBoundingRect()
+
+ rect.width = size.width + 16
+ rect.translation = [rectParent.width - rect.width, 162]
+end function
+
function OnThumbnailLoadFailed() as void
if m.thumbnail.loadStatus <> "failed"
return
diff --git a/playlet-lib/src/components/VideoRowCell/VideoRowCell.xml b/playlet-lib/src/components/VideoRowCell/VideoRowCell.xml
index 3b6fe023..db021992 100644
--- a/playlet-lib/src/components/VideoRowCell/VideoRowCell.xml
+++ b/playlet-lib/src/components/VideoRowCell/VideoRowCell.xml
@@ -17,18 +17,18 @@
0
+ minutes = "0" + minutes.ToStr()
+ else
+ minutes = minutes.ToStr()
+ end if
+
+ formattedTime = minutes + ":" + seconds
+
+ if hours > 0
+ formattedTime = hours.ToStr() + ":" + formattedTime
+ end if
+
+ return formattedTime
end function
function GetFormattedTimeLeft(unixTimestamp as integer) as string
diff --git a/playlet-web/src/lib/VideoCell.svelte b/playlet-web/src/lib/VideoCell.svelte
index 6ca65bd0..055c2390 100644
--- a/playlet-web/src/lib/VideoCell.svelte
+++ b/playlet-web/src/lib/VideoCell.svelte
@@ -151,10 +151,21 @@
}
function getFormattedTime(length) {
- const minutes = Math.floor(length / 60).toString();
+ const hours = Math.floor(length / 3600);
+ const minutes = Math.floor((length / 60) % 60);
const seconds = length % 60;
+
const secondsString = seconds < 10 ? `0${seconds}` : seconds.toString();
- return minutes + ":" + secondsString;
+ const minutesString =
+ minutes < 10 && hours > 0 ? `0${minutes}` : minutes.toString();
+
+ let formattedTime = minutesString + ":" + secondsString;
+
+ if (hours > 0) {
+ formattedTime = hours.toString() + ":" + formattedTime;
+ }
+
+ return formattedTime;
}
function isVideoLive() {