Meshtastic-Apple/Meshtastic/Views/Helpers/DateTimeText.swift

39 lines
895 B
Swift
Raw Permalink Normal View History

//
// DateTimeText.swift
// Meshtastic Apple
//
// Copyright(C) Garth Vander Houwen 5/30/22.
//
import SwiftUI
//
// LastHeardText.swift
// Meshtastic Apple
//
// Created by Garth Vander Houwen on 5/25/22.
//
struct DateTimeText: View {
var dateTime: Date?
2023-03-06 10:33:18 -08:00
let sixMonthsAgo = Calendar.current.date(byAdding: .month, value: -6, to: Date())
2023-09-07 23:38:53 -07:00
let localeDateFormat = DateFormatter.dateFormat(fromTemplate: "yyMMddjmmssa", options: 0, locale: Locale.current)
var body: some View {
2023-09-07 23:38:53 -07:00
let dateFormatString = (localeDateFormat ?? "MM/dd/YY j:mm:ss a")
2023-03-06 10:33:18 -08:00
2023-09-07 23:38:53 -07:00
if dateTime != nil && dateTime! >= sixMonthsAgo! {
Text(" \(dateTime!.formattedDate(format: dateFormatString))")
} else {
2025-05-03 08:58:33 -07:00
Text("Unknown Age")
}
}
}
Add missing SwiftUI #Preview blocks across 65 views (#1649) * Add SwiftUI previews for simple helper views Agent-Logs-Url: https://github.com/meshtastic/Meshtastic-Apple/sessions/a2a43e8c-24fd-443a-8a98-13b678770edd Co-authored-by: garthvh <1795163+garthvh@users.noreply.github.com> * Add previews for action buttons, ChannelForm, MetricsColumnDetail, and DeviceOnboarding Agent-Logs-Url: https://github.com/meshtastic/Meshtastic-Apple/sessions/a2a43e8c-24fd-443a-8a98-13b678770edd Co-authored-by: garthvh <1795163+garthvh@users.noreply.github.com> * Add previews for config views, log views, AppLog, Firmware, AppData, and UserConfig Agent-Logs-Url: https://github.com/meshtastic/Meshtastic-Apple/sessions/a2a43e8c-24fd-443a-8a98-13b678770edd Co-authored-by: garthvh <1795163+garthvh@users.noreply.github.com> * Add preview for PositionConfig Agent-Logs-Url: https://github.com/meshtastic/Meshtastic-Apple/sessions/a2a43e8c-24fd-443a-8a98-13b678770edd Co-authored-by: garthvh <1795163+garthvh@users.noreply.github.com> * Fix formatting bugs in #Preview blocks: restore missing .environmentObject/.environment modifiers and add proper tab indentation Agent-Logs-Url: https://github.com/meshtastic/Meshtastic-Apple/sessions/7eeb7a54-7928-466f-8e39-b00d0012a09d Co-authored-by: garthvh <1795163+garthvh@users.noreply.github.com> * Linting fixes --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: garthvh <1795163+garthvh@users.noreply.github.com> Co-authored-by: Garth Vander Houwen <garthvh@yahoo.com>
2026-04-04 18:02:32 -07:00
#Preview {
VStack {
DateTimeText(dateTime: Date())
DateTimeText(dateTime: Calendar.current.date(byAdding: .day, value: -1, to: Date()))
DateTimeText(dateTime: nil)
}
}