Last active
August 29, 2015 14:13
-
-
Save entrity/5b15e52f984c973d3861 to your computer and use it in GitHub Desktop.
Paychex TimeandLabor Clockout Calculator
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: | |
TIME_REGEX = /^(\d+):(\d+) (\w+)/; | |
function show (targetHours) { | |
var clockoutMatch = /(\d{2}):(\d{2}):(\d{2}){0,1}/.exec(getClockoutTime(targetHours).toString()); | |
var outputHours = parseInt(clockoutMatch[1]); | |
var outputMeridian = (outputHours >= 12) ? 'pm' : 'am'; | |
if (outputHours > 12) outputHours = outputHours % 12; | |
var clockoutString = "Clock out: "+outputHours+':'+clockoutMatch[2]+' '+outputMeridian; | |
if (clockoutMatch[3]) clockoutString += ' & '+clockoutMatch[3]+' sec'; | |
var nextTry = prompt(clockoutString+"\n\nTarget number of hours (float):"); | |
if (nextTry && nextTry.trim().length) { | |
var nextTargetHours = parseFloat(nextTry.trim()); | |
show(nextTargetHours); | |
} | |
} | |
/* Return float for hours */ | |
function getLastPunch () { | |
var rows = jQuery('table#Table1 tr'); | |
var lastPunchRow = -1; | |
for (var i = rows.length-1; i >= 0 ; i--) { | |
var cell = rows[i].children[6]; | |
if (cell && TIME_REGEX.test(cell.textContent)) | |
break; | |
} | |
var lastPunchMatch = TIME_REGEX.exec(cell.textContent); | |
var hours = parseInt(lastPunchMatch[1]); | |
var minutes = parseInt(lastPunchMatch[2]); | |
var meridian = lastPunchMatch[3]; | |
if (meridian == 'pm' && hours != 12) | |
hours += 12; | |
var lastPunch = new Date; | |
lastPunch.setHours(hours); | |
lastPunch.setMinutes(minutes); | |
lastPunch.setSeconds(0); | |
console.log('lastPunch: '+lastPunch.getTime()); | |
console.log("lastPunch: "+lastPunch); | |
return lastPunch; | |
} | |
/* Return Date for clockout */ | |
function getClockoutTime (targetHours) { | |
var delta; | |
var hoursSoFar = parseFloat(jQuery('table#Table1 tr:last-child td:nth-child(4)').text()); | |
console.log("hoursSoFar "+hoursSoFar); | |
if (!targetHours) { | |
delta = 8 - (hoursSoFar % 8); | |
} else { | |
delta = targetHours - hoursSoFar; | |
} | |
console.log("delta to target "+delta); | |
var clockoutTime = getLastPunch().getTime() + 1000*60*60*delta; | |
console.log("clockout: "+clockoutTime); | |
var nextPunch = new Date(clockoutTime); | |
console.log("clockout: "+nextPunch); | |
return nextPunch; | |
} | |
show(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment