comp.lang.ada
 help / color / mirror / Atom feed
* Ada.Calendar Question
@ 2012-07-20 17:18 awdorrin
  2012-07-20 17:59 ` Adam Beneschan
  0 siblings, 1 reply; 5+ messages in thread
From: awdorrin @ 2012-07-20 17:18 UTC (permalink / raw)


I have been looking at the Ada.Calendar and Ada.Real_Time packages, trying to update some old Ada code, which interfaces to C.

How do I access the 'Conversion_Operations' package defined within Ada.Calendar?

I have been trying to make use of:
 Conversion_Operations.To_Ada_Time( Unix_Time : Long-Integer );
 Conversion_Operations.To_Struct_Timespec()
and
 Conversion_Operations.To_Duration()

I have seen the C specific versions in Ada.Calendar.Conversion, but those all use the Interfaces.C package types.








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

* Re: Ada.Calendar Question
  2012-07-20 17:18 Ada.Calendar Question awdorrin
@ 2012-07-20 17:59 ` Adam Beneschan
  2012-07-20 18:24   ` awdorrin
  0 siblings, 1 reply; 5+ messages in thread
From: Adam Beneschan @ 2012-07-20 17:59 UTC (permalink / raw)


On Friday, July 20, 2012 10:18:22 AM UTC-7, awdorrin wrote:
> I have been looking at the Ada.Calendar and Ada.Real_Time packages, trying to update some old Ada code, which interfaces to C.
> 
> How do I access the 'Conversion_Operations' package defined within
> Ada.Calendar?

This is defined in the *private* part of one implementor's implementation of Ada.Calendar.  They could easily change the semantics of those routines in a future release.  So attempting to access them seems like a very bad idea.

                          -- Adam



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

* Re: Ada.Calendar Question
  2012-07-20 17:59 ` Adam Beneschan
@ 2012-07-20 18:24   ` awdorrin
  2012-07-20 18:51     ` Simon Wright
  0 siblings, 1 reply; 5+ messages in thread
From: awdorrin @ 2012-07-20 18:24 UTC (permalink / raw)


I finally realized that these nested packages are tagged private. Now it makes sense.

It looks like the 'easiest' way for me to get from the stored 'seconds' and 'nanoseconds' is to do the following:

procedure Example( sec : in Integer; nSec : in Integer) is

  T : Ada.Calendar.Time;

begin

  T := Ada.Calendar.Conversions.To_Ada_Time(0) -- to get epoch
    + Ada.Calendar.Conversions.To_Duration( long(sec), long(nSec));

  Put_Line( Ada.Calendar.Formatting.Image(
    Date => T, Include_Time_Fraction => True, 
    Time_Zone => Ada.Calendar.Time_Zones.UTC_Time_Offset(T) );

end Example;

The 'To_Duration' is a bit annoying, requiring withing the 'Interfaces.C' package for the 'long' type, but it does work fine.



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

* Re: Ada.Calendar Question
  2012-07-20 18:24   ` awdorrin
@ 2012-07-20 18:51     ` Simon Wright
  2012-07-23 13:23       ` awdorrin
  0 siblings, 1 reply; 5+ messages in thread
From: Simon Wright @ 2012-07-20 18:51 UTC (permalink / raw)


awdorrin <awdorrin@gmail.com> writes:

> procedure Example( sec : in Integer; nSec : in Integer) is
>
>   T : Ada.Calendar.Time;
>
> begin
>
>   T := Ada.Calendar.Conversions.To_Ada_Time(0) -- to get epoch
>     + Ada.Calendar.Conversions.To_Duration( long(sec), long(nSec));

It depends what you mean by 'epoch'. If it's 1 Jan 1970 (as for Unix),
then you should be aware that at the change to Ada 05 GNAT changed
representations so that 1 Jan 1970 is no longer stored as 0.

      use type Ada.Calendar.Time;
   begin
      T := Ada.Calendar.Time_Of (Year => 1970, Month => 1, Day => 1)
             + Duration (sec) + Duration (nSec) / 1.0e9;



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

* Re: Ada.Calendar Question
  2012-07-20 18:51     ` Simon Wright
@ 2012-07-23 13:23       ` awdorrin
  0 siblings, 0 replies; 5+ messages in thread
From: awdorrin @ 2012-07-23 13:23 UTC (permalink / raw)


On Friday, July 20, 2012 2:51:23 PM UTC-4, Simon Wright wrote:
> 
> It depends what you mean by &#39;epoch&#39;. If it&#39;s 1 Jan 1970 (as for Unix),
> then you should be aware that at the change to Ada 05 GNAT changed
> representations so that 1 Jan 1970 is no longer stored as 0.

Since I'm interfacing to C routines, I do mean 1-Jan-1970.

I do like your suggestion, it is much cleaner and I don't need to include either the Interfaces.C or Ada.Calendar.Conversions packages.

Thanks!



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

end of thread, other threads:[~2012-07-26 15:07 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-07-20 17:18 Ada.Calendar Question awdorrin
2012-07-20 17:59 ` Adam Beneschan
2012-07-20 18:24   ` awdorrin
2012-07-20 18:51     ` Simon Wright
2012-07-23 13:23       ` awdorrin

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