Skip to content

Commit 9cb7c29

Browse files
authored
feat(ceremony): update time format (#3172)
2 parents dca70b4 + b8ef764 commit 9cb7c29

File tree

1 file changed

+28
-6
lines changed

1 file changed

+28
-6
lines changed

ceremony/src/lib/utils/utils.ts

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -94,16 +94,38 @@ export function msToTimeString(ms: number): string {
9494
}
9595

9696
export function formatWaitTime(minutes: number) {
97-
const hours = Math.floor(minutes / 60)
97+
const weeks = Math.floor(minutes / (7 * 24 * 60))
98+
const days = Math.floor((minutes % (7 * 24 * 60)) / (24 * 60))
99+
const hours = Math.floor((minutes % (24 * 60)) / 60)
98100
const remainingMinutes = Math.round(minutes % 60)
99101

100-
if (hours === 0) {
101-
return `${remainingMinutes} minute${remainingMinutes !== 1 ? "s" : ""}`
102+
const parts: Array<string> = []
103+
104+
if (weeks > 0) {
105+
parts.push(`${weeks} week${weeks !== 1 ? "s" : ""}`)
106+
}
107+
108+
if (days > 0) {
109+
parts.push(`${days} day${days !== 1 ? "s" : ""}`)
110+
}
111+
112+
if (hours > 0 && weeks === 0) {
113+
// Only show hours if less than a week
114+
parts.push(`${hours} hour${hours !== 1 ? "s" : ""}`)
115+
}
116+
117+
if (remainingMinutes > 0 && weeks === 0 && days === 0) {
118+
// Only show minutes if less than a day
119+
parts.push(`${remainingMinutes} minute${remainingMinutes !== 1 ? "s" : ""}`)
120+
}
121+
122+
if (parts.length === 0) {
123+
return "0 minutes"
102124
}
103125

104-
if (remainingMinutes === 0) {
105-
return `${hours} hour${hours !== 1 ? "s" : ""}`
126+
if (parts.length === 1) {
127+
return parts[0]
106128
}
107129

108-
return `${hours} hour${hours !== 1 ? "s" : ""} and ${remainingMinutes} minute${remainingMinutes !== 1 ? "s" : ""}`
130+
return `${parts.slice(0, -1).join(", ")} and ${parts[parts.length - 1]}`
109131
}

0 commit comments

Comments
 (0)