@@ -121,46 +121,56 @@ extension JTACMonthView {
121
121
}
122
122
}
123
123
124
- func setupMonthInfoDataForStartAndEndDate( with config : ConfigurationParameters ? = nil ) -> CalendarData {
124
+ func setupMonthInfoDataForStartAndEndDate( with optionalConfig : ConfigurationParameters ? = nil ) -> CalendarData {
125
125
var months = [ Month] ( )
126
126
var monthMap = [ Int: Int] ( )
127
127
var totalSections = 0
128
128
var totalDays = 0
129
129
130
- var validConfig = config
131
- if validConfig == nil { validConfig = calendarDataSource? . configureCalendar ( self ) }
132
- if let validConfig = validConfig {
133
- let comparison = validConfig. calendar. compare ( validConfig. startDate, to: validConfig. endDate, toGranularity: . nanosecond)
134
- if comparison == ComparisonResult . orderedDescending {
135
- assert ( false , " Error, your start date cannot be greater than your end date \n " )
136
- return ( CalendarData ( months: [ ] , totalSections: 0 , sectionToMonthMap: [ : ] , totalDays: 0 ) )
137
- }
138
-
139
- // Set the new cache
140
- _cachedConfiguration = validConfig
130
+
131
+ // first use the config passed in
132
+ // If nil, fetch the config from the datasource
133
+ let possibleConfig = optionalConfig ?? calendarDataSource? . configureCalendar ( self )
134
+
135
+ let validConfig : ConfigurationParameters
136
+ if let valid = possibleConfig {
137
+ validConfig = valid
138
+ } else {
139
+ assert ( false , " Using default parameters. Your config should not have been nil here. In production, your dates will be an incorrect default date " )
140
+ validConfig = ConfigurationParameters ( startDate: Date ( ) , endDate: Date ( ) )
141
+ }
142
+
143
+ let comparison = validConfig. calendar. compare ( validConfig. startDate, to: validConfig. endDate, toGranularity: . nanosecond)
144
+ if comparison == ComparisonResult . orderedDescending {
145
+ assert ( false , " Error, your start date cannot be greater than your end date \n " )
146
+ return ( CalendarData ( months: [ ] , totalSections: 0 , sectionToMonthMap: [ : ] , totalDays: 0 ) )
147
+ }
148
+
149
+ // Set the new cache
150
+ _cachedConfiguration = validConfig
151
+
152
+ if let
153
+ startMonth = calendar. startOfMonth ( for: validConfig. startDate) ,
154
+ let endMonth = calendar. endOfMonth ( for: validConfig. endDate) {
155
+ startOfMonthCache = startMonth
156
+ endOfMonthCache = endMonth
157
+ // Create the parameters for the date format generator
158
+ let parameters = ConfigurationParameters ( startDate: startOfMonthCache,
159
+ endDate: endOfMonthCache,
160
+ numberOfRows: validConfig. numberOfRows,
161
+ calendar: calendar,
162
+ generateInDates: validConfig. generateInDates,
163
+ generateOutDates: validConfig. generateOutDates,
164
+ firstDayOfWeek: validConfig. firstDayOfWeek,
165
+ hasStrictBoundaries: validConfig. hasStrictBoundaries)
141
166
142
- if let
143
- startMonth = calendar. startOfMonth ( for: validConfig. startDate) ,
144
- let endMonth = calendar. endOfMonth ( for: validConfig. endDate) {
145
- startOfMonthCache = startMonth
146
- endOfMonthCache = endMonth
147
- // Create the parameters for the date format generator
148
- let parameters = ConfigurationParameters ( startDate: startOfMonthCache,
149
- endDate: endOfMonthCache,
150
- numberOfRows: validConfig. numberOfRows,
151
- calendar: calendar,
152
- generateInDates: validConfig. generateInDates,
153
- generateOutDates: validConfig. generateOutDates,
154
- firstDayOfWeek: validConfig. firstDayOfWeek,
155
- hasStrictBoundaries: validConfig. hasStrictBoundaries)
156
-
157
- let generatedData = dateGenerator. setupMonthInfoDataForStartAndEndDate ( parameters)
158
- months = generatedData. months
159
- monthMap = generatedData. monthMap
160
- totalSections = generatedData. totalSections
161
- totalDays = generatedData. totalDays
162
- }
167
+ let generatedData = dateGenerator. setupMonthInfoDataForStartAndEndDate ( parameters)
168
+ months = generatedData. months
169
+ monthMap = generatedData. monthMap
170
+ totalSections = generatedData. totalSections
171
+ totalDays = generatedData. totalDays
163
172
}
173
+
164
174
let data = CalendarData ( months: months, totalSections: totalSections, sectionToMonthMap: monthMap, totalDays: totalDays)
165
175
return data
166
176
}
0 commit comments