JSFiddle - React, Tailwind, and code Playground

by OwenMelbz

HTML

<div id="today">Earned Today: £<span></span>
</div>
<div id="total">Total Earned: £<span></span>
</div>

JavaScript

$(function () {
    var startdate = new Date("09/19/2013");
    var now = new Date();
    //var now = new Date("09/20/2013 11:30:00")
    var total, today = 0;
    var todayBox = $('#today span');
    var totalBox = $('#total span');
    var daily = 61.54;
    var hourly = daily / 7.5;
    var minutely = hourly / 60;
    var secondly = minutely / 60;
    var hours = {
        9: 0,
        10: 1,
        11: 2,
        12: 3,
        13: 4,
        14: 5,
        15: 6,
        16: 7,
        17: 7.5
    };

    //earned so far
    total = (calcBusinessDays(startdate, now) * daily).toFixed(2);
    totalBox.text(total);

    //earned today already
    var day = now.getDay();
    var hour = now.getHours() <= 18 ? now.getHours() : 17;
    var mins = now.getMinutes();
    var worked = hours[hour];
    today = worked * hourly;
    if(hour >= 17){
        if(mins <= 30 && now.getHours() == 17) {
            today = today + (mins * minutely);   
        }
    }
    todayBox.text(today.toFixed(2));
    
    var timer = setInterval(function () {
        day = now.getDay();
        hour = now.getHours();
        mins = now.getMinutes();
        if (day != 6 && day != 7 && hour >= 9 && (hour <= 17)) {

            //var time = now.getTime();
            today = (today + secondly);
            todayBox.text(today.toFixed(2));

        }
    }, 1000);
});
























function calcBusinessDays(dDate1, dDate2) { // input given as Date objects
    var iWeeks, iDateDiff, iAdjust = 0;
    if (dDate2 < dDate1) return -1; // error code if dates transposed
    var iWeekday1 = dDate1.getDay(); // day of week
    var iWeekday2 = dDate2.getDay();
    iWeekday1 = (iWeekday1 === 0) ? 7 : iWeekday1; // change Sunday from 0 to 7
    iWeekday2 = (iWeekday2 === 0) ? 7 : iWeekday2;
    if ((iWeekday1 > 5) && (iWeekday2 > 5)) iAdjust = 1; // adjustment if both days on weekend
    iWeekday1 = (iWeekday1 > 5) ? 5 : iWeekday1; // only count weekdays
    iWeekday2 = (iWeekday2 > 5) ? 5...