Translating with DrWatson… this can take a few seconds the first time.
This is a genuine, complex translation. DrWatson protects commands, error codes, and log output while naturally translating the surrounding text. It’s translated once and saved.
Obnoxio The Clown posted a 4GL function validating an integer HHMM time. monkeys paw said it worked well. Jonathan Leffler pointed out that negative values such as -9999 would pass the hour test, and Obnoxio replied that his code already rejected negative input at the start, so the check was covered. Resolved.
Auto-generated by Claude from the posts below — may be imperfect; read the full thread.
Obnoxio The Clown wrote:
> monkeys paw wrote:
>
>> Hi all, I need an integer to conform to military time, so
>> i have to check that the tens digit is no more than 59,
>> i.e. 2159 is a valid time, 2162 is not.
>>
>> I've not seen much "arithmetic" done in 4gl so could someone
>> suggest the best way to check an int for this condition.
>>
>>
>
> What's wrong with a DATETIME HOUR TO SECOND ?
>
>
Anyway, no 4GL compiler handy, plus there's all sorts of assumptions here:
FUNCTION validate_time (lv_time_in)
DEFINE lv_time_in SMALLINT
DEFINE lv_hour, lv_minute SMALLINT
IF lv_time_in < 0
THEN
ERROR "Negative time not allowed"
RETURN FALSE
END IF
LET lv_hour = lv_time_in / 100
LET lv_minute = lv_time_in - (lv_hour * 100)
IF lv_hour < 23
AND lv_minute < 60
AND lv_minute >= 0
THEN
RETURN TRUE
ELSE
ERROR "Invalid time"
RETURN FALSE
END IF
END FUNCTION
--
Cheers,
Obnoxio the Clown
http://obotheclown.blogspot.com
This code snippet works perfectly, no compile probs even!
The handling of the modulus had escaped me, thanks for
jarring the cranium, OTC.
> Obnoxio The Clown wrote:
>> monkeys paw wrote:
>>
>>> Hi all, I need an integer to conform to military time, so
>>> i have to check that the tens digit is no more than 59,
>>> i.e. 2159 is a valid time, 2162 is not.
>>>
>>> I've not seen much "arithmetic" done in 4gl so could someone
>>> suggest the best way to check an int for this condition.
>>>
>>
>> What's wrong with a DATETIME HOUR TO SECOND ?
>>
>>
>
> Anyway, no 4GL compiler handy, plus there's all sorts of assumptions here:
>
> FUNCTION validate_time (lv_time_in)
> DEFINE lv_time_in SMALLINT
> DEFINE lv_hour, lv_minute SMALLINT
>
> IF lv_time_in < 0
> THEN
> ERROR "Negative time not allowed"
> RETURN FALSE
> END IF
>
> LET lv_hour = lv_time_in / 100
> LET lv_minute = lv_time_in - (lv_hour * 100)
>
> IF lv_hour < 23
> AND lv_minute < 60
> AND lv_minute >= 0
> THEN
> RETURN TRUE
> ELSE
> ERROR "Invalid time"
> RETURN FALSE
> END IF
> END FUNCTION
>
monkeys paw wrote:
> This code snippet works perfectly, no compile probs even!
>
Am I allowed to preen? Just a little? :o)
--
Cheers,
Obnoxio the Clown
http://obotheclown.blogspot.com
On Sep 16, 2:22 pm, Obnoxio The Clown <obno...@serendipita.com> wrote:
> monkeys paw wrote:
> > This code snippet works perfectly, no compile probs even!
>
> Am I allowed to preen? Just a little? :o)
Just a little. But only a little.
You forgot to check that the value was not negative, so -9999 passes
your test for hours (< 23) -- you did check for non-negative minutes,
but if I chose -100, that would have a remainder of zero, so the
minutes would be valid and the hours would be OK too.
Just a tiny bit of help from one nit-picker to another.
-=JL=-
Jonathan Leffler wrote:
> On Sep 16, 2:22 pm, Obnoxio The Clown <obno...@serendipita.com> wrote:
>
>> monkeys paw wrote:
>>
>>> This code snippet works perfectly, no compile probs even!
>>>
>> Am I allowed to preen? Just a little? :o)
>>
>
> Just a little. But only a little.
>
> You forgot to check that the value was not negative, so -9999 passes
> your test for hours (< 23) -- you did check for non-negative minutes,
> but if I chose -100, that would have a remainder of zero, so the
> minutes would be valid and the hours would be OK too.
>
> Just a tiny bit of help from one nit-picker to another.
>
Ahem:
IF lv_time_in < 0
THEN
ERROR "Negative time not allowed"
RETURN FALSE
END IF
--
Cheers,
Obnoxio the Clown
http://obotheclown.blogspot.com
We use strictly necessary cookies to make this site work. With your
consent we’d also use optional cookies for analytics and marketing. You can accept all,
reject all, or choose. Read our Cookie Policy.