Fix date parsing to handle ISO datetime format

The toDate() extension was only parsing "yyyy-MM-dd" format, causing
ISO datetime strings like "2025-01-02T00:00:00Z" to fail parsing and
display as raw strings. Now extracts the date part before the "T"
before parsing.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Trey t
2025-12-19 21:15:12 -06:00
parent 59cbc60668
commit 4d9d8d8e45

View File

@@ -65,12 +65,14 @@ extension Date {
// MARK: - String to Date Extensions
extension String {
/// Converts API date string (yyyy-MM-dd) to Date
/// Converts API date string (yyyy-MM-dd or ISO datetime) to Date
func toDate() -> Date? {
DateFormatters.shared.apiDate.date(from: self)
// Extract date part if it includes time (e.g., "2025-01-02T00:00:00Z" -> "2025-01-02")
let datePart = self.components(separatedBy: "T").first ?? self
return DateFormatters.shared.apiDate.date(from: datePart)
}
/// Converts API date string to formatted display string
/// Converts API date string to formatted display string (e.g., "Jan 2, 2025")
func toFormattedDate() -> String {
guard let date = self.toDate() else { return self }
return date.formatted()