adding and subtracting time
Kenneth Brody
kenbrody at spamcop.net
Mon Jan 11 09:53:05 PST 2016
On 1/10/2016 12:52 PM, James Flanagan via Filepro-list wrote:
> I am trying to identify the most elegant way to add and subtract time with user input in filepro. The first example, where dummy ti is a 2 digit .0 variable, does not work properly. The second example, by changing ti to an 8 digit hms variable does. however, i do not want to have end users accidentally or otherwise screwing up the 00:00:00 sequence. therefore, how can i prompt a user for a 2 digit number and ultimately get filepro to remove the respective number of minutes from my tm dummy variable. Thank you very much in advance.
Use time math. If "a-b" has both "a" and "b" as time fields, filePro does
all the magic for you.
> ::ti(2,.0):
> ::input popup ti "Please enter how many minutes ago to start the downtime clock^A":
> ::tm=@tm-"00^A"{ti{"^A00":
Because the result of:
"00:" { ti { ":00"
is not a time field. It's just a string. Subtracting a string from a time
field is not the same as subtracting a time from a time field, even if that
string "looks like" a time. Basically, the above will always subtract zero
from @TM.
> ::ti(8,hms):
> ::input popup ti "Please enter how many minutes ago to start the downtime clock^A" default "00^A00^A00":
> ::tm=@tm-ti:
Here, you're actually passing a time.
There are several ways to handle this.
You could put the "00:nn:00" into a time field:
xx(8,hms) = "00:" { ti { ":00" ; tm = @tm - xx
Another option would be to convert your "00:nn:00" to a time:
tm = @tm - doedit("00:"{ti{":00","hms")
But, given that you are trying to subtract minutes from the time, simply
divide the number of minutes by "60", to convert it to hours, and subtract that:
tm = @tm - ti/"60"
Finally, since you're dealing with "clock" time, I would suggest using
"time" rather than "hms". The difference is that "time" will wrap at
midnight. Subtracting 30 minutes from 12:15AM ("00:15:00") as "hms" will
give you negative 15 minutes("-0:15:00"), whereas using "time" will give you
11:45pm ("23:45:00").
--
Kenneth Brody
More information about the Filepro-list
mailing list