I have been working on a travel app that records transactions. I was surprised recently to see the transaction entry date and time changing with travel across one or more time zone. For example, if I record a lunch expense in Frankfurt that occurred on May 12 at 18:05 (6:05 pm) Central European Summer Time. Then later upon return to the United States west coast (Pacific Daylight Time), I view the transaction in my travel app the transaction is displayed as occurring on May 12 at 09:05 in the morning.
I would like to maintain the original transaction date and time (May 12 18:05) no matter where the user happens to be located.
I'm guessing that I somehow need to save off the transaction timezone and apply that to the date / time upon display of the transaction. How do I do this?
I'm using DatePicker to get the current date:
DatePicker("", selection: $entryDT, in: ...Date())
.datePickerStyle(CompactDatePickerStyle())
I'm using the iOS 15 date formatting technique to display the date and time:
let hDate = item.entryDT ?? Date()
Text(hDate.formatted(.dateTime.day().month(.wide).year().hour().minute()))