Copy link to clipboard
Copied
I have a very simple timesheet. 3 columns that consist of a TimeIn, TimeOut, and TotalTime. My question relates to how the time is entered. We want the user to be able to select the AM or PM of their In and Out (such as a drop down menu or something similar). This way depending on who is using it no typing other than a numberpad is needed for the time. Is this possible?
My Total Time javascript is:
event.value = '';
// get the start time
var sStart = this.getField('TimeIn.0').value;
// get the end time
var sEnd = this.getField('TimeOut.0').value;
// complete script only if we have data
if(sStart != '' & sEnd != '') {
// convert sStart string to seconds
var fStart = Time2Num('hh:mm', sStart);
// convert sEnd string to seconds
var fEnd = Time2Num('hh:mm', sEnd);
// compute difference in seconds
var fDiff = fEnd - fStart;
// convert to rounded minutes
fDiff = Math.round(fDiff / 60);
// report decimal hours
event.value = fDiff / 60;
}
Copy link to clipboard
Copied
Yes, but you you would need to post the full code, specifically of the Time2Num function.
Copy link to clipboard
Copied
Oh sorry, I misread your response.
Here is the full script.
//<Document-Level>
//<ACRO_source>Num2sTime</ACRO_source>
//<ACRO_script>
/*********** belongs to: Document-Level:Num2sTime ***********/
function Num2sTime(fValue) {
// convert minutes to HH:MM string
fDiff = Math.round(Number(fValue) / 60);
// get hours from fDiff
fHours = Math.floor(fDiff / 60);
// get minutes less than hour from fDiff
fMins = Math.round(((fDiff / 60) - fHours ) * 60);
// format fMins with leading zero
sMins = util.printf("%,302.0f", fMins);
// build display string
return fHours + ':' + sMins;
}
//</ACRO_script>
//</Document-Level>
//<Document-Level>
//<ACRO_source>SupressZero</ACRO_source>
//<ACRO_script>
/*********** belongs to: Document-Level:SupressZero ***********/
function SupressZero(sValue) {
if(Number(sValue) ==0) sValue = '';
return sValue;
}
//</ACRO_script>
//</Document-Level>
//<Document-Level>
//<ACRO_source>Time2Num</ACRO_source>
//<ACRO_script>
/*********** belongs to: Document-Level:Time2Num ***********/
function Time2Num(sFormat, sTime) {
/*
convert time string (sTime) with format of sFormat
to the seconds since the start of the day
*/
if(sTime == '') return ''; // exit
// get date time for Epoch date and sTime
var oTime = util.scand('mm/dd/yyyy ' + sFormat, '01/01/1970 ' + sTime);
// convert UTC Offset to milliseonds for adjustment
var fTZOffset = oTime.getTimezoneOffset() * 1000 * 60
// time since the start of the day in millseconds
var fTime = oTime.valueOf() - fTZOffset;
// convert to seconds and return value
return Math.round(fTime / 1000);
}
//</ACRO_script>
//</Document-Level>
//<Document-Level>
//<ACRO_source>sTime2Num</ACRO_source>
//<ACRO_script>
/*********** belongs to: Document-Level:sTime2Num ***********/
function sTime2Num(sValue) {
if(sValue == '') return 0;
var aValue = sValue.split(':');
return (aValue[0] * 3600) + (aValue[1] * 60);
}
//</ACRO_script>
//</Document-Level>
//<AcroForm>
//<ACRO_source>TimeDec.1:Calculate</ACRO_source>
//<ACRO_script>
/*********** belongs to: AcroForm:TimeDec.1:Calculate ***********/
event.value = '';
// get the start time
var sStart = this.getField('TimeIn.1').value;
// get the end time
var sEnd = this.getField('TimeOut.1').value;
// complete script only if we have data
if(sStart != '' & sEnd != '') {
// convert sStart string to seconds
var fStart = Time2Num('hh:mm', sStart);
// convert sEnd string to seconds
var fEnd = Time2Num('hh:mm', sEnd);
// compute difference in seconds
var fDiff = fEnd - fStart;
// convert to rounded minutes
fDiff = Math.round(fDiff / 60);
// report decimal hours
event.value = fDiff / 60;
}
//</ACRO_script>
//</AcroForm>
//<AcroForm>
//<ACRO_source>TimeDec.2:Calculate</ACRO_source>
//<ACRO_script>
/*********** belongs to: AcroForm:TimeDec.2:Calculate ***********/
event.value = '';
// get the start time
var sStart = this.getField('TimeIn.2').value;
// get the end time
var sEnd = this.getField('TimeOut.2').value;
// complete script only if we have data
if(sStart != '' & sEnd != '') {
// convert sStart string to seconds
var fStart = Time2Num('hh:mm', sStart);
// convert sEnd string to seconds
var fEnd = Time2Num('hh:mm', sEnd);
// compute difference in seconds
var fDiff = fEnd - fStart;
// convert to rounded minutes
fDiff = Math.round(fDiff / 60);
// report decimal hours
event.value = fDiff / 60;
}
//</ACRO_script>
//</AcroForm>
Copy link to clipboard
Copied
OK. So in your original code you can add these lines after line #7:
sStart+= " " + this.getField("TimeIn.AMPM.0");
sEnd+= " " + this.getField("TimeOut.AMPM.0");
And then change lines #9 and #11 to:
var fStart = Time2Num('hh:mm tt', sStart);
var fEnd = Time2Num('hh:mm tt', sEnd);
Copy link to clipboard
Copied
You should realize that your time sheet will not work if it covers the date and time for the change to Daylight Savings Time or Summer time.
It looks like you could use a simple loop to process each day's hours worked instead of computing the total for each day. It also might be possible to compute the row number form the daily total field name and then apply that value to the inputs for the daily calculation.
It appears that the Time2Num function coverts the formatted time in the 24 hour civilian format into the number of minutes from midnight. This neans there is no need for the AM or PM meridians since the time values for a single day are from 00:00 to 23:59.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now