Re: Time Calculation

new topic     » goto parent     » topic index » view thread      » older message » newer message

On Sun, 28 Nov 1999 00:00:44 -0500, Ad Rienks <kwibus at ZONNET.NL>
wrote:

>On Sat, 27 Nov 1999 05:23:00 -0500, Liquid-Nitrogen Software <nitrogen_069 at
>HOTMAIL.COM> wrote:

>>Hi, I'm working on an application for my wife's work, and I need to
>>calculate how long a worker has worked, given a start time, and an end time.
>>Each start/end time is in a sequence like this:

>>{Hour(1-12), minute(0-59), second(0-59), AM/PM (0/1)}

>>I need to be able to calculate the number of seconds from the start time to
>>the end time, but the AM/PM thing is realy confusing to program with.

>>any help would be REALY appreciated!

>Why don't you use the European format; I mean you could program:

>if AMPM = 1 then    -- if it's afternoon, add 12 to hours
>    hours += 12
>end if

>Only problem I see, is for working night shifts; a day number should be
>added then.

Actually, you'd be better off if you simply check to see if the
AM/PM fields in both records (start and finish) are the same or
not:

:If start[AMPM] != end[AMPM] then    -- I always forget whether it's != or <>
:  end[HOURS] += 12
:end if

This handles night shifts with no problem.

If _very_ long shifts are a possibility (e.g., start at 10AM,
finish at 2AM next morning), you'll also want to check to see if
the end time is earlier than the start time, and if they are,
swap them, calculate the difference, and then subtract that
difference from 24 hours.  That will cover everything except a
shift that's 24 hours or longer.
--
Jeff Zeitlin
jzeitlin at cyburban.com

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu