From 8cd68a72f9284b54fc6b5613d3cbb733b58c5df7 Mon Sep 17 00:00:00 2001 From: Shafqat Muneer Date: Sat, 20 Apr 2024 02:18:19 +0500 Subject: [PATCH] fix: Maintain calendar toggle and local calendar event mapping --- 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()