Undefined Time

I need to compare a time-field with the actual time less 90 minutes. The code i created was IF (tab2.“End time” < (TIME - 5400000)) THEN BEGIN Compiling the code shows no error, but when i try to execute the report i always get the error message ‘An undefined time can’t be used in time calculation’. Going back into the report the word TIME is always converted to ‘Time’. Using a variable like NewTime := TIME; NewTime := NewTime - 5400000; doesn’t solve the problem. How can i calculate the time correctly ?? Stefan Weinreich Billing Analyst

stefan, ur code works fine. I just created a table with 2 fields with starttime as one of field with data type as Time. in Onvalidate() of Starttime field I just wrote ur condition… IF (Starttime < (TIME - 5400000)) THEN MESSAGE(‘Time is less than 90 mins Less Current time’) ELSE MESSAGE(‘Time is greater than or equal to 90 mins Less Current time’); Taj

Hey Taj, odd… before i posted my problem i created a little report with just a single line: MESSAGE(‘current time is %1\calculated time is %2’, TIME, (TIME - 5400000)); this worked fine, but when i use the code shown above i get the error message. Perhaps there has something been changed in our version (DE 2.50) ? Stefan Weinreich Billing Analyst

Stefan, I can reproduce your problem: In table Tab2 there is a field called ‘Time’. The code looks like this: With Tab2 do IF “End Time” < (Time - 5400000) THEN … (This also explains the conversion from TIME to Time). If this is your problem, you should rename the field called Time in your Table Tab2. Willy

Hey Willy, yes, you’re right. There was a field called “Time”. Setting the “EndTime” Variable as global and initialising it during the report-init-phase everything worked fine. thanks a lot ! Stefan Weinreich Billing Analyst

Attention ! The Code line

IF (Starttime < (TIME - 5400000)) THEN

will not work if TIME is exactly 5400000! In this case the right bracket would be reduced to

IF (Starttime < (0)) THEN

And Navision will complain that it cannot compare Starttime with an undefined Time Value (Zero). If you want to use Time Arithmetic it’s a good Idea to convert the time into a decimal and vice-versa:

Function TimeToDecimal (T : Time) D : Decimal;

BEGIN
  IF T = 0T THEN
    EXIT(0.0);
  d := T- 000001T + 1000.0;
  EXIT(d / 3600000);
END;

Function DecimalToTime (d : Decimal) T : Time;

BEGIN
  IF T = 0T THEN
    EXIT(0.0);
  d := T- 000001T + 1000.0;
  EXIT(d / 3600000);
END;

As you can see I avoid the Time=Zero-Problem by adding and subtracting one Second. ------- With best regards from Switzerland Marcus Fabian Edited by - fabian on 2001 Aug 14 01:29:31

I’ve just tried what happens, if TIME - 5400000 results in a value (or time) less 0. There the time was correctly converted in the new 24hours-time (21:59:03 or something else). Normally 0:00 is a valid time. So if you’re right (i didn’t check this yet) the system couldn’t handle midnight (0:00) ?! Stefan Weinreich Billing Analyst

Quite correct. To be precise: The system cannot handle midnight if the Time is used in time-calculations. Now, coming back to your example with 90 minutes or 5’400’000 Milliseconds: Let’s assume you have a job which should break after 90 Minutes maximum execution time:


StartTime := TIME;
REPEAT
UNTIL (Finished) or ((TIME - 5400000) > StartTime)

You might end up in troubles if the job exceeds midnight respectively any time between midnight and 1:30 as the result of (TIME- 5400000) will always be negative and therefore be smaller than StartTime which is >=0 You could however change

((TIME - 5400000) > StartTime) 

into the positive Range using

((StartTime + 5400000) < Time) 

and take the change to the next day into consideration:

IF ((StartTime + 5400000) < Time) OR
(Today > StartDate)

------- With best regards from Switzerland Marcus Fabian