comp.lang.ada
 help / color / mirror / Atom feed
From: dmitry@elros.cbb-automation.de (Dmitry A. Kazakov)
Subject: Re: FILETIME <-> Ada.Real_Time.Time conversions
Date: Fri, 21 Dec 2001 10:26:02 GMT
Date: 2001-12-21T10:26:02+00:00	[thread overview]
Message-ID: <3c22f845.175317718@News.CIS.DFN.DE> (raw)
In-Reply-To: BNxU7.16478$NM4.3218496@rwcrnsc53

On Fri, 21 Dec 2001 03:13:37 GMT, "Steve Doiel"
<nospam_steved94@attbi.com> wrote:

>> >Also note: it may not be possible (read probably isn't) to represent all
>> >values of FILETIME as a Ada.Real_Time.Time value since the size of the
>> >values may differ.  As I recall the resolution of time in Ada.Real_Time
>is
>> >not specified, but a minimum resolution and range is.
>>
>> We can definitely live with smaller range and/or precision. The real
>> problem is that there is no correlation between epoch of
>> Ada.Real_Time.Split and UTC.
>>
>> Regards,
>> Dmitry Kazakov
>
>Have you considered defining your own epoch in terms of both times?
>
>You can determine the FILETIME value for your epoch using
>SystemTimeToFileTime.  I'll call this file_time_epoch.  You only have to do
>this once, then you can define the value as a program constant.

Yes, I already did it (:-)):

type FILETIME is new Interfaces.Unsigned_64;
Ticks_Of_1_Jan_2001 : constant FILETIME := 12622780800;

The rest is easy:

Ticks_Per_Second  : constant Float := 10_000_000.0;
Time_Of_1_Jan_2001 : constant Ada.Calendar.Time  :=
   Time_Of (2001, 1, 1);

function From_FILETIME (Time : FILETIME)
   return Ada.Calendar.Time
is
   Seconds : Float;
begin
   if Time > Ticks_Of_1_Jan_2001 then
      Seconds :=
         Float (Time - Ticks_Of_1_Jan_2001) / Ticks_Per_Second;
   else
      Seconds :=
        -Float (Ticks_Of_1_Jan_2001 - Time) / Ticks_Per_Second;
   end if;
   return Time_Of_1_Jan_2001 + Duration (Seconds);
exception
   when Constraint_Error =>
      raise Time_Error;
end From_FILETIME;

>You can determine the Real_Time.Time value for your epoch using
>Ada.Calendar.Time_Of.  I'll call this real_time_epoch.

How do I convert Ada.Calendar.Time to Ada.Real_Time.Time?

>To obtain a Real_Time.Time value from a subsequent FILETIME values use:
>
>  real_time_value := real_time_epoch
>                              + Ada.Real_Time.Nanoseconds( Integer(
>file_time_value - file_time_epoch ) );
>
>I'm sure you'll have to mess with the types to get things working, but I
>think this will get you there.

Regards,
Dmitry Kazakov



  reply	other threads:[~2001-12-21 10:26 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-12-18 12:53 FILETIME <-> Ada.Real_Time.Time conversions Dmitry A. Kazakov
2001-12-19  9:02 ` Alfred Hilscher
2001-12-19 13:37   ` Dmitry A. Kazakov
2001-12-19 15:06     ` Steve Doiel
2001-12-20 11:27       ` M. A. Alves
2001-12-20 15:10       ` Dmitry A. Kazakov
2001-12-21  3:13         ` Steve Doiel
2001-12-21 10:26           ` Dmitry A. Kazakov [this message]
2001-12-21 16:18             ` Steve Doiel
2001-12-24 18:02               ` Dmitry A. Kazakov
2001-12-21  6:17         ` tmoran
2001-12-21  8:51           ` Dmitry A. Kazakov
2001-12-21 18:17             ` tmoran
2001-12-24 15:59               ` Dmitry A. Kazakov
2001-12-24 18:21                 ` tmoran
2001-12-25 15:53                   ` Dmitry A. Kazakov
replies disabled

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