Skip to content

Commit 3cc190f

Browse files
committed
extract DatePeriod date as time
1 parent 928d6f4 commit 3cc190f

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

src/domain/entities/DatePeriod.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,22 +41,18 @@ export class DatePeriod extends Struct<DatePeriodAttrs>() {
4141
return [];
4242
}
4343

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");
5046

51-
if (!allStartTimes.length || !allEndTime.length) {
47+
if (!allStartTimes.length || !allEndTimes.length) {
5248
return [];
5349
}
5450

5551
const startDate = new Date(startDateStr);
5652
const endDate = new Date(endDateStr);
5753

5854
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()));
6056

6157
const startYear = startDate.getFullYear();
6258
const startMonth = startDate.getMonth();
@@ -78,6 +74,12 @@ export class DatePeriod extends Struct<DatePeriodAttrs>() {
7874
.value();
7975
}
8076

77+
private extractPeriodDateAsTimes<K extends "startDate" | "endDate">(field: K) {
78+
return _(this.periods)
79+
.compactMap(p => stringToTime(p[field]))
80+
.value();
81+
}
82+
8183
generatePeriods(config: DataPeriodConfig): DatePeriod["periods"] {
8284
const { startDate, endDate, periods, years } = this;
8385

0 commit comments

Comments
 (0)