I have a function that calculates the number of hours a person should be paid for work done in our jury division of the court and there's a bug in it. It's not calculating the PublicEmployees hours correctly. If you are a public employee you don't get paid for time that you are at the court that corresponds to time you usually work. For example, my regular schedule is 7 am - 4 pm. If I was called to jury duty from 2pm - 5pm, I would get paid 1 hour from 4 - 5 because that's normally MY time, not time that I'm usually working.
Here's the IntToTime function:
In the data below expression 00009 indicates if the person should be paid for all hours worked, if there's a T in the expression, pay all hours.
So the first two people (each person has a JURNUM) are ok.
The first bold person, 51793, is wrong. On 20080611 person 51793 should have 1/2 hour paid from 1700 - 1730; and on 20080624 should be paid from 1700 - 1830 (1 1/2 hours).
The other issue is the second bold person, 54937. On 20080611 they were paid for 5 hours because they fit this section of the calculation:
but that's wrong...it should only be the 2 hours from the start to finish.
The third bold person has an incorrect HourSpan calculation...I'm not sure why, but sometimes when subtracting 1730 and 1700 it doesn't come up with .5, I get values like .49 (this occasionally happens with full hours as well and I get values of .99 instead of 1).
[tt]
JURNUM SERVDAT TIMEIN TIMEOUT COUNTTRIP PAYHOURS REGTIMEIN REGTIMEOUT 00009
47482 20080611 1530 1730 1 2 830 1445 FFT
47482 20080616 830 1600 1 7.5 830 1445 FFT
47482 20080617 830 1200 1 3.5 830 1445 FFT
47482 20080619 830 1130 1 3 830 1445 FFT
47482 20080623 830 1130 1 3 830 1445 FFT
47482 20080624 830 1130 1 3 830 1445 FFT
48419 20080611 1530 1730 0 2 855 1555 FFT
48419 20080616 830 1130 0 3 855 1555 FFT
48419 20080618 830 1230 0 4 855 1555 FFT
48419 20080619 830 1130 0 3 855 1555 FFT
48419 20080623 830 1130 0 3 855 1555 FFT
48419 20080624 830 1730 0 9 855 1555 FFT
51793 20080611 1530 1730 0 0 800 1700 FFF
51793 20080618 830 1230 0 0 800 1700 FFF
51793 20080619 830 1130 0 0 800 1700 FFF
51793 20080623 830 1130 0 0 800 1700 FFF
51793 20080624 830 1830 0 0 800 1700 FFF
51793 20080625 1030 1230 0 0 800 1700 FFF
53664 20080611 1530 1730 0 0 830 1700 FFF
53664 20080616 830 1600 0 0 830 1700 FFF
53664 20080617 830 1200 0 0 830 1700 FFF
53664 20080619 830 1130 0 0 830 1700 FFF
53664 20080620 900 1100 0 0 830 1700 FFF
53664 20080624 830 1130 0 0 830 1700 FFF
54855 20080611 1530 1730 1 2 800 1700 FFT
54855 20080616 830 1600 1 7.5 800 1700 FFT
54855 20080617 830 1200 1 3.5 800 1700 FFT
54855 20080619 830 1130 1 3 800 1700 FFT
54855 20080620 900 1100 1 2 800 1700 FFT
54855 20080623 1330 1530 1 2 800 1700 FFT
54855 20080625 830 1130 1 3 800 1700 FFT
54937 20080611 1530 1730 0 5 900 1230 FFF
54937 20080619 830 1130 0 0.5 900 1230 FFF
55570 20080611 1530 1730 1 2 1700 130 FFT
55570 20080616 830 1130 1 3 1700 130 FFT
55570 20080618 830 1230 1 4 1700 130 FFT
55570 20080619 830 1130 1 3 1700 130 FFT
55570 20080623 830 1130 1 3 1700 130 FFT
55570 20080624 830 1130 1 3 1700 130 FFT
55659 20080611 1530 1730 0 0 600 1700 FFF
55659 20080617 830 1200 0 0 600 1700 FFF
55659 20080619 830 1130 0 0 600 1700 FFF
55659 20080620 900 1100 0 0 600 1700 FFF
55659 20080624 830 1130 0 0 600 1700 FFF
55673 20080611 1530 1730 0 0.49 800 1700 FFF
55673 20080616 830 1130 0 0 800 1700 FFF
55673 20080618 830 1230 0 0 800 1700 FFF
55673 20080619 830 1130 0 0 800 1700 FFF
55673 20080623 830 1300 0 0 800 1700 FFF[/tt]
I have been stepping through and looking at this code for days now and can't figure out what I need to change in order to get this right!
Any extra eyes would be appreciated!
thanks!
leslie
Code:
[navy][i]// for automatic syntax highlighting see faq102-6487[/i][/navy]
[b]function[/b] PublicEmployeeHours(JurNum : [b]string[/b]; TimeIn : TTime; TimeOut : TTime): double;
[b]var[/b]
PEStartTime, PEEndTime : TTime;
[b]begin[/b]
[b]if[/b] [b]not[/b] CheckPayAllPEHours(JurNum) [b]then[/b]
[b]begin[/b]
[b]with[/b] dmJMS.qryPubEmpHours [b]do[/b]
[b]begin[/b]
SQL.Clear;
SQL.Add([teal]'SELECT * FROM JMPPEMPLE WHERE JURNUM = '[/teal] + JurNum);
Active := True;
[b]if[/b] (FieldByName([teal]'REGTIMEIN'[/teal]).AsInteger <> [purple]0[/purple]) AND (FieldByName([teal]'REGTIMEOUT'[/teal]).AsInteger <> [purple]0[/purple]) [b]then[/b]
[b]begin[/b]
PEStartTime := IntToTime(FieldByName([teal]'REGTIMEIN'[/teal]).AsInteger);
PEEndTime := IntToTime(FieldByName([teal]'REGTIMEOUT'[/teal]).AsInteger);
[b]if[/b] TimeOut < PEStartTime [b]then[/b]
Result := HourSpan(TimeOut, TimeIn)
[b]else[/b] [b]if[/b] (TimeIn < PEStartTime) AND (TimeOut < PEEndTime) [b]then[/b]
Result := HourSpan(TimeIn, PEStartTime)
[b]else[/b] [b]if[/b] (TimeIn > PEStartTime) AND (TimeOut > PEEndTime) [b]then[/b]
Result := HourSpan(PEEndTime, TimeOut)
[b]else[/b]
Result := [purple]0[/purple];
[b]end[/b]
[b]else[/b]
Result := [purple]0[/purple];
[b]end[/b];
[b]end[/b]
[b]else[/b]
Result := HourSpan(TimeOut, TimeIn);
[b]end[/b];
Code:
function IntToTime(iTime: integer): TDateTime;
// converts integer time (800) to TDateTime (8:00 am):
var
strTime: string;
begin
strTime:= IntToStr(iTime);
while Length(strTime) < 4 do strTime:= '0' + strTime;
strTime:= LeftStr(strTime, 2) + ':' + RightStr(strTime, 2) + ':00';
Result:= StrToTime(strTime);
end;
In the data below expression 00009 indicates if the person should be paid for all hours worked, if there's a T in the expression, pay all hours.
So the first two people (each person has a JURNUM) are ok.
The first bold person, 51793, is wrong. On 20080611 person 51793 should have 1/2 hour paid from 1700 - 1730; and on 20080624 should be paid from 1700 - 1830 (1 1/2 hours).
The other issue is the second bold person, 54937. On 20080611 they were paid for 5 hours because they fit this section of the calculation:
Code:
[b]else[/b] [b]if[/b] (TimeIn > PEStartTime) AND (TimeOut > PEEndTime) [b]then[/b]
Result := HourSpan(PEEndTime, TimeOut)
but that's wrong...it should only be the 2 hours from the start to finish.
The third bold person has an incorrect HourSpan calculation...I'm not sure why, but sometimes when subtracting 1730 and 1700 it doesn't come up with .5, I get values like .49 (this occasionally happens with full hours as well and I get values of .99 instead of 1).
[tt]
JURNUM SERVDAT TIMEIN TIMEOUT COUNTTRIP PAYHOURS REGTIMEIN REGTIMEOUT 00009
47482 20080611 1530 1730 1 2 830 1445 FFT
47482 20080616 830 1600 1 7.5 830 1445 FFT
47482 20080617 830 1200 1 3.5 830 1445 FFT
47482 20080619 830 1130 1 3 830 1445 FFT
47482 20080623 830 1130 1 3 830 1445 FFT
47482 20080624 830 1130 1 3 830 1445 FFT
48419 20080611 1530 1730 0 2 855 1555 FFT
48419 20080616 830 1130 0 3 855 1555 FFT
48419 20080618 830 1230 0 4 855 1555 FFT
48419 20080619 830 1130 0 3 855 1555 FFT
48419 20080623 830 1130 0 3 855 1555 FFT
48419 20080624 830 1730 0 9 855 1555 FFT
51793 20080611 1530 1730 0 0 800 1700 FFF
51793 20080618 830 1230 0 0 800 1700 FFF
51793 20080619 830 1130 0 0 800 1700 FFF
51793 20080623 830 1130 0 0 800 1700 FFF
51793 20080624 830 1830 0 0 800 1700 FFF
51793 20080625 1030 1230 0 0 800 1700 FFF
53664 20080611 1530 1730 0 0 830 1700 FFF
53664 20080616 830 1600 0 0 830 1700 FFF
53664 20080617 830 1200 0 0 830 1700 FFF
53664 20080619 830 1130 0 0 830 1700 FFF
53664 20080620 900 1100 0 0 830 1700 FFF
53664 20080624 830 1130 0 0 830 1700 FFF
54855 20080611 1530 1730 1 2 800 1700 FFT
54855 20080616 830 1600 1 7.5 800 1700 FFT
54855 20080617 830 1200 1 3.5 800 1700 FFT
54855 20080619 830 1130 1 3 800 1700 FFT
54855 20080620 900 1100 1 2 800 1700 FFT
54855 20080623 1330 1530 1 2 800 1700 FFT
54855 20080625 830 1130 1 3 800 1700 FFT
54937 20080611 1530 1730 0 5 900 1230 FFF
54937 20080619 830 1130 0 0.5 900 1230 FFF
55570 20080611 1530 1730 1 2 1700 130 FFT
55570 20080616 830 1130 1 3 1700 130 FFT
55570 20080618 830 1230 1 4 1700 130 FFT
55570 20080619 830 1130 1 3 1700 130 FFT
55570 20080623 830 1130 1 3 1700 130 FFT
55570 20080624 830 1130 1 3 1700 130 FFT
55659 20080611 1530 1730 0 0 600 1700 FFF
55659 20080617 830 1200 0 0 600 1700 FFF
55659 20080619 830 1130 0 0 600 1700 FFF
55659 20080620 900 1100 0 0 600 1700 FFF
55659 20080624 830 1130 0 0 600 1700 FFF
55673 20080611 1530 1730 0 0.49 800 1700 FFF
55673 20080616 830 1130 0 0 800 1700 FFF
55673 20080618 830 1230 0 0 800 1700 FFF
55673 20080619 830 1130 0 0 800 1700 FFF
55673 20080623 830 1300 0 0 800 1700 FFF[/tt]
I have been stepping through and looking at this code for days now and can't figure out what I need to change in order to get this right!
Any extra eyes would be appreciated!
thanks!
leslie