Javascript value set null if value equals nothing -


right working on timesheet users can set in time, out time, , how long they've been @ lunch. use function subtracts in time & lunch out time figure out hours, plus possible overtime. want have javascript set value of overtime field '' (aka null) if amount of time @ work 8 hours or less.

my code checking overtime this:

// return difference between 2 times in hh:mm[am/pm] format hh:mm function checkovertime(timein, timeout, away) {   // small helper function pad single digits   function z(n){return (n<10?'0':'') + n;}   // difference in minutes   var subtotal = daytimestringtomins(timeout) - daytimestringtomins(timein) - timestringtomins(away);   var regularhours = '08:00';   if (subtotal > timestringtomins(regularhours)) {var overtime = daytimestringtomins(timeout) - daytimestringtomins(timein) - timestringtomins(away) - timestringtomins(regularhours);}     else {var overtime = '0';}   return   z(overtime/60 | 0) + ':' + z(overtime % 60); } 

and in calculation function have this:

if (checkovertime(timein, timeout, away).value == '00:00') {   document.getelementbyid("date-1-overtime").value = ''; } else {   document.getelementbyid("date-1-overtime").value = checkovertime(timein, timeout, away); } 

so if person @ work 8 hours, "date-1-overtime" field says "00:00" put nothing in there sheet prints out more cleanly.

i think maybe confusing difference between strings , integers in calculation functions i'm not sure, me!

i think should change method use regular expressions extract appropriate parts of input , use parseint value in numeric form.

convert minutes , if minutes less or equal 480 (8 * 60), return actual string.

also, can't assign null value html param. null not same 0. null essentially, undefined.

you should return number of minutes worked overtime function , use 0 overtime if user didn't work overtime.


Comments

Popular posts from this blog

php - Magento - Deleted Base url key -

javascript - Tooltipster plugin not firing jquery function when button or any click even occur -

java - WrongTypeOfReturnValue exception thrown when unit testing using mockito -