Last active
December 20, 2022 20:09
-
-
Save bosconian-dynamics/0cf0414cdbaa63522404630f96c7b24b to your computer and use it in GitHub Desktop.
This file contains hidden or 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 data = []; | |
var current_year = (new Date()).getFullYear(); | |
var $rows = document.querySelectorAll('table.rpt>tbody>tr'); | |
var node = document.createElement( 'td' ); | |
node.innerHTML = '<div>Work Period</div>'; | |
$rows[0].appendChild( node ); | |
node = document.createElement( 'td' ); | |
node.innerHTML = '<div>Work Day</div>'; | |
$rows[0].appendChild( node ); | |
for(var i = 1; i < $rows.length; i++) { | |
var $row = $rows[i]; | |
var $period = document.createElement('td'); | |
var $day = document.createElement('td'); | |
var entry = { | |
$row: $row, | |
$status: $row.cells[1].children[0], | |
$date: $row.cells[2].children[0], | |
$notes: $row.cells[3].children[0], | |
$period, | |
$day, | |
status: $row.cells[1].children[0].textContent, | |
date: new Date($row.cells[2].children[0].textContent), | |
notes: $row.cells[3].children[0].textContent, | |
period: undefined, | |
day: undefined, | |
}; | |
$row.appendChild($period); | |
$row.appendChild($day); | |
// if(entry.date.getFullYear() < current_year - 1) | |
// break; | |
var adjustment = entry.notes.match(/\s*@?(?:(\d\d?)(?::(\d\d))?)\s*(A\.?M\.?|P\.?M\.?)?\s*(?:(\d\d?)\/(\d\d?)(?:\/(\d\d?\d?\d?))?)?/i); | |
if(adjustment != null) { | |
if(entry.notes.length > adjustment[0].length + 2) { | |
entry.$date.style.color = 'red'; | |
continue; | |
} | |
if(adjustment[4]) { | |
var year = adjustment[6] ? parseInt(adjustment[6].padStart(4, '20')) : entry.date.getFullYear(); | |
entry.date.setFullYear(year, parseInt(adjustment[4]) - 1, parseInt(adjustment[5])); | |
} | |
var hours = parseInt(adjustment[1]); | |
if(hours <= 12) { | |
if(adjustment[3]) | |
hours += adjustment[3].toUpperCase().replaceAll('.','') == 'PM' ? 12 : 0; | |
else if(entry.date.getHours() > 12) | |
hours += 12; | |
} | |
if(adjustment[2]) | |
entry.date.setHours(hours, parseInt(adjustment[2]), 0); | |
else | |
entry.date.setHours(hours, 0, 0); | |
entry.$date.style.color = 'cyan'; | |
entry.$date.setAttribute('title', `Adjusted from ${entry.$date.textContent}`); | |
entry.$date.style.cursor = 'pointer'; | |
entry.$date.innerHTML = `${entry.date.getFullYear()}-${(entry.date.getMonth() + 1).toString().padStart(2, '0')}-${entry.date.getDate().toString().padStart(2, '0')} ${entry.date.toLocaleTimeString('en-GB')}`; | |
} | |
data.push(entry); | |
} | |
var last_in; | |
var last_day; | |
var day_hours = 0; | |
for(var i = data.length - 1; i >= 0; i--) { | |
var entry = data[i]; | |
switch(entry.status) { | |
case 'IN': | |
last_in = entry.date; | |
if(entry.date.getDate() != last_day) | |
last_day = entry.date.getDate(); | |
break; | |
case 'OUT': | |
case 'LUNCH': | |
if(!last_in) continue; | |
entry.period = Math.round((entry.date - last_in) / 36000) / 100; | |
entry.$period.innerHTML = `<div>${Math.floor(entry.period)}:${Math.round((entry.period % 1) * 60).toString().padStart(2, '0')}</div>`; | |
last_in = undefined; | |
day_hours += entry.period; | |
if(!data[i-1] || data[i - 1] && data[i - 1].date.getDate() != entry.date.getDate()) { | |
entry.$day.style['text-align'] = 'right'; | |
entry.$day.innerHTML = `<div>${entry.date.toLocaleDateString('en-US')}: ${Math.floor(day_hours)}:${Math.ceil((day_hours % 1) * 60).toString().padStart(2, '0')}</div>`; | |
day_hours = 0; | |
} | |
break; | |
} | |
} |
This file contains hidden or 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
javascript:(() => {var script = document.createElement('script'); script.type = 'text/javascript'; script.src = 'https://gist.githack.com/bosconian-dynamics/0cf0414cdbaa63522404630f96c7b24b/raw/AspIW_TimeCalc.js'; document.body.appendChild(script);})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment