Swift date conversion for islamic calendar is wrong in specific timezone

The Islamic calendar is updating ongoing (with the moon phase). For example Ramadan could have 1 less or more days. But it can’t be predicted and it turns out at the end of the month itself. So the following code will not work correctly some times:

func islamicDate(of formattedDate: String) -> String {     let timezone = TimeZone(abbreviation: "IRST")!      // Get the date     var inputCalendar = Calendar(identifier: .persian)     inputCalendar.timeZone = timezone      let inputFormatter = DateFormatter()     inputFormatter.calendar = inputCalendar     inputFormatter.dateFormat = "yyyy/MM/dd"     inputFormatter.timeZone = timezone      let date = inputFormatter.date(from: formattedDate)!      // Convert the date     var outputCalendar = Calendar(identifier: .islamic)     outputCalendar.timeZone = timezone      let outputFormatter = DateFormatter()     outputFormatter.calendar = outputCalendar     outputFormatter.dateFormat = "dd MMMM"     outputCalendar.timeZone = timezone     let outputFormattedDate = outputFormatter.string(from: date)      return outputFormattedDate } 

for example, giving 1399/06/04 will result in:

06 Muharram

but expected to be

05 Muharram

Although it’s correct in the other timezones, it’s incorrect in the IRST. How is this can be sync with the current time adjastment of the timezone?

Add Comment
0 Answer(s)

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.