When searching .forward, and only specifying a month in the date components, we expect to get the next start of the month. So if I request the nextDate that matches December after December the 12th in 2023, I expect to get December the 1st in 2024. This is the actual result provided by the nextDate method.
On the contrary, when we search .backward, and we only specify a month, I expect to get the last day of the specified month, not the first one. To me, the next date that matches only a month when searching backward is the last day (first day encountering the specified month if we go back day by day). Maybe this is for another topic.
Anyway, let's assume I'm wrong and the expected date is still the start of the month. I tested with other date components to see if the dates provided by these methods are correct when searching backward. I tested using a .nextTime and .strict matchingPolicy.
DateComponents(month: 1)
Correct years, wrong days. I mainly get dates around January the 5th. But the years seem to be correct. In this case, only the America/Los_Angeles date seems to be correct. Even GMT is wrong.
- 2023-01-05 00:00:00 +0000 for Europe/London
- 2023-01-04 23:00:00 +0000 for Europe/Paris
- 2023-01-04 22:00:00 +0000 for Europe/Vilnius
- 2023-01-01 08:00:00 +0000 for America/Los_Angeles
- 2023-01-05 00:00:00 +0000 for GMT
DateComponents(month: 2)
Correct years, correct days
DateComponents(month: 3)
Correct years, wrong days
DateComponents(month: 4)
Correct years, correct days
DateComponents(month: 5)
Correct years, wrong days. I mainly get dates around May the 3rd.
- 2023-05-02 23:00:00 +0000 for Europe/London
- 2023-05-02 22:00:00 +0000 for Europe/Paris
- 2023-05-02 21:00:00 +0000 for Europe/Vilnius
- 2023-05-03 07:00:00 +0000 for America/Los_Angeles
- 2023-05-03 00:00:00 +0000 for GMT
DateComponents(month: 6)
Correct years, correct days
DateComponents(month: 7)
Correct years, wrong days
DateComponents(month: 8)
Correct years, wrong days
DateComponents(month: 9)
Wrong years, correct days
DateComponents(month: 10)
Correct years, wrong days
DateComponents(month: 11)
Correct years, correct days
DateComponents(month: 12)
Correct years, correct days if we expect to get the start of the December from the previous year when we already are in December (and not the start of the current month).
If I additionally specify a day in the date components like DateComponents(month: 1, day: 1) or DateComponents(month: 4, day: 20), I get the correct results for all time zones, except for September (still wrong years).