Last active
August 29, 2019 10:20
-
-
Save nobuhikosawai/451e091b26beb55c2152bcfb289a4c61 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var isWorkingDay = (year, month ,day, holidays) => ( | |
moment([year, month, day]).isValid() && | |
moment([year, month, day]).day() >= 1 && | |
moment([year, month, day]).day() <= 5 && | |
!holidays.includes(day) | |
) | |
var getWorkingDays = (targetYear, targetMonth, startDay, holidays) => { | |
let workingDays = [] | |
for(let i = startDay; i <= 31; i++) { | |
if (isWorkingDay(targetYear, targetMonth, i, holidays)) { | |
workingDays.push({year: targetYear, month: targetMonth, day: i}); | |
} | |
} | |
return workingDays; | |
} | |
var inputTime = (targetYear, targetMonth, targetDay) => { | |
console.log(targetYear, targetMonth, targetDay); | |
document.getElementById(`ttvTimeSt${moment([targetYear, targetMonth, targetDay]).format('YYYY-MM-DD')}`).click(); | |
document.getElementById('startTime').value = `9:${getRandomInt(0, 60)}`; | |
var endTime = `${getRandomInt(19, 21)}:${getRandomInt(00,60)}`; | |
if (!isValidEndTime(moment(endTime, 'HH:mm'))) { | |
clearRestTime(); | |
} | |
document.getElementById('endTime').value = endTime; | |
document.getElementById("dlgInpTimeOk").click(); | |
} | |
var isValidEndTime = (endTime) => { | |
// check if endTime overlaps the restTime. | |
var startRestTime = moment(document.getElementById('startRest2'), 'HH:mm'); | |
var endRestTime = moment(document.getElementById('endRest2'), 'HH:mm'); | |
return endTime < startRestTime || endTime > endRestTime; | |
} | |
var clearRestTime = () => { | |
document.getElementById('startRest2').value = ''; | |
document.getElementById('endRest2').value = ''; | |
} | |
var mainLoop = (workingDays) => { | |
workingDays.forEach((workingDay, index) => { | |
setTimeout(() => inputTime(workingDay.year, workingDay.month, workingDay.day), index * 5000); | |
}) | |
} | |
var getRandomInt = (min, max) => Math.floor( Math.random() * (max - min)) + min; | |
// ============= Input here ===============// | |
var year = 2018; | |
var month = 2; | |
var day = 1; | |
var holidays = [12]; // Input public holiday or your holiday here. If none, leave as an empty array. | |
// =========================================// | |
var workingDays = getWorkingDays(year, month - 1, day, holidays); // month is zero-index | |
mainLoop(workingDays); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment