Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Time in and time out timesheet question (form attached)

Explorer ,
Mar 14, 2016 Mar 14, 2016

Yes I know this question has been asked many times but I have looked through dozens of examples and a lot of the "Sample" forms in the forums are no longer available since Adobe has changed stuff around. I have attached the form. I need it set up where time is not given in negative numbers for example if a person works from 9:00 pm to 7:00 am. It needs to display 10 hours instead of -14 hours (as it currently gives me). I appreciate the help! There are no "breaks" or "lunches" etc. in this. Just a calculation between the Time In and Time Out.

Thanks!

Screenshot.jpg

Dropbox - Staff Assignment Sheet.pdf

TOPICS
Acrobat SDK and JavaScript , Windows
1.5K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Mar 14, 2016 Mar 14, 2016

In TimeDiff, after this line:

var fEnd = Time2Num(sTimeFormat, sEnd);

Add this:

if (fEnd<fStart) fEnd+=86400;

Translate
Community Expert ,
Mar 14, 2016 Mar 14, 2016

If you're interested, I developed a tool that allows you to easily set up such calculations, with or without a break. You can purchase it from here:

Custom-made Adobe Scripts: Acrobat -- Calculate Time Differences in a Worksheet

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Mar 14, 2016 Mar 14, 2016

Looking for help on what code to help replace for what I currently have.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 14, 2016 Mar 14, 2016

Then start by posting what you currently have...

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 14, 2016 Mar 14, 2016

Sorry, I see now you linked to the file. Checking it now...

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Mar 14, 2016 Mar 14, 2016

Thanks I appreciate it!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 14, 2016 Mar 14, 2016

In TimeDiff, after this line:

var fEnd = Time2Num(sTimeFormat, sEnd);

Add this:

if (fEnd<fStart) fEnd+=86400;

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Mar 14, 2016 Mar 14, 2016

Thank you very much!!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Mar 14, 2016 Mar 14, 2016

For future purposes for anyone here is the code:

Document Level Javascripts:

function Time2Num(sFormat, sTime) {

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);

}

function TimeDiff(cStartField, cEndField) {

var sTimeFormat = 'hh:mm';

var fDiff = 0;

// get the start time

var sStart = this.getField(cStartField).value;

// get the end time

var sEnd = this.getField(cEndField).value;

// complete script only if we have data

if(sStart != '' & sEnd != '') {

// convert sStart string to seconds

var fStart = Time2Num(sTimeFormat, sStart);

// convert sEnd string to seconds

var fEnd = Time2Num(sTimeFormat, sEnd);

if (fEnd<fStart) fEnd+=86400;

// compute difference in seconds

fDiff += fEnd - fStart;

}

return fDiff;

}

In the Custom Calculation Script

(this goes in the field that will calculate the difference between Time In field and Time Out field..swap out SundayIn and SundayOut for your field names):

event.value = '';

var fDiff = 0;

// compute the difference for first pair of fields

// get the start time

var sStart = this.getField('SundayIn').value;

// get the end time

var sEnd = this.getField('SundayOut').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

fDiff += fEnd - fStart;

}

fDiff = TimeDiff('SundayIn', 'SundayOut');

// convert to rounded minutes if not zero

if (fDiff != 0) {

fDiff = Math.round(fDiff / 60);

// report decimal hours

event.value = fDiff / 60;

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 14, 2016 Mar 14, 2016

By the way, I would recommend moving the code in the individual fields to a

doc-level script that takes as a parameter the name of the day, as the rest

of the code is exactly the same.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Mar 14, 2016 Mar 14, 2016
LATEST

Do you have an y adjustment for Daylight Savings Time or Summer Time adjustment?

What happens wen you cover the dates Mar 12, 1016 and Mar 13, 2016 and the time interval covers 1:00 am to 3:00 am?

It is best to inlcue the actual dates for the time in and out along with removing t he timezone offset.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines