@@ -41,22 +41,18 @@ export class DatePeriod extends Struct<DatePeriodAttrs>() {
41
41
return [ ] ;
42
42
}
43
43
44
- const allStartTimes = _ ( periods )
45
- . compactMap ( p => stringToTime ( p . startDate ) )
46
- . value ( ) ;
47
- const allEndTime = _ ( periods )
48
- . compactMap ( p => stringToTime ( p . endDate ) )
49
- . value ( ) ;
44
+ const allStartTimes = this . extractPeriodDateAsTimes ( "startDate" ) ;
45
+ const allEndTimes = this . extractPeriodDateAsTimes ( "endDate" ) ;
50
46
51
- if ( ! allStartTimes . length || ! allEndTime . length ) {
47
+ if ( ! allStartTimes . length || ! allEndTimes . length ) {
52
48
return [ ] ;
53
49
}
54
50
55
51
const startDate = new Date ( startDateStr ) ;
56
52
const endDate = new Date ( endDateStr ) ;
57
53
58
54
const openingDate = new Date ( Math . min ( ...allStartTimes , startDate . getTime ( ) ) ) ;
59
- const closingDate = new Date ( Math . max ( ...allEndTime , endDate . getTime ( ) ) ) ;
55
+ const closingDate = new Date ( Math . max ( ...allEndTimes , endDate . getTime ( ) ) ) ;
60
56
61
57
const startYear = startDate . getFullYear ( ) ;
62
58
const startMonth = startDate . getMonth ( ) ;
@@ -78,6 +74,12 @@ export class DatePeriod extends Struct<DatePeriodAttrs>() {
78
74
. value ( ) ;
79
75
}
80
76
77
+ private extractPeriodDateAsTimes < K extends "startDate" | "endDate" > ( field : K ) {
78
+ return _ ( this . periods )
79
+ . compactMap ( p => stringToTime ( p [ field ] ) )
80
+ . value ( ) ;
81
+ }
82
+
81
83
generatePeriods ( config : DataPeriodConfig ) : DatePeriod [ "periods" ] {
82
84
const { startDate, endDate, periods, years } = this ;
83
85
0 commit comments