const form = document.getElementById('form'); const rentStartInput = document.getElementById('rent-start'); const rentStartTimeHoursInput = document.getElementById('rent-start-time-hours'); const rentStartTimeMinutesInput = document.getElementById('rent-start-time-minutes'); const rentOffInput = document.getElementById('rent-off'); const rentOffTimeHoursInput = document.getElementById('rent-off-time-hours'); const rentOffTimeMinutesInput = document.getElementById('rent-off-time-minutes'); const durationOutput = document.getElementById('duration'); const minDuration = 3; // минимальная продолжительность аренды в сутках const hoursOptions = [...Array(25).keys()].map(i => i.toString().padStart(2, '0')); const minutesOptions = ['00', '15', '30', '45']; const createElement = (element, item) => { const newElement = document.createElement(element); newElement.textContent = item; return newElement; }; const populateSelect = (select, options) => { options.forEach(option => { select.appendChild(createElement('option', option)); }); }; populateSelect(rentStartTimeHoursInput, hoursOptions); populateSelect(rentStartTimeMinutesInput, minutesOptions); populateSelect(rentOffTimeHoursInput, hoursOptions); populateSelect(rentOffTimeMinutesInput, minutesOptions); const calculateDuration = (rentStart, rentStartTime, rentOff, rentOffTime) => { const rentStartDate = new Date(rentStart); const rentStartTimeDate = new Date(); rentStartTimeDate.setHours(rentStartTime.hours, rentStartTime.minutes); const rentEndDate = new Date(rentOff); const rentEndTimeDate = new Date(); rentEndTimeDate.setHours(rentOffTime.hours, rentOffTime.minutes); const diff = Math.round((rentEndTimeDate - rentStartTimeDate) / (1000 * 60 * 60 * 24)); if (diff < minDuration) { return minDuration; } return diff; }; const updateDuration = (e) => { e.preventDefault(); const rentStart = rentStartInput.value; const rentStartTime = { hours: parseInt(rentStartTimeHoursInput.value), minutes: parseInt(rentStartTimeMinutesInput.value) }; const rentOff = rentOffInput.value; const rentOffTime = { hours: parseInt(rentOffTimeHoursInput.value), minutes: parseInt(rentOffTimeMinutesInput.value) }; if (!rentStart || !rentStartTime || !rentOff || !rentOffTime) { alert('Заполните все поля!'); return; } if (rentOff < rentStart) { alert('Дата окончания аренды не может быть меньше даты начала аренды!'); return; } const duration = calculateDuration(rentStart, rentStartTime, rentOff, rentOffTime); durationOutput.value = duration; }; form.addEventListener('submit', updateDuration);
Open your mind to new experiences
Getting things done is a process. It demands accountability and clear goals. Following through is the most valuable asset to any organization. Successful teams ask questions, evaluate the reality, and navigate toward specific solutions.
How It Works
1
High Quality
We are a leading firm in providing value to our customers. Each member of our team has at least five years of legal experience. We love what we do.
2
Good Support
Our managers are always ready to answer your questions. You can call us during the weekends and at night. You can also visit our office for a personal consultation.
3
Individual Approach
Our company works according to the principle of individual approach to every client. This method allows us to achieve success in problems of all levels.
Made on
Tilda