in a mock json file, I receive separated date, start hour, end hour, so I need to merge date and a start date, then doing the same with end date. Before, I had a date like this:
23/03/2022
and code worked, now I have this, which is causing old code to crash:
"2021-06-25T07:50:56.970Z”
the portion of the object from with I get date and the hours I need
"date": "2021-06-25T07:50:56.970Z",
"time": {
"from": "17:00",
"to": "18:00"
}
code in which such date was manipulated:
public class ShortDateTimeFormatter: DateFormatter {
override public init() {
super.init()
self.dateFormat = "dd/MM/yyyy HH:mm"
}
required public init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}
used here as let
private let shortTimeFormatter = ShortDateTimeFormatter()
called here
if let startTime = hours.from,
let startDate = date.concats(startTime),
let start = self.shortTimeFormatter.date(from: startDate) {
event.startDate = start
event.addAlarm(EKAlarm(absoluteDate: start.dayBefore))
event.addAlarm(EKAlarm(absoluteDate: start.halfHourBefore))
event.endDate = start.hourAfter
}
if let endTime = hours.to,
let endDate = date.concats(endTime),
let end = self.shortTimeFormatter.date(from: endDate) {
event.endDate = end
}
eventually, used here
guard let url = URL(string: "calshow:\(event.startDate.timeIntervalSinceReferenceDate)") else { return }
how can I put together a date I can use now? in other way, I think I need to get day/month/year from “2021-06-25T07:50:56.970Z” put tighter a format like the "old date" and go on. or maybe a different way to handle it is needed.