@@ -90,6 +90,39 @@ extension Notification.Name {
90
90
static let handleIncomingURL = Notification . Name ( " handleIncomingURL " )
91
91
}
92
92
93
+ extension TimeInterval {
94
+ /// Formats a TimeInterval into `hh:mm:ss` or `mm:ss`
95
+ func formattedTime( ) -> String {
96
+ let hours = Int ( self ) / 3600
97
+ let minutes = ( Int ( self ) % 3600 ) / 60
98
+ let seconds = Int ( self ) % 60
99
+
100
+ if hours > 0 {
101
+ return String ( format: " %02d:%02d:%02d " , hours, minutes, seconds)
102
+ } else {
103
+ return String ( format: " %02d:%02d " , minutes, seconds)
104
+ }
105
+ }
106
+
107
+ // func to format time to a string with "minutes" or "seconds" or "hourds" depending on the time
108
+ func formattedTimeUnit( ) -> String {
109
+ let hours = Int ( self ) / 3600
110
+ let minutes = ( Int ( self ) % 3600 ) / 60
111
+ let seconds = Int ( self ) % 60
112
+
113
+ if hours > 0 {
114
+ let hourUnit = hours == 1 ? " hour " : " hours "
115
+ return String ( format: " %d \( hourUnit) " , hours)
116
+ } else if minutes > 0 {
117
+ let minuteUnit = minutes == 1 ? " minute " : " minutes "
118
+ return String ( format: " %d \( minuteUnit) " , minutes)
119
+ } else {
120
+ let secondUnit = seconds == 1 ? " second " : " seconds "
121
+ return String ( format: " %d \( secondUnit) " , seconds)
122
+ }
123
+ }
124
+ }
125
+
93
126
extension Color {
94
127
// Orange shades
95
128
static let orangeLight = Color ( hue: 0.1 , saturation: 0.9 , brightness: 0.75 ) // Softer orange for light mode
@@ -102,4 +135,4 @@ extension Color {
102
135
103
136
// Gray shades - darker gray for light mode
104
137
static let grayLight = Color ( hue: 0 , saturation: 0 , brightness: 0.3 )
105
- }
138
+ }
0 commit comments