-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUsageData.swift
More file actions
32 lines (28 loc) · 819 Bytes
/
Copy pathUsageData.swift
File metadata and controls
32 lines (28 loc) · 819 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import Foundation
struct UsageData: Equatable {
let session: UsageWindow
let week: UsageWindow
let planType: String?
let limitID: String?
let rateLimitReachedType: String?
let eventTimestamp: Date
let lastUpdated: Date
let sourcePath: String?
}
struct UsageWindow: Equatable {
let utilization: Double
let resetsAt: Date
let windowMinutes: Int?
var displayPercent: Int { Int((utilization * 100).rounded()) }
var safeValue: Double { min(max(utilization, 0), 1) }
var durationLabel: String {
guard let minutes = windowMinutes else { return "" }
if minutes % (24 * 60) == 0 {
return "\(minutes / (24 * 60))d"
}
if minutes % 60 == 0 {
return "\(minutes / 60)h"
}
return "\(minutes)m"
}
}