- Migrate from SwiftData to CoreData with CloudKit sync - Add core models: Split, Exercise, Workout, WorkoutLog - Implement tab-based UI: Workout Logs, Splits, Settings - Add SF Symbols picker for split icons - Add exercise picker filtered by split with exclusion of added exercises - Integrate IndieAbout for settings/about section - Add Yams for YAML exercise definition parsing - Include starter exercise libraries (bodyweight, Planet Fitness) - Add Date extensions for formatting (formattedTime, isSameDay) - Format workout date ranges to show time-only for same-day end dates - Add build number update script - Add app icons
57 lines
1.5 KiB
Swift
57 lines
1.5 KiB
Swift
import Foundation
|
|
|
|
extension Date {
|
|
func formattedDate() -> String {
|
|
let formatter = DateFormatter()
|
|
formatter.dateStyle = .short
|
|
formatter.timeStyle = .short
|
|
return formatter.string(from: self)
|
|
}
|
|
|
|
func formattedTime() -> String {
|
|
let formatter = DateFormatter()
|
|
formatter.dateStyle = .none
|
|
formatter.timeStyle = .short
|
|
return formatter.string(from: self)
|
|
}
|
|
|
|
func isSameDay(as other: Date) -> Bool {
|
|
Calendar.current.isDate(self, inSameDayAs: other)
|
|
}
|
|
|
|
func formatDate() -> String {
|
|
let formatter = DateFormatter()
|
|
formatter.dateStyle = .medium
|
|
formatter.timeStyle = .none
|
|
return formatter.string(from: self)
|
|
}
|
|
|
|
var abbreviatedMonth: String {
|
|
let formatter = DateFormatter()
|
|
formatter.dateFormat = "MMM"
|
|
return formatter.string(from: self)
|
|
}
|
|
|
|
var dayOfMonth: Int {
|
|
Calendar.current.component(.day, from: self)
|
|
}
|
|
|
|
var abbreviatedWeekday: String {
|
|
let formatter = DateFormatter()
|
|
formatter.dateFormat = "EEE"
|
|
return formatter.string(from: self)
|
|
}
|
|
|
|
func humanTimeInterval(to other: Date) -> String {
|
|
let interval = other.timeIntervalSince(self)
|
|
let hours = Int(interval) / 3600
|
|
let minutes = (Int(interval) % 3600) / 60
|
|
|
|
if hours > 0 {
|
|
return "\(hours)h \(minutes)m"
|
|
} else {
|
|
return "\(minutes)m"
|
|
}
|
|
}
|
|
}
|