Skip to content

Commit 484cbb4

Browse files
Thomas FinkThomas Fink
authored andcommitted
fix(ZMS-3466): improve hours selection
1 parent 088356f commit 484cbb4

File tree

3 files changed

+32
-10
lines changed

3 files changed

+32
-10
lines changed

zmsadmin/js/page/availabilityDay/form/datepicker.js

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -256,13 +256,19 @@ class AvailabilityDatePicker extends Component
256256
return className;
257257
}
258258

259-
/*
260259
const filterPassedTime = (time) => {
261-
const currentDate = this.state.selectedDate;
262-
const selectedDate = new Date(time);
263-
return currentDate.getTime() < selectedDate.getTime();
264-
};
260+
if (!moment(this.state.selectedDate).isSame(moment.unix(this.props.attributes.today), 'day')) {
261+
return true;
262+
}
263+
264+
const currentTime = moment();
265+
const timeToCheck = moment(time);
266+
267+
return timeToCheck.hour() > currentTime.hour() ||
268+
(timeToCheck.hour() === currentTime.hour() && timeToCheck.minute() > currentTime.minute());
269+
};
265270

271+
/*
266272
const isWeekday = date => {
267273
const day = date.getDay();
268274
return day !== 0 && day !== 6;
@@ -337,7 +343,7 @@ class AvailabilityDatePicker extends Component
337343
minTime={this.state.minTime}
338344
maxTime={this.state.maxTime}
339345
excludeTimes={this.state.excludeTimeList}
340-
//filterTime={filterPassedTime}
346+
filterTime={filterPassedTime}
341347
disabled={this.props.attributes.disabled}
342348
onInputClick={this.openTimePicker}
343349
onKeyDown={this.tpKeyDownHandler}

zmsadmin/js/page/availabilityDay/form/formButtons.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ const FormButtons = (props) => {
2121
className="button button--diamond" disabled={disabled || data.startDate == selectedDate}>Ab diesem Tag ändern</button>
2222
<button onClick={onUpdateSingle}
2323
title="Öffnungszeit aktualisieren"
24-
className="button button--diamond" disabled={(data && !data.id) || hasConflicts || hasSlotCountError || props.isCreatingExclusion}>Aktualisieren</button>
24+
className="button button--diamond" disabled={disabled || props.isCreatingExclusion}>Aktualisieren</button>
2525
</div>
2626
</div>
2727
)

zmsadmin/js/page/availabilityDay/helpers.js

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,13 +102,22 @@ export const getNewAvailability = (timestamp, tempId, scope, existingAvailabilit
102102
})
103103

104104
const currentTime = moment()
105-
let startTime = moment('05:00:00', 'HH:mm:ss')
106-
if (currentTime.isAfter(startTime)) {
105+
const dayEndTime = moment('22:00:00', 'HH:mm:ss')
106+
let startTime = moment('07:00:00', 'HH:mm:ss')
107+
108+
// Only use current time if the selected date is today
109+
if (now.format('YYYY-MM-DD') === currentTime.format('YYYY-MM-DD') && currentTime.isAfter(startTime)) {
107110
// Round up to next half hour
108111
startTime = moment(currentTime).add(30 - (currentTime.minutes() % 30), 'minutes')
109112
}
110113
let endTime = moment(startTime).add(1, 'hour')
111114

115+
// Adjust if end time would exceed 22:00
116+
if (endTime.isAfter(dayEndTime)) {
117+
startTime = moment(dayEndTime).subtract(1, 'hour')
118+
endTime = moment(dayEndTime)
119+
}
120+
112121
const hasOverlap = (start, end) => {
113122
return todayAvailabilities.some(availability => {
114123
const availStart = moment(availability.startTime, 'HH:mm:ss')
@@ -125,10 +134,17 @@ export const getNewAvailability = (timestamp, tempId, scope, existingAvailabilit
125134
} else {
126135
const lastAvail = todayAvailabilities[todayAvailabilities.length - 1]
127136
startTime = moment(lastAvail.endTime, 'HH:mm:ss')
128-
if (startTime.isBefore(currentTime)) {
137+
// Only check current time if it's today
138+
if (now.format('YYYY-MM-DD') === currentTime.format('YYYY-MM-DD') && startTime.isBefore(currentTime)) {
129139
startTime = moment(currentTime).add(30 - (currentTime.minutes() % 30), 'minutes')
130140
}
131141
endTime = moment(startTime).add(1, 'hour')
142+
143+
// Check end time limit again after adjusting for overlaps
144+
if (endTime.isAfter(dayEndTime)) {
145+
startTime = moment(dayEndTime).subtract(1, 'hour')
146+
endTime = moment(dayEndTime)
147+
}
132148
}
133149
}
134150

0 commit comments

Comments
 (0)