I am searching for a method to fill a Set
with the weeks that maintain the primary of any month for the present yr. For instance, because the first week of the yr usually holds the primary day in January, I might merely add it to the SET as a 1, after which I might test for every other weeks within the yr that holds the primary of any month and add it to the SET as nicely. My present drawback is discovering out a method to test what weeks maintain the primary of any month within the present yr. I assumed at first of getting the primary and final day of the a month however I’ve began to confuse myself at this level. Any assist can be appreciated.
extension Date {
func getStart(of part: Calendar.Element, calendar: Calendar = Calendar.present) -> Date? {
return calendar.dateInterval(of: part, for: self)?.begin
}
func getEnd(of part: Calendar.Element, calendar: Calendar = Calendar.present) -> Date? {
return calendar.dateInterval(of: part, for: self)?.finish
}
}
Purpose: 2023, Set = (1,5,9…and so on)