comp.lang.ada
 help / color / mirror / Atom feed
From: Brian May <bam@snoopy.apana.org.au>
Subject: Re: ADA.CALENDAR and midnight
Date: Thu, 05 Aug 2004 21:46:03 +1000
Date: 2004-08-05T21:46:03+10:00	[thread overview]
Message-ID: <sa44qnherk4.fsf@snoopy.apana.org.au> (raw)
In-Reply-To: opsb9a2igcp4pfvb@bram-2

>>>>> "Nick" == Nick Roberts <nick.roberts@acm.org> writes:

    Nick> If Time_Of is called with a seconds value of 86_400.0, the value
    Nick> returned is equal to the value of Time_Of for the next day with a
    Nick> seconds value of 0.0. The value returned by the function Seconds or
    Nick> through the Seconds parameter of the procedure Split is always less
    Nick> than 86_400.0.

    Nick> So I would say that an implementation which returns 86_400.0 is
    Nick> faulty.

Hmmm.. Have to double check.

I have the following function (spot the bug!), for displaying times in
hh:mm:ss format.

>-------function To_String(The_Time : in Time) return String is
>------->-------Duration : Integer;
>------->-------H : Integer range 1..24;
>------->-------M : Integer range 0..60;
>------->-------S : Integer range 0..60;
>-------begin
>------->-------Duration := Integer(Seconds(The_Time));

>------->-------S := Duration mod 60;
>------->-------Duration := (Duration-S)/60;

>------->-------M := Duration mod 60;
>------->-------Duration := (Duration-M)/60;

>------->-------H := Duration;
>------->-------
>------->-------return Strip(Integer'Image(H))&":"
>------->------->-------&Strip(Integer'Image(M))&":"
>------->------->-------&Strip(Integer'Image(S));
>-------end To_String;

The first call is To_String(Clock + offset). When an exception occurs,
it is called as To_String(Clock) for the log message. Strip is just a
function that strips off leading white space.

This worked until around midnight. Predictably, I got a constraint
exception when assigning the value to H, because my limits are wrong.
However, when printing the exception message, this function is called
again[1], and returned the result of "24:0:0". I am kind of confused
this is possible, unless Duration was initially 86_400.0[2].

Maybe somewhere my logic is flawed, I will investigate again tomorrow.

Notes:
[1] hmmm... what happens if you get a recursive exception in Ada?
    I probably should protect my logging functions a bit better.
[2] Can someone confirm my assumption that Integer(86_399.9) = 86_399?
-- 
Brian May <bam@snoopy.apana.org.au>



  reply	other threads:[~2004-08-05 11:46 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-08-05 10:00 ADA.CALENDAR and midnight Brian May
2004-08-05 11:06 ` Frank Piron
2004-08-05 11:19 ` Nick Roberts
2004-08-05 11:46   ` Brian May [this message]
2004-08-05 12:01     ` Jano
2004-08-05 12:15       ` Jean-Pierre Rosen
2004-08-05 23:18         ` Brian May
2004-08-06  5:59           ` Martin Dowie
2004-08-06  7:34           ` Gautier
2004-08-05 13:01 ` Ada.Calendar " Jacob Sparre Andersen
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox