From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,f3f07e9e53bcc4f6 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2001-12-21 02:26:04 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!fu-berlin.de!uni-berlin.de!tar-alcarin.cbb-automation.DE!not-for-mail From: dmitry@elros.cbb-automation.de (Dmitry A. Kazakov) Newsgroups: comp.lang.ada Subject: Re: FILETIME <-> Ada.Real_Time.Time conversions Date: Fri, 21 Dec 2001 10:26:02 GMT Message-ID: <3c22f845.175317718@News.CIS.DFN.DE> References: <3c1f3917.16015859@News.CIS.DFN.DE> <3C2057AF.323DFF5C@icn.siemens.de> <3c208dc5.16968437@News.CIS.DFN.DE> <3c21f386.108560406@News.CIS.DFN.DE> NNTP-Posting-Host: tar-alcarin.cbb-automation.de (212.79.194.111) X-Trace: fu-berlin.de 1008930363 18782614 212.79.194.111 (16 [77047]) X-Newsreader: Forte Free Agent 1.21/32.243 Xref: archiver1.google.com comp.lang.ada:18193 Date: 2001-12-21T10:26:02+00:00 List-Id: On Fri, 21 Dec 2001 03:13:37 GMT, "Steve Doiel" 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