Skip to content

Commit

Permalink
fix(ZMS-3466): disable maintanence daily cronjob hours from opening h…
Browse files Browse the repository at this point in the history
…ours selection
  • Loading branch information
Thomas Fink authored and Thomas Fink committed Jan 30, 2025
1 parent 687af94 commit d86c998
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 21 deletions.
25 changes: 20 additions & 5 deletions zmsadmin/js/page/availabilityDay/form/datepicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,17 @@ class AvailabilityDatePicker extends Component
return;
}
var times = [];

// Add maintenance window times (23:00-01:00)
const selectedDate = moment(this.state.selectedDate);
for (let minute = 1; minute < 60; minute++) {
times.push(selectedDate.clone().hour(23).minute(minute).toDate());
}
for (let minute = 0; minute < 59; minute++) {
times.push(selectedDate.clone().hour(0).minute(minute).toDate());
}

// Filter and sort availabilities
const availabilities = [...this.state.availabilityList]
.filter(availability =>
availability.id !== this.state.availability.id &&
Expand All @@ -137,7 +148,7 @@ class AvailabilityDatePicker extends Component
return timeA.diff(timeB);
});

// First add regular excluded times
// Add regular excluded times
availabilities.forEach(availability => {
const startTime = moment(availability.startTime, 'hh:mm')
.add(this.state.availability.slotTimeInMinutes, "m");
Expand All @@ -161,7 +172,7 @@ class AvailabilityDatePicker extends Component
times.push(endOnDay);
});

// Then check for and add boundary timestamps between adjacent availabilities
// Add boundary timestamps between adjacent availabilities
for (let i = 0; i < availabilities.length - 1; i++) {
const current = availabilities[i];
const next = availabilities[i + 1];
Expand Down Expand Up @@ -287,12 +298,16 @@ class AvailabilityDatePicker extends Component
if (!moment(this.state.selectedDate).isSame(moment.unix(this.props.attributes.today), 'day')) {
return true;
}


const BUFFER_MINUTES = 60; // Minimum minutes needed between current time and next slot
const currentTime = moment();
const timeToCheck = moment(time);

return timeToCheck.hour() > currentTime.hour() ||
(timeToCheck.hour() === currentTime.hour() && timeToCheck.minute() > currentTime.minute());
// Calculate minutes difference between times
const minutesDiff = timeToCheck.diff(currentTime, 'minutes');

// Disable if time is in past or too close to current time
return minutesDiff >= BUFFER_MINUTES;
};

/*
Expand Down
29 changes: 15 additions & 14 deletions zmsadmin/js/page/availabilityDay/form/validate.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,9 +168,9 @@ function validateStartTime(today, tomorrow, selectedDate, data) {
const isFuture = (data.kind && 'future' == data.kind);
//const isOrigin = (data.kind && 'origin' == data.kind);

if (! isFuture && selectedDate.unix() > today.unix() && startTime.isAfter(selectedDate.startOf('day'), 'day')) {
if (!isFuture && selectedDate.unix() > today.unix() && startTime.isAfter(selectedDate.startOf('day'), 'day')) {
errorList.push({
type: 'startTimeFuture',
type: 'startTimeFuture',
message: `Das Startdatum der Öffnungszeit muss vor dem ${tomorrow.format('DD.MM.YYYY')} liegen.`
})
}
Expand All @@ -183,11 +183,12 @@ function validateStartTime(today, tomorrow, selectedDate, data) {
})
}
*/

if ((startHour == "00" && startMinute == "00") || (endHour == "00" && endMinute == "00")) {
const startHourInt = parseInt(startHour);
const endHourInt = parseInt(endHour);
if (startHourInt >= 23 || startHourInt === 0 || endHourInt >= 23 || endHourInt === 0) {
errorList.push({
type: 'startOfDay',
message: 'Die Uhrzeit darf nicht "00:00" sein.'
message: 'Die Uhrzeit darf nicht zwischen 23:00 und 01:00 liegen, da in diesem Zeitraum der tägliche Cronjob ausgeführt wird.'
})
}
return errorList;
Expand All @@ -208,14 +209,14 @@ function validateEndTime(today, yesterday, selectedDate, data) {

if (dayMinutesEnd <= dayMinutesStart) {
errorList.push({
type: 'endTime',
type: 'endTime',
message: 'Die Endzeit darf nicht vor der Startzeit liegen.'
})
}
}

if (startTimestamp >= endTimestamp) {
errorList.push({
type: 'endTime',
type: 'endTime',
message: 'Das Enddatum darf nicht vor dem Startdatum liegen.'
})
}
Expand All @@ -232,20 +233,20 @@ function validateOriginEndTime(today, yesterday, selectedDate, data) {
const endTimestamp = endTime.clone().set({ h: endHour, m: endMinute }).unix();
const isOrigin = (data.kind && 'origin' == data.kind)

if (! isOrigin && selectedDate.unix() > today.unix() && endTime.isBefore(selectedDate.startOf('day'), 'day')) {
if (!isOrigin && selectedDate.unix() > today.unix() && endTime.isBefore(selectedDate.startOf('day'), 'day')) {
errorList.push({
type: 'endTimeFuture',
message: `Das Enddatum der Öffnungszeit muss nach dem ${yesterday.format('DD.MM.YYYY')} liegen.`
})
}

if (
(! isOrigin && endTimestamp < today.unix())
(!isOrigin && endTimestamp < today.unix())
) {
errorList.push({
type: 'endTimePast',
type: 'endTimePast',
message: 'Öffnungszeiten in der Vergangenheit lassen sich nicht bearbeiten '
+ '(Die aktuelle Zeit "'+today.format('DD.MM.YYYY HH:mm')+' Uhr" liegt nach dem Terminende am "'+endDateTime.format('DD.MM.YYYY HH:mm')+' Uhr").'
+ '(Die aktuelle Zeit "' + today.format('DD.MM.YYYY HH:mm') + ' Uhr" liegt nach dem Terminende am "' + endDateTime.format('DD.MM.YYYY HH:mm') + ' Uhr").'
})
}
return errorList;
Expand All @@ -262,7 +263,7 @@ function validateType(data) {
return errorList;
}

function validateSlotTime (data) {
function validateSlotTime(data) {
let errorList = []
const startTime = moment(data.startDate, 'X');
const startHour = data.startTime.split(':')[0]
Expand Down
4 changes: 2 additions & 2 deletions zmsentities/src/Zmsentities/Availability.php
Original file line number Diff line number Diff line change
Expand Up @@ -472,10 +472,10 @@ public function validateStartTime(\DateTimeInterface $today, \DateTimeInterface
];
}

if (($startHour == 0 && $startMinute == 0) || ($endHour == 0 && $endMinute == 0)) {
if ($startHour >= 23 || $startHour === 0 || $endHour >= 23 || $endHour === 0) {
$errorList[] = [
'type' => 'startOfDay',
'message' => 'Die Uhrzeit darf nicht "00:00" sein.'
'message' => 'Die Uhrzeit darf nicht zwischen 23:00 und 01:00 liegen, da in diesem Zeitraum der tägliche Cronjob ausgeführt wird.'
];
}

Expand Down

0 comments on commit d86c998

Please sign in to comment.