There are two issues:
The use of .weekOfMonth. This is not a "number of weeks". If the result had 21 days, this doesn't give 3, for example. Drop your use of .weekOfMonth since it is not a useful component for what you are trying to do.
The "strange" output is the result of your use of the DateComponentsFormatter. The formatter assumes a 28-day month. Just print the raw components.
If you change the line:
let result = formatter.string(from: components)!
to:
let result = "\(components)"
then you will get correct output (once you remove the use of .weekOfMonth.
57: year: 0 month: 1 day: 26
58: year: 0 month: 1 day: 27
59: year: 0 month: 1 day: 28
60: year: 0 month: 1 day: 29
61: year: 0 month: 2 day: 0
62: year: 0 month: 2 day: 1
63: year: 0 month: 2 day: 2
Topic:
App & System Services
SubTopic:
General
Tags: