I'm trying to find the first day of the month. There have been different solutions posted here on SO (e.g. this)
When analyzing them it seems like the day component is being ignored.
Instead of returning the first day of the month
Calendar.current.date(from: Calendar.current.dateComponents([.year, .month], from: Calendar.current.startOfDay(for: self)))!
it returns the current day but changes the month:
(lldb) po Calendar.current.date(from: Calendar.current.dateComponents([.year, .month], from: Calendar.current.startOfDay(for: self)))!
▿ 2019-02-28 23:00:00 +0000
- timeIntervalSinceReferenceDate : 573087600.0
(lldb) po self
▿ 2019-03-28 01:09:17 +0000
- timeIntervalSinceReferenceDate : 575428157.663583
I've also looked into setting the components by hand:
var components = Calendar.current.dateComponents([.year, .month, .day], from: self)
components.setValue(1, for: .day)
let value = Calendar.current.date(from: components)!
which results in the same:
(lldb) po value
▿ 2019-02-28 23:00:00 +0000
- timeIntervalSinceReferenceDate : 573087600.0
Am I doing something wrong? Or is this a bug in Calendar?
Apple Swift version 5.0.1 (swiftlang-1001.0.82.4 clang-1001.0.46.5)
Target: x86_64-apple-darwin18.6.0
Oh in case this is interesting I'm developing for macOS but as far as I can see, this API is not influenced by Catalina.