Truncate Date to Calendar.Component in Swift

from blog Hearthside by Caleb Hearth, | ↗ original
↗ original
I’m frequently wanting to work with truncated dates in Swift apps, especially when dealing with Swift Charts. Foundation provides Calendar.startOfDay(for:) to get the first moment of a day, and that’s been really useful. The extension below will do something similar for an arbitrary1 ...