36
36
</template >
37
37
<script >
38
38
import pickerMixin from ' ~/mixins/pickerMixin.vue'
39
- import { isDateDisabled } from ' ~/utils/DisabledDatesUtils'
39
+ import DisabledDate from ' ~/utils/DisabledDate'
40
+ import HighlightedDate from ' ~/utils/HighlightedDate'
40
41
41
42
export default {
42
43
name: ' DatepickerDayView' ,
@@ -74,18 +75,16 @@ export default {
74
75
const monthName = this .showFullMonthName
75
76
? this .translation .months
76
77
: this .translation .monthsAbbr
77
- return this .utils .getMonthNameAbbr (
78
- this .utils .getMonth (this .pageDate ),
79
- monthName,
80
- )
78
+
79
+ return this .utils .getMonthNameAbbr (this .pageMonth , monthName)
81
80
},
82
81
/**
83
82
* Gets the name of the year that current page is on
84
- * @return {Number }
83
+ * @return {String }
85
84
*/
86
85
currYearName () {
87
86
const { yearSuffix } = this .translation
88
- return ` ${ this .utils . getFullYear ( this . pageDate ) }${ yearSuffix} `
87
+ return ` ${ this .pageYear }${ yearSuffix} `
89
88
},
90
89
/**
91
90
* Sets an array with all days to show this month
@@ -148,30 +147,25 @@ export default {
148
147
* @return {Boolean}
149
148
*/
150
149
isNextDisabled () {
151
- if (! this .disabledDates || ! this . disabledDates .from ) {
150
+ if (! this .disabledConfig . has .from ) {
152
151
return false
153
152
}
154
- const d = this .pageDate
155
153
return (
156
- this .utils .getMonth (this .disabledDates .from ) <=
157
- this .utils .getMonth (d) &&
158
- this .utils .getFullYear (this .disabledDates .from ) <=
159
- this .utils .getFullYear (d)
154
+ this .disabledConfig .from .month <= this .pageMonth &&
155
+ this .disabledConfig .from .year <= this .pageYear
160
156
)
161
157
},
162
158
/**
163
159
* Is the previous month disabled?
164
160
* @return {Boolean}
165
161
*/
166
162
isPreviousDisabled () {
167
- if (! this .disabledDates || ! this . disabledDates .to ) {
163
+ if (! this .disabledConfig . has .to ) {
168
164
return false
169
165
}
170
- const d = this .pageDate
171
166
return (
172
- this .utils .getMonth (this .disabledDates .to ) >= this .utils .getMonth (d) &&
173
- this .utils .getFullYear (this .disabledDates .to ) >=
174
- this .utils .getFullYear (d)
167
+ this .disabledConfig .to .month >= this .pageMonth &&
168
+ this .disabledConfig .to .year >= this .pageYear
175
169
)
176
170
},
177
171
/**
@@ -181,10 +175,24 @@ export default {
181
175
isYmd () {
182
176
return this .translation .ymd && this .translation .ymd === true
183
177
},
178
+ /**
179
+ * Returns the current page's month as an integer.
180
+ * @return {Number}
181
+ */
182
+ pageMonth () {
183
+ return this .utils .getMonth (this .pageDate )
184
+ },
184
185
nextPageDate () {
185
186
const d = new Date (this .pageTimestamp )
186
187
return new Date (this .utils .setMonth (d, this .utils .getMonth (d) + 1 ))
187
188
},
189
+ highlightedConfig () {
190
+ return new HighlightedDate (
191
+ this .utils ,
192
+ this .disabledDates ,
193
+ this .highlighted ,
194
+ ).config
195
+ },
188
196
},
189
197
methods: {
190
198
/**
@@ -227,66 +235,24 @@ export default {
227
235
* @return {Boolean}
228
236
*/
229
237
isDisabledDate (date ) {
230
- return isDateDisabled (date, this .disabledDates , this .utils )
238
+ return new DisabledDate (this .utils , this .disabledDates ).isDateDisabled (
239
+ date,
240
+ )
231
241
},
232
242
/**
233
243
* Whether a day is highlighted
234
244
* (only if it is not disabled already except when highlighted.includeDisabled is true)
235
245
* @param {Date} date to check if highlighted
236
246
* @return {Boolean}
237
247
*/
238
- // eslint-disable-next-line complexity,max-statements
239
248
isHighlightedDate (date ) {
240
- let highlighted = false
241
249
const dateWithoutTime = this .utils .resetDateTime (date)
242
- if (
243
- typeof this .highlighted === ' undefined' ||
244
- (! (this .highlighted && this .highlighted .includeDisabled ) &&
245
- this .isDisabledDate (dateWithoutTime))
246
- ) {
247
- return false
248
- }
249
-
250
- if (typeof this .highlighted .dates !== ' undefined' ) {
251
- this .highlighted .dates .forEach ((d ) => {
252
- if (this .utils .compareDates (dateWithoutTime, d)) {
253
- highlighted = true
254
- }
255
- })
256
- }
257
-
258
- const hasHighlightedTo =
259
- typeof this .highlighted .to !== ' undefined' &&
260
- dateWithoutTime <= this .highlighted .to
261
-
262
- const hasHighlightedFrom =
263
- typeof this .highlighted .from !== ' undefined' &&
264
- dateWithoutTime >= this .highlighted .from
265
-
266
- const hasHighlightedDays =
267
- typeof this .highlighted .days !== ' undefined' &&
268
- this .highlighted .days .indexOf (this .utils .getDay (dateWithoutTime)) !== - 1
269
250
270
- const hasHighlightedDaysOfMonth =
271
- typeof this .highlighted .daysOfMonth !== ' undefined' &&
272
- this .highlighted .daysOfMonth .indexOf (
273
- this .utils .getDate (dateWithoutTime),
274
- ) !== - 1
275
-
276
- const hasCustomPredictor =
277
- typeof this .highlighted .customPredictor === ' function' &&
278
- this .highlighted .customPredictor (dateWithoutTime)
279
-
280
- if (
281
- hasHighlightedDays ||
282
- hasHighlightedDaysOfMonth ||
283
- hasCustomPredictor ||
284
- (hasHighlightedTo && hasHighlightedFrom)
285
- ) {
286
- highlighted = true
287
- }
288
-
289
- return highlighted
251
+ return new HighlightedDate (
252
+ this .utils ,
253
+ this .disabledDates ,
254
+ this .highlighted ,
255
+ ).isDateHighlighted (dateWithoutTime)
290
256
},
291
257
/**
292
258
* Whether a day is highlighted and it is the last date
@@ -295,14 +261,13 @@ export default {
295
261
* @return {Boolean}
296
262
*/
297
263
isHighlightEnd (date ) {
264
+ const config = this .highlightedConfig
265
+
298
266
return (
299
267
this .isHighlightedDate (date) &&
300
- this .highlighted .to instanceof Date &&
301
- this .utils .getFullYear (this .highlighted .to ) ===
302
- this .utils .getFullYear (date) &&
303
- this .utils .getMonth (this .highlighted .to ) ===
304
- this .utils .getMonth (date) &&
305
- this .utils .getDate (this .highlighted .to ) === this .utils .getDate (date)
268
+ config .to .year === this .utils .getFullYear (date) &&
269
+ config .to .month === this .utils .getMonth (date) &&
270
+ config .to .day === this .utils .getDate (date)
306
271
)
307
272
},
308
273
/**
@@ -312,14 +277,13 @@ export default {
312
277
* @return {Boolean}
313
278
*/
314
279
isHighlightStart (date ) {
280
+ const config = this .highlightedConfig
281
+
315
282
return (
316
283
this .isHighlightedDate (date) &&
317
- this .highlighted .from instanceof Date &&
318
- this .utils .getFullYear (this .highlighted .from ) ===
319
- this .utils .getFullYear (date) &&
320
- this .utils .getMonth (this .highlighted .from ) ===
321
- this .utils .getMonth (date) &&
322
- this .utils .getDate (this .highlighted .from ) === this .utils .getDate (date)
284
+ config .from .year === this .utils .getFullYear (date) &&
285
+ config .from .month === this .utils .getMonth (date) &&
286
+ config .from .day === this .utils .getDate (date)
323
287
)
324
288
},
325
289
/**
0 commit comments