function makeHumanReadable(){
let maintWindow = document.getElementById("maintenanceWindow").value;
let maintWindowExp = /([a-z]{3}):(\d{2}):(\d{2})-([a-z]{3}):(\d{2}):(\d{2})/g;
let maintWindowParts = maintWindowExp.exec(maintWindow);
let dayNumbers = {"sun": 0, "mon": 1, "tue": 2, "wed": 3, "thu": 4, "fri": 5, "sat": 6};
let startTime = new Date();
let endTime = new Date();
//set the date by determining the next occurrence of the maintenance weekday (which could be today)
startTime.setTime(startTime.getTime() + ((7 + dayNumbers[maintWindowParts[1]] - startTime.getDay()) % 7)*86400000);
endTime.setTime(endTime.getTime() + ((7 + dayNumbers[maintWindowParts[4]] - endTime.getDay()) % 7)*86400000);
//set the hours and minutes as well
startTime.setHours(maintWindowParts[2], maintWindowParts[3], 0, 0);
endTime.setHours(maintWindowParts[5], maintWindowParts[6], 0, 0);
//if the hour and minute adjustment put us back into the past, add 7 days to make this the following week
if(startTime.getTime() < Date.now()) startTime.setDate(startTime.getDate() + 7);
if(endTime.getTime() < startTime.getTime()) endTime.setDate(endTime.getDate() + 7);
let options = { year: 'numeric', month: 'long', day: 'numeric', hour: 'numeric', minute: 'numeric'};
document.getElementById("machineReadable").innerHTML = "Machine readable: " + startTime.getTime() + " to " + endTime.getTime();
document.getElementById("humanReadable").innerHTML = "Human readable: " + new Intl.DateTimeFormat('default', options).format(startTime) + " to " + new Intl.DateTimeFormat('default', options).format(endTime);
}
makeHumanReadable();
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.