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:
@@ -65,12 +65,14 @@ extension Date {
|
|||||||
// MARK: - String to Date Extensions
|
// MARK: - String to Date Extensions
|
||||||
|
|
||||||
extension String {
|
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? {
|
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 {
|
func toFormattedDate() -> String {
|
||||||
guard let date = self.toDate() else { return self }
|
guard let date = self.toDate() else { return self }
|
||||||
return date.formatted()
|
return date.formatted()
|
||||||
|
|||||||
Reference in New Issue
Block a user