0

So the purpose is to create a month view calendar with collection view. Today is the starting point, so I will get the first and last day of month in calendar from today.

func setDate(date: Date) {
    let firstDate = date.start(of: .month)
    let lastDate = date.end(of: .month)
}

Say today is 2017-07-19, instead of first date return 25th of June it return 30th of June and last date return 31st of July instead of 5th of August.

I could solve this by using the pure Swift Date Library, but I believe that this task could be solved by DateTools. I just don't know how.

By the way I'm using Swift 3. DateTools Swift

Norak
  • 448
  • 1
  • 9
  • 22
  • 1
    Is 25th of June/ 5th of August what you *expect* as result? Why? – Martin R Jun 19 '17 at 06:47
  • You can find range (days) of two dates hear https://stackoverflow.com/questions/32536612/swift-print-all-dates-between-two-nsdate – Oleg Gordiichuk Jun 19 '17 at 06:48
  • @MartinR because in Calendar the start date of July 2017 is 25th of June not 1st of July. (Sunday is the first day of the week) – Norak Jun 19 '17 at 06:52
  • So what about calculating the start of month first, and use that to compute the start of the week? – Martin R Jun 19 '17 at 06:58
  • @MartinR Yes, that is what I'm doing now, but I just want to know if the DateToolsSwift library already provided this solution. – Norak Jun 19 '17 at 07:00

0 Answers0