feat: add iOS support and harden receipt scanning
This commit is contained in:
25
app/ios/ScanReceipts/Support/ISO8601.swift
Normal file
25
app/ios/ScanReceipts/Support/ISO8601.swift
Normal file
@@ -0,0 +1,25 @@
|
||||
import Foundation
|
||||
|
||||
/// The backend serialises every timestamp with `Date.prototype.toISOString()`,
|
||||
/// which always includes milliseconds (`...307Z`). `ISO8601DateFormatter`'s
|
||||
/// default options reject that string, so every date in this app must go
|
||||
/// through this helper rather than a bare `ISO8601DateFormatter()` — using
|
||||
/// the wrong one is a silent-failure trap, not a compile error.
|
||||
enum ISO8601 {
|
||||
private static let withFractional: ISO8601DateFormatter = {
|
||||
let f = ISO8601DateFormatter()
|
||||
f.formatOptions = [.withInternetDateTime, .withFractionalSeconds]
|
||||
return f
|
||||
}()
|
||||
|
||||
private static let withoutFractional: ISO8601DateFormatter = {
|
||||
let f = ISO8601DateFormatter()
|
||||
f.formatOptions = [.withInternetDateTime]
|
||||
return f
|
||||
}()
|
||||
|
||||
static func parse(_ string: String?) -> Date? {
|
||||
guard let string else { return nil }
|
||||
return withFractional.date(from: string) ?? withoutFractional.date(from: string)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user