From a0c4c1778d16a4a8c7cc204c0fc00011b4134785 Mon Sep 17 00:00:00 2001 From: Shafqat Muneer Date: Mon, 22 Apr 2024 16:05:32 +0500 Subject: [PATCH] fix: Maintain calendar toggle and local calendar event mapping (#411) --- Core/Core/Extensions/DateExtension.swift | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Core/Core/Extensions/DateExtension.swift b/Core/Core/Extensions/DateExtension.swift index ca1a7d73b..8a57079f4 100644 --- a/Core/Core/Extensions/DateExtension.swift +++ b/Core/Core/Extensions/DateExtension.swift @@ -11,6 +11,7 @@ import Foundation public extension Date { init(iso8601: String) { let formats = ["yyyy-MM-dd'T'HH:mm:ssZ", "yyyy-MM-dd'T'HH:mm:ss.SSSSSSZ"] + let calender = Calendar.current var date: Date var dateFormatter: DateFormatter? dateFormatter = DateFormatter() @@ -18,7 +19,12 @@ public extension Date { date = formats.compactMap { format in dateFormatter?.dateFormat = format - return dateFormatter?.date(from: iso8601) + guard let formattedDate = dateFormatter?.date(from: iso8601) else { return nil } + let components = calender.dateComponents( + [.year, .month, .day, .hour, .minute, .second], + from: formattedDate + ) + return calender.date(from: components) } .first ?? Date()