Some messy stuff cleaned up in Inventory UI
This commit is contained in:
@@ -1,6 +1,52 @@
|
||||
import SwiftUI
|
||||
import LabWiseKit
|
||||
|
||||
private let isoDateFormatter: ISO8601DateFormatter = {
|
||||
let f = ISO8601DateFormatter()
|
||||
f.formatOptions = [.withFullDate]
|
||||
return f
|
||||
}()
|
||||
|
||||
private let isoTimestampFormatter: ISO8601DateFormatter = {
|
||||
let f = ISO8601DateFormatter()
|
||||
f.formatOptions = [.withInternetDateTime, .withFractionalSeconds]
|
||||
return f
|
||||
}()
|
||||
|
||||
private let displayDateFormatter: DateFormatter = {
|
||||
let f = DateFormatter()
|
||||
f.dateStyle = .medium
|
||||
f.timeStyle = .none
|
||||
return f
|
||||
}()
|
||||
|
||||
private let displayTimestampFormatter: DateFormatter = {
|
||||
let f = DateFormatter()
|
||||
f.dateStyle = .medium
|
||||
f.timeStyle = .short
|
||||
return f
|
||||
}()
|
||||
|
||||
private func formatDate(_ iso: String?) -> String {
|
||||
guard let iso else { return "" }
|
||||
if let date = isoDateFormatter.date(from: iso) {
|
||||
return displayDateFormatter.string(from: date)
|
||||
}
|
||||
// Fallback: try full timestamp (e.g. "2025-03-01T00:00:00.000Z")
|
||||
if let date = isoTimestampFormatter.date(from: iso) {
|
||||
return displayDateFormatter.string(from: date)
|
||||
}
|
||||
return iso
|
||||
}
|
||||
|
||||
private func formatTimestamp(_ iso: String?) -> String {
|
||||
guard let iso else { return "" }
|
||||
if let date = isoTimestampFormatter.date(from: iso) {
|
||||
return displayTimestampFormatter.string(from: date)
|
||||
}
|
||||
return iso
|
||||
}
|
||||
|
||||
struct ChemicalDetailView: View {
|
||||
@State private var chemical: Chemical
|
||||
@State private var showEdit = false
|
||||
@@ -56,8 +102,8 @@ struct ChemicalDetailView: View {
|
||||
if let lot = chemical.lotNumber {
|
||||
LabeledContent("Lot #", value: lot)
|
||||
}
|
||||
if let exp = chemical.expirationDate {
|
||||
LabeledContent("Expiration", value: exp)
|
||||
if let exp = chemical.expirationDate, !exp.isEmpty {
|
||||
LabeledContent("Expiration", value: formatDate(exp))
|
||||
}
|
||||
if let barcode = chemical.barcode {
|
||||
LabeledContent("Barcode", value: barcode)
|
||||
@@ -76,10 +122,10 @@ struct ChemicalDetailView: View {
|
||||
|
||||
Section("Record") {
|
||||
if let created = chemical.createdAt {
|
||||
LabeledContent("Created", value: created)
|
||||
LabeledContent("Created", value: formatTimestamp(created))
|
||||
}
|
||||
if let updated = chemical.updatedAt {
|
||||
LabeledContent("Updated", value: updated)
|
||||
LabeledContent("Updated", value: formatTimestamp(updated))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user