CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Dec 2010

    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.

  2. #2
    Join Date
    May 2006

    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.
    Posting code? Use code tags like this: [code]...Your code here...[/code]
    Click here for examples of Java Code

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Windows Mobile Development Center

Click Here to Expand Forum to Full Width

On-Demand Webinars (sponsored)

We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.