Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(ceremony): update time format #3172

Merged
merged 2 commits into from
Oct 30, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 28 additions & 6 deletions ceremony/src/lib/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,16 +94,38 @@ export function msToTimeString(ms: number): string {
}

export function formatWaitTime(minutes: number) {
const hours = Math.floor(minutes / 60)
const weeks = Math.floor(minutes / (7 * 24 * 60))
const days = Math.floor((minutes % (7 * 24 * 60)) / (24 * 60))
const hours = Math.floor((minutes % (24 * 60)) / 60)
const remainingMinutes = Math.round(minutes % 60)

if (hours === 0) {
return `${remainingMinutes} minute${remainingMinutes !== 1 ? "s" : ""}`
const parts: Array<string> = []

if (weeks > 0) {
parts.push(`${weeks} week${weeks !== 1 ? "s" : ""}`)
}

if (days > 0) {
parts.push(`${days} day${days !== 1 ? "s" : ""}`)
}

if (hours > 0 && weeks === 0) {
// Only show hours if less than a week
parts.push(`${hours} hour${hours !== 1 ? "s" : ""}`)
}

if (remainingMinutes > 0 && weeks === 0 && days === 0) {
// Only show minutes if less than a day
parts.push(`${remainingMinutes} minute${remainingMinutes !== 1 ? "s" : ""}`)
}

if (parts.length === 0) {
return "0 minutes"
}

if (remainingMinutes === 0) {
return `${hours} hour${hours !== 1 ? "s" : ""}`
if (parts.length === 1) {
return parts[0]
}

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