'Adding month not working as expected - Swift

I am trying to add a month to a date. What I need to code that takes one date, and then returns that date as an object and also that date as an object + 1 month later. See my current code below:

let dateFormatter = DateFormatter()
dateFormatter.timeZone = .current
dateFormatter.dateFormat = "yyyy/MM/d"
stringDateMinimum = "2022-03-01"
let minimimDate = dateFormatter.date(from: stringDateMinimum)
print(minimimDate ?? "")       
var maximumDate =  Calendar.current.date(byAdding: .month, value: 1, to: minimimDate!)!
print(maximumDate)

I expected the output to be:

2022-03-01 00:00:00 +0000
2022-04-01 00:00:00 +0000

But I actually got:

2022-03-01 00:00:00 +0000
2022-03-31 23:00:00 +0000

Could I think this could be because of the UK summer time as this problem only happens in march



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source