JSFiddle - React, Tailwind, and code Playground
by lustre
HTML
<div id="currentSecs">Seconds Today:</div>
<br /><br />
<div id="thistime-day">Parcels today: </div>
<div id="thistime-week">This week: </div>
<div id="thistime-year">This year: </div>
CSS
#thistime-day,
#thistime-week{
color:green;
font-weight:bold;
}
JavaScript
$(function() {
/* Variables defined by the client */
var parcelsPerMinute = 34;
var parcelsPerDay = 50000;
//var oneSecond = 1000; // milliseconds
var oneMinute = 60*1000; // seconds*milliseconds
//var oneHour = 60*60*1000; // minutes*seconds*milliseconds
var oneDay = 24*60*60*1000; // hours*minutes*seconds*milliseconds
var oneWeek = 7*24*60*60*1000; // days*hours*minutes*seconds*milliseconds
var thisYear = new Date().getFullYear();
var thisMonth = new Date().getMonth();
var thisDay = new Date().getDate();
var dayInWeek = new Date().getDay(); // Get the day of the week. 0=Sunday, 1=Monday
var startOfYear = new Date(thisYear,00,01); // Jan 1st of current year
var startOfToday = new Date(thisYear,thisMonth,thisDay,00,00,00); // start of the day
var today = new Date();
//var diffSecs = Math.round(Math.abs((startOfYear.getTime() - today.getTime())/(oneSecond)));
var diffMins = Math.round(Math.abs((startOfToday.getTime() - today.getTime())/(oneMinute))); // difference in minutes from start of the day to now.
var diffDays = Math.round(Math.abs((startOfYear.getTime() - today.getTime())/(oneDay)));
var diffWeeks = Math.round(Math.abs((startOfYear.getTime() - today.getTime())/(oneWeek)));
var currentWeek = diffWeeks+1;
var parcelsSoFarToday = diffMins*parcelsPerMinute; // Number of parcels which have been delivered so far today. 34*number of minutes elapsed
/* 34 * number of minutes elapsed today */
$('#thistime-day').append(parcelsSoFarToday);
/* Calculate dayInWeek so Monday = 0. If it's less than 1 then day is Sunday so set to 6 */
var realDayInWeek = dayInWeek-1;
if(realDayInWeek < 0){
realDayInWeek = 6;
}
/* Work out todays then add 50000 * days in week */
$('#thistime-week').append(parcelsSoFarToday + (realDayInWeek * parcelsPerDay));
/* parcelsSoFarToday + (diffDays * 50000) */
$('#thistime-year').append(parcelsSoFarToday + (diffDays*parcelsPerDay));
});