• Post Reply Bookmark Topic Watch Topic
  • New Topic

Timesheet Program  RSS feed

 
meera krishna
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,


I am working on a time sheet program. I want to split punches into three parts.

Suppose an employee punch in at 8:45 am and punch out at 5:30 pm.

If the shift is 9:00 am to 4:30 , i want to split the above time period to period before shift, period in shift and period after shift.

In this case :-


8:45 am -9:00 am
9:00 am -4:30 pm
4:30 pm -5:30 pm

He had worked 15 minutes prior to his shift, 7.5 hours in his shift and 1 hour after his shift.

I want to do this to calculate regular hours and over time.

Is there any easy way to split this time interval ??
 
fred rosenberger
lowercase baba
Bartender
Posts: 12563
49
Chrome Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The first steps are always the same...forget about programming, just start thinking. Use pencil, paper and erasers. Pretend you have to explain to a 10 year old child what needs to be done. Start writing out the steps they should follow, then revise them, making them simpler and clearer.

as far as solving your problem, you need to know a couple of things...

When DID they start? When SHOULD they have started? There are three scenarios - they started early, they started on time, or they started late. The first question that comes up in my mind is - how early/late can they be? When I punched a clock, I had one place that had a 5 minute grace rule, another that had a 2 minute grace rule, and another that had a 15 minute grace rule.
 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
meera krishna wrote:I am working on a time sheet program. I want to split punches into three parts.
Suppose an employee punch in at 8:45 am and punch out at 5:30 pm.
If the shift is 9:00 am to 4:30 , i want to split the above time period to period before shift, period in shift and period after shift.

Why?

I'm not saying it's not a good idea, but it's part of Fred's "thinking" process. You need to be able to justify it; otherwise it might just be wasted effort.

What if someone works a 10pm to 6am shift? What's "before" and "after" then?

Like I say, you may have a perfectly good reason for doing this - or you may have been told to do it - but either way, you need to think about all the ramifications of the requirement.

HIH

Winston
 
Stephan van Hulst
Saloon Keeper
Posts: 7969
143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And when you're done thinking, take a look at the java.time.* package (of Java 8) which has some very useful methods to deal with time calculations (in particular, for this problem you might want to look at LocalTime and Duration).
 
sai rama krishna
Ranch Hand
Posts: 536
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
4:30 pm -5:30 pm


do you need one hour shift as above?
 
meera krishna
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, sai rama krishna

Thanks for the reply..

Each day there is only one shift one employee has to work in.Here it is 9:00 am to 4:30 pm. 4:30 pm to 5:30 pm is to be separated for calculating overtime hours

I know we can write a complex program to do this.. It is only matter of logic.

But i want to know if there is any better method such as a built in function to do this.

just like the method

samplestring.split(",");
 
meera krishna
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Winston Gutkowski ,


I already split the punches to different dates before processing it.

If an employee works from 10:00 pm to 6:00 am

I have to work on

10:00 pm to 12:00 of one day and then 12:00 to 6:00 am of next day..

Because i have to get so many details pertaining to specific day such as which is his regular shift, is it an off day/holiday for him, is he on leave etc..

Hope it is more clear to you,

Thank you..
 
meera krishna
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
fred rosenberger wrote:The first steps are always the same...forget about programming, just start thinking. Use pencil, paper and erasers. Pretend you have to explain to a 10 year old child what needs to be done. Start writing out the steps they should follow, then revise them, making them simpler and clearer.

as far as solving your problem, you need to know a couple of things...

When DID they start? When SHOULD they have started? There are three scenarios - they started early, they started on time, or they started late. The first question that comes up in my mind is - how early/late can they be? When I punched a clock, I had one place that had a 5 minute grace rule, another that had a 2 minute grace rule, and another that had a 15 minute grace rule.





I will post my code for any suggestion.

A few thinks to note..

1) Each punch( in out combination) is already split to different dates.So both in and out would be on same day.
2) shiftstart and shiftend are used to specify a shift.

Here 9:00 am to 4:30 pm
then shiftstart=9:00 am and shiftend=4:30 pm.
3)in punch and out punch are of type "timestamp"
4)After splitting the punch the output would be a two dimensional array in which first row would be the part before the shift, second row the part in shift, and third row after shift.

Here is my code.. just logic

if(in<shiftstart)
{
a[0][0]=in;
if(out>shiftstart)
{
a[0][1]=shiftstart;
in=shiftstart;
}
}


if(in>=shiftstart && in<shiftend)
{
a[1][0]=in;
if(out>shiftend)
{
a[1][1]=shiftend;
in=shiftend;
}
else
{
a[1][1]=out;
}

}

if(in>=shiftend)
{
a[2][0]=in;
a[2][1]=out;
}

Thats all..

if the punch is 8:00 am to 5:00 pm

a[0][0] and a[0][1] = 8:00 am 9:00 am
a[1][0] and a[1][1] = 9:00 am 4:30 pm
a[2][0] and a[2][1] = 4:30 pm 5:00 pm

Any suggestion or improvement please..??
 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
meera krishna wrote:Because i have to get so many details pertaining to specific day such as which is his regular shift, is it an off day/holiday for him, is he on leave etc..
Hope it is more clear to you,

Somewhat. Have you thought about dealing with fractions of days, rather than trying to split everything up by day? (for instance 48 or 96, depending on whether you deal in quarter or half hour "units")?

Then every shift-worker's time could be divided into "units on" and "units off", and you wouldn't have to worry about all this "day-splitting".

It's just a thought, but I suspect that then, with a fairly simple calculation module, it would be easy to determine when things like "holidays" start and end - especially when you have a worker that works through midnight. You could also do things like work out whether they are allowed to work (for example: have they had sufficient "off time" between shifts?).

PS: Sorry for delay in posting. I've been away.

Winston
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!