JSFiddle - React, Tailwind, and code Playground
HTML
Result: <span id="result"></span>
JavaScript
function funLoad(str1, str3, str4) {
var dym1 = str1.split("/");
// get the given(start) epoch value (using midnight for time - will adjust for actual time further below)
var start_date = new Date(dym1[2], (dym1[1]-1), dym1[0], 0, 0, 0, 0);
var start_epoch = start_date.getTime();
// get todays(end) epoch value (using midnight for time - will adjust for actual time further below)
var end_d = new Date();
var end_epoch = new Date(end_d.getFullYear(), end_d.getMonth(), end_d.getDate(), 0, 0, 0, 0).getTime();
var end_date_is_weekend = (end_d.getDay()==0 || end_d.getDay()==6)?1:0;
// get value for 1 day in milliseconds
var one_day = 1000*60*60*24;
// how many days between given date and todays date
var total_days = Math.ceil( (end_epoch - start_epoch ) / one_day)-1;
// figure out how many of those total days are weekend days
var date_to_check = start_epoch + one_day;
var total_weekend_days = 0;
var next_day_is_weekend = 0;
for(var x=0; x<total_days; x++){
d=new Date(date_to_check);
if(d.getDay()==0 || d.getDay()==6){
total_weekend_days++;
if(x==0){next_day_is_weekend=1;}
}
date_to_check += one_day
}
// determine number of week days
var total_week_days = total_days - total_weekend_days;
// get the total hours from the total week days
var total_hours = total_week_days*24;
// still need to add the remaining hours from the given(start) date and the number of hours that have already past in the end(todays) date
// add in the remaining hours left in the start date
var hours_remaining_in_start_date = 0;
// rounding up to next nearest start date hour
if(str4 > 30){
if(str3 == 23 && next_day_is_weekend==0){
// rounding up puts the start date into the start of the next day so subtract
// one day from the total, UNLESS the next...