Skip to content

Commit

Permalink
Сделал дз функции возвращаются
Browse files Browse the repository at this point in the history
  • Loading branch information
generalofgotei committed Dec 8, 2024
1 parent 0e5b396 commit 0048100
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
1 change: 1 addition & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -234,5 +234,6 @@ <h2 class="data-error__title">Не удалось загрузить данны
</section>
</template>
<script src="js/main.js" type="module"></script>
<script src="js/functions.js"></script>
</body>
</html>
37 changes: 37 additions & 0 deletions js/functions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
const getHours = (timeString) => Number(timeString.split(':')[0]);
const getMinutes = (timeString) => Number(timeString.split(':')[0]);

const isWithinWorkingHours = (workdayStart, workdayEnd, meetingStart, meetingLength) => {

// Получаем часы и минуты начала рабочего дня
let workdayStartHours = getHours(workdayStart);
let workdayStartMinutes = getMinutes(workdayStart);

// Получаем часы и минуты конца рабочего дня
let workdayEndHours = getHours(workdayEnd);
let workdayEndMinutes = getMinutes(workdayEnd);

// Получаем часы и минуты начала встречи
let meetingStartHours = getHours(meetingStart);
let meetingStartMinutes = getMinutes(meetingStart);

// Получаем часы и минуты конца встречи
let meetingEndHours = meetingStartHours + Math.floor(meetingLength / 60);
let meetingEndMinutes = meetingStartMinutes + (meetingLength - meetingEndHours * 60);
if (meetingEndMinutes >= 60) {
meetingEndHours += 1;
meetingEndMinutes -= 60;
};

// Проверяем начало и конец встречи на выход за рабочий день
if ((workdayStartHours > meetingStartHours) || (workdayStartHours === meetingStartHours && workdayStartMinutes > meetingStartMinutes) || (workdayEndHours < meetingEndHours) || (workdayEndHours === meetingEndHours && workdayEndMinutes < meetingEndMinutes)) {
return false
};
return true;
};

console.log(isWithinWorkingHours('08:00', '17:30', '14:00', 90));
console.log(isWithinWorkingHours('8:0', '10:0', '8:0', 120));
console.log(isWithinWorkingHours('08:00', '14:30', '14:00', 90));
console.log(isWithinWorkingHours('14:00', '17:30', '08:0', 90));
console.log(isWithinWorkingHours('8:00', '17:30', '08:00', 900));

0 comments on commit 0048100

Please sign in to comment.