October 10th, 2012, 12:55 AM
Calculate a timespan of work of an employee in an HR system
There are 2 pay rates - normal rates and overtime rates.
An employee can work in many different hour combination say
* 2012-10-30 08:00 to 2012-10-30 18:30
* 2012-10-30 10:30 to 2012-10-30 15:00
* 2012-10-30 07:00 to 2012-11-02 23:00
Despite of leaves and other allowances, how do you calculate their time spans of work
Say in the first day, he works from 7:00 - 23:59 and 2 full days and the last day 0:00 to 23:00 etc
My first thought was to convert this to a Calendar and compare the dates first and work out the full days worked.
if there is at least one full day, I subtract 23:59 from his on-duty time
and subtract his off-duty time from 0:00.
And then, I compare the range of time with the normal working-hours and OT hours
The problem is how do you convert a timestamp data type to calendar?
Am I on the right track?
Last edited by lucky6969b; October 10th, 2012 at 01:18 AM.
October 10th, 2012, 06:41 AM
Re: Calculate a timespan of work of an employee in an HR system
You haven't said what your timestamp data type is but if it is a java.sql.Timestamp then it has a getTime() method which returns the milliseconds since epoch which can be used to configure the Calendar via it's setTimeInMillis() method.
Personally I'd use JodaTime as it has better features for handling date time comparisons.
Click Here to Expand Forum to Full Width
This is a CodeGuru survey question.