Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

fix(mobile): show hours in chapter times

Paddy6b6b50c30c1c
diff --git a/apps/mobile/app/caps/[id].tsx b/apps/mobile/app/caps/[id].tsx
index 45c5d46ca..86d933cb3 100644
--- a/apps/mobile/app/caps/[id].tsx
+++ b/apps/mobile/app/caps/[id].tsx
@@ -46,7 +46,7 @@ import { GlassSurface } from "@/components/GlassSurface";
import { ReactionBar, type ReactionCount } from "@/components/ReactionBar";
import { Screen } from "@/components/Screen";
import { colors, fonts, radius, squircle } from "@/theme";
-import { formatRelativeDate } from "@/utils/format";
+import { formatChapterTime, formatRelativeDate } from "@/utils/format";
const showPhotosSettingsAlert = () => {
if (Platform.OS === "ios") {
@@ -106,14 +106,6 @@ const sectionEntrance = (order: number) =>
.stiffness(220)
.delay(order * 55);
-const formatChapterTime = (start: number) => {
- const minutes = Math.floor(start / 60);
- const seconds = Math.floor(start % 60)
- .toString()
- .padStart(2, "0");
- return `${minutes}:${seconds}`;
-};
-
type CapDetailOperation = "comment" | "safety" | "save" | "visibility";
type AnalyticsMetricProps = {
@@ -1691,7 +1683,7 @@ const styles = StyleSheet.create({
borderColor: colors.gray5,
},
chapterTime: {
- width: 44,
+ minWidth: 44,
fontFamily: fonts.medium,
fontSize: 13,
color: colors.blue11,
diff --git a/apps/mobile/src/utils/format.test.ts b/apps/mobile/src/utils/format.test.ts
index 1ef398500..82475a65e 100644
--- a/apps/mobile/src/utils/format.test.ts
+++ b/apps/mobile/src/utils/format.test.ts
@@ -1,5 +1,10 @@
import { describe, expect, it } from "vitest";
-import { formatDuration, formatFileSize, formatRelativeDate } from "./format";
+import {
+ formatChapterTime,
+ formatDuration,
+ formatFileSize,
+ formatRelativeDate,
+} from "./format";
describe("mobile formatters", () => {
it("formats card dates like Cap web", () => {
@@ -24,6 +29,14 @@ describe("mobile formatters", () => {
expect(formatDuration(7200)).toBe("2 hrs");
});
+ it("formats chapter times with hours from an hour on", () => {
+ expect(formatChapterTime(0)).toBe("0:00");
+ expect(formatChapterTime(95.7)).toBe("1:35");
+ expect(formatChapterTime(3599.9)).toBe("59:59");
+ expect(formatChapterTime(3600)).toBe("1:00:00");
+ expect(formatChapterTime(3905)).toBe("1:05:05");
+ });
+
it("formats native upload file sizes", () => {
expect(formatFileSize(null)).toBeNull();
expect(formatFileSize(0)).toBeNull();
diff --git a/apps/mobile/src/utils/format.ts b/apps/mobile/src/utils/format.ts
index a8b43469f..1713e6ae4 100644
--- a/apps/mobile/src/utils/format.ts
+++ b/apps/mobile/src/utils/format.ts
@@ -39,6 +39,16 @@ export const formatDuration = (seconds: number | null) => {
return "< 1 sec";
};
+export const formatChapterTime = (seconds: number) => {
+ const total = Math.max(0, Math.floor(seconds));
+ const hours = Math.floor(total / 3600);
+ const minutes = Math.floor(total / 60) % 60;
+ const secs = (total % 60).toString().padStart(2, "0");
+ return hours > 0
+ ? `${hours}:${minutes.toString().padStart(2, "0")}:${secs}`
+ : `${minutes}:${secs}`;
+};
+
export const formatFileSize = (bytes: number | null | undefined) => {
if (bytes === null || bytes === undefined || !Number.isFinite(bytes)) {
return null;