Skip to content
Merged
Show file tree
Hide file tree
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
14 changes: 14 additions & 0 deletions src/__tests__/format.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,20 @@ describe("formatWindowLabel", () => {
it("returns Daily for 1440", () => {
expect(formatWindowLabel(1440)).toBe("Daily")
})

it("returns Monthly for 43200", () => {
expect(formatWindowLabel(43200)).toBe("Monthly")
})

it("returns Hourly for 60", () => {
expect(formatWindowLabel(60)).toBe("Hourly")
})

it("returns human-readable fallback for unknown durations", () => {
expect(formatWindowLabel(720)).toBe("12h")
expect(formatWindowLabel(2880)).toBe("2d")
expect(formatWindowLabel(30)).toBe("30m")
})
})

describe("getPercentColor", () => {
Expand Down
10 changes: 8 additions & 2 deletions src/format.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,16 @@ export function formatBar(

export function formatWindowLabel(windowDurationMins: number | null | undefined): string {
if (windowDurationMins == null) return "Unknown"
if (windowDurationMins === 60) return "Hourly"
if (windowDurationMins === 300) return "Session"
if (windowDurationMins === 10080) return "Weekly"
if (windowDurationMins === 1440) return "Daily"
if (windowDurationMins === 60) return "Hourly"
if (windowDurationMins === 10080) return "Weekly"
if (windowDurationMins === 43200) return "Monthly"

const totalHours = Math.floor(windowDurationMins / 60)
const days = Math.floor(totalHours / 24)
if (days > 0) return `${days}d`
if (totalHours > 0) return `${totalHours}h`
return `${windowDurationMins}m`
}

Expand Down
Loading