I'm using JTAppleCalendar and each months date is 1 day ahead than it should be. This is my code for the configuration:
func configureCalendar(_ calendar: JTAppleCalendarView) -> ConfigurationParameters {
formatter.dateFormat = "yyyy MM dd"
formatter.timeZone = Calendar.current.timeZone
formatter.locale = Calendar.current.locale
let currentYear = Calendar.current.component(.year, from: Date())
let stringCurrentYear = String(currentYear)
let nextYear = currentYear + 1
let stringNextYear = String(nextYear)
let currentMonth = Calendar.current.component(.month, from: Date())
let stringCurrentMonth = String(currentMonth)
let startDate = formatter.date(from: "\(stringCurrentYear) \(stringCurrentMonth) 01")!
let endDate = formatter.date(from: "\(stringNextYear) 12 31")!
let parameters = ConfigurationParameters(startDate: startDate, endDate: endDate)
return parameters
}
This is the current output:
The 1st of January 2018 should be a Monday however is appearing as a Tuesday.
Found my own answer. I used the following code to fix it:
let parameters = ConfigurationParameters(
startDate: startDate,
endDate: endDate,
numberOfRows: 6,
calendar: calendar,
generateOutDates: .tillEndOfRow,
firstDayOfWeek: .monday
)
return parameters
I think the issue was that by default the first day of the week was by default Sunday. So setting it to Monday resolved the problem.