Skip to content

Commit

Permalink
fix(ZMS-3466): improve hours selection
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas Fink authored and Thomas Fink committed Jan 28, 2025
1 parent 088356f commit 484cbb4
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 10 deletions.
18 changes: 12 additions & 6 deletions zmsadmin/js/page/availabilityDay/form/datepicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -256,13 +256,19 @@ class AvailabilityDatePicker extends Component
return className;
}

/*
const filterPassedTime = (time) => {
const currentDate = this.state.selectedDate;
const selectedDate = new Date(time);
return currentDate.getTime() < selectedDate.getTime();
};
if (!moment(this.state.selectedDate).isSame(moment.unix(this.props.attributes.today), 'day')) {
return true;
}

const currentTime = moment();
const timeToCheck = moment(time);

return timeToCheck.hour() > currentTime.hour() ||
(timeToCheck.hour() === currentTime.hour() && timeToCheck.minute() > currentTime.minute());
};

/*
const isWeekday = date => {
const day = date.getDay();
return day !== 0 && day !== 6;
Expand Down Expand Up @@ -337,7 +343,7 @@ class AvailabilityDatePicker extends Component
minTime={this.state.minTime}
maxTime={this.state.maxTime}
excludeTimes={this.state.excludeTimeList}
//filterTime={filterPassedTime}
filterTime={filterPassedTime}
disabled={this.props.attributes.disabled}
onInputClick={this.openTimePicker}
onKeyDown={this.tpKeyDownHandler}
Expand Down
2 changes: 1 addition & 1 deletion zmsadmin/js/page/availabilityDay/form/formButtons.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const FormButtons = (props) => {
className="button button--diamond" disabled={disabled || data.startDate == selectedDate}>Ab diesem Tag ändern</button>
<button onClick={onUpdateSingle}
title="Öffnungszeit aktualisieren"
className="button button--diamond" disabled={(data && !data.id) || hasConflicts || hasSlotCountError || props.isCreatingExclusion}>Aktualisieren</button>
className="button button--diamond" disabled={disabled || props.isCreatingExclusion}>Aktualisieren</button>
</div>
</div>
)
Expand Down
22 changes: 19 additions & 3 deletions zmsadmin/js/page/availabilityDay/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,13 +102,22 @@ export const getNewAvailability = (timestamp, tempId, scope, existingAvailabilit
})

const currentTime = moment()
let startTime = moment('05:00:00', 'HH:mm:ss')
if (currentTime.isAfter(startTime)) {
const dayEndTime = moment('22:00:00', 'HH:mm:ss')
let startTime = moment('07:00:00', 'HH:mm:ss')

// Only use current time if the selected date is today
if (now.format('YYYY-MM-DD') === currentTime.format('YYYY-MM-DD') && currentTime.isAfter(startTime)) {
// Round up to next half hour
startTime = moment(currentTime).add(30 - (currentTime.minutes() % 30), 'minutes')
}
let endTime = moment(startTime).add(1, 'hour')

// Adjust if end time would exceed 22:00
if (endTime.isAfter(dayEndTime)) {
startTime = moment(dayEndTime).subtract(1, 'hour')
endTime = moment(dayEndTime)
}

const hasOverlap = (start, end) => {
return todayAvailabilities.some(availability => {
const availStart = moment(availability.startTime, 'HH:mm:ss')
Expand All @@ -125,10 +134,17 @@ export const getNewAvailability = (timestamp, tempId, scope, existingAvailabilit
} else {
const lastAvail = todayAvailabilities[todayAvailabilities.length - 1]
startTime = moment(lastAvail.endTime, 'HH:mm:ss')
if (startTime.isBefore(currentTime)) {
// Only check current time if it's today
if (now.format('YYYY-MM-DD') === currentTime.format('YYYY-MM-DD') && startTime.isBefore(currentTime)) {
startTime = moment(currentTime).add(30 - (currentTime.minutes() % 30), 'minutes')
}
endTime = moment(startTime).add(1, 'hour')

// Check end time limit again after adjusting for overlaps
if (endTime.isAfter(dayEndTime)) {
startTime = moment(dayEndTime).subtract(1, 'hour')
endTime = moment(dayEndTime)
}
}
}

Expand Down

0 comments on commit 484cbb4

Please sign in to comment.