comp.lang.ada
 help / color / mirror / Atom feed
* Help - time to string query
@ 2002-12-11  8:30 TAMS Team
  2002-12-12  3:52 ` SteveD
  0 siblings, 1 reply; 5+ messages in thread
From: TAMS Team @ 2002-12-11  8:30 UTC (permalink / raw)


Hi!

Hopefully this is a very simple question (from a very simple programmer!).
I'm using a parameter of type ada.real_time.time in my program and I need to
be able to convert this into a string.  Can't suss how to achieve this, and
it's getting to the brick wall/head banging stage.  I'm sure I should be
using something like 'image, but can't figure out how to do it.

How do I do it?!

Cheers,

Mike Clarke





^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Help - time to string query
@ 2002-12-11  8:48 Grein, Christoph
  0 siblings, 0 replies; 5+ messages in thread
From: Grein, Christoph @ 2002-12-11  8:48 UTC (permalink / raw)


> Hopefully this is a very simple question (from a very simple programmer!).
> I'm using a parameter of type ada.real_time.time in my program and I need to
> be able to convert this into a string.  Can't suss how to achieve this, and
> it's getting to the brick wall/head banging stage.  I'm sure I should be
> using something like 'image, but can't figure out how to do it.

Use Ada.Real_Time.Split to produce an integer type Seconds_Count. You can then use 'Image on the 
result.



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Help - time to string query
  2002-12-11  8:30 Help - time to string query TAMS Team
@ 2002-12-12  3:52 ` SteveD
  2002-12-12 15:42   ` Toshitaka Kumano
  0 siblings, 1 reply; 5+ messages in thread
From: SteveD @ 2002-12-12  3:52 UTC (permalink / raw)


"TAMS Team" <tamsteam@rolls-royce-rps.demon.co.uk> wrote in message
news:at6t3k$n63$1$830fa7a5@news.demon.co.uk...
> Hi!
>
> Hopefully this is a very simple question (from a very simple programmer!).
> I'm using a parameter of type ada.real_time.time in my program and I need
to
> be able to convert this into a string.  Can't suss how to achieve this,
and
> it's getting to the brick wall/head banging stage.  I'm sure I should be
> using something like 'image, but can't figure out how to do it.
>
> How do I do it?!

Ada provides two packages for dealing with time: Ada.Calendar and
Ada.Real_Time.
If you want to deal with time as in time of day use Ada.Calendar.  If you
want to deal with time as in measuring or delaying for precise times use
Ada.Real_Time.

Time values returned from Ada.Real_Time reflect the time since "epoch" (LRM
A.8.28) which may have no particular relation to the time of day.

The difference between two Ada.Real_Time.Time values is calculated using the
"-" operator and results in a value of type Ada.Real_Time.Time_Span.  The
function Ada.Real_Time.To_Duration can be used to convert a time span to a
"Duration" which may be converted to a floating point value of seconds.

I often use Ada.Real_Time to do precise timing.  Forr example:

   start_Time := Ada.Real_Time.Clock;
   for I in A'range loop
      Processing( A(I) );
   end loop;
   End_Time := Ada.Real_Time.Clock;
   Text_Io.Put( "Time for array based loop is " );
   Float_Text_Io.Put( Float( Ada.Real_Time.To_Duration( end_Time -
Start_TIme ) ), 3, 5, 0 );
   Text_Io.New_Line;

Oh, and sorry if I'm off target on what you're asking.

Steve
(The Duck)

> Cheers,
>
> Mike Clarke
>
>





^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Help - time to string query
  2002-12-12  3:52 ` SteveD
@ 2002-12-12 15:42   ` Toshitaka Kumano
  2002-12-12 18:26     ` Randy Brukardt
  0 siblings, 1 reply; 5+ messages in thread
From: Toshitaka Kumano @ 2002-12-12 15:42 UTC (permalink / raw)


SteveD wrote:
>    Float_Text_Io.Put( Float( Ada.Real_Time.To_Duration( end_Time -
> Start_TIme ) ), 3, 5, 0 );
>    Text_Io.New_Line;

OR simply,

... use Ada.Real_Time;
Text_IO.Put_Line (Duration'Image (To_Duration (end_Time - Start_TIme)));

-- If converting to float, you might lose precision. 


OR if you prefer somewhat "current" time than relative time_span, 

... use Ada.Real_Time;
Text_IO.Put_Line (Duration'Image (To_Duration (Clock - Time_First)));

-- This shows total time_span since "epoch".
-- In this case, because the time_span value may be rather large,
-- in some compilers (e.g. GNAT), you may lose precision in Duration'Image().

-- 
Toshitaka Kumano
Kamakura, Japan



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Help - time to string query
  2002-12-12 15:42   ` Toshitaka Kumano
@ 2002-12-12 18:26     ` Randy Brukardt
  0 siblings, 0 replies; 5+ messages in thread
From: Randy Brukardt @ 2002-12-12 18:26 UTC (permalink / raw)


Toshitaka Kumano wrote in message ...
>SteveD wrote:
>>    Float_Text_Io.Put( Float( Ada.Real_Time.To_Duration( end_Time -
>> Start_TIme ) ), 3, 5, 0 );
>>    Text_Io.New_Line;
>
>OR simply,
>
>... use Ada.Real_Time;
>Text_IO.Put_Line (Duration'Image (To_Duration (end_Time -
Start_TIme)));
>
>-- If converting to float, you might lose precision.


Right. And if you care about the formatting, use an instantiation of
Fixed_IO (then you won't lose precision either):

    package Dur_IO is new Ada.Text_IO.Fixed_IO(Duration);

    ...
   Dur_IO.Put (Ada.Real_Time.To_Duration (End_Time - Start_Time ), 3, 5,
0 );

It's the same number of lines, after all (as we're replacing the "with
Float_Text_IO;" by the instantiation).

                   Randy.






^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2002-12-12 18:26 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-12-11  8:30 Help - time to string query TAMS Team
2002-12-12  3:52 ` SteveD
2002-12-12 15:42   ` Toshitaka Kumano
2002-12-12 18:26     ` Randy Brukardt
  -- strict thread matches above, loose matches on Subject: below --
2002-12-11  8:48 Grein, Christoph

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