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=-0.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: a07f3367d7,e2ba2bcbcb635510 X-Google-Attributes: gida07f3367d7,public,usenet X-Google-NewGroupId: yes X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!news4.google.com!feeder.news-service.com!newsfeed0.kamp.net!newsfeed.kamp.net!newsfeed.freenet.de!bolzen.all.de!newsfeed.ision.net!newsfeed2.easynews.net!ision!newsfeed.arcor.de!newsspool4.arcor-online.net!news.arcor.de.POSTED!not-for-mail From: "Dmitry A. Kazakov" Subject: Re: Dates and Times in GNAT on Linux Newsgroups: comp.lang.ada User-Agent: 40tude_Dialog/2.0.15.1 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Reply-To: mailbox@dmitry-kazakov.de Organization: cbb software GmbH References: <95e64$4aad119b$4a336034$30511@API-DIGITAL.COM> Date: Sun, 13 Sep 2009 18:17:27 +0200 Message-ID: <1phb6ttjutj63.17ukuloo3axox$.dlg@40tude.net> NNTP-Posting-Date: 13 Sep 2009 18:17:28 CEST NNTP-Posting-Host: e582037a.newsspool4.arcor-online.net X-Trace: DXC=aP6LIO^4jV7]E=H1Q9`7874IUKQORO?DNcfSJ;bb[5IRnRBaCd0oUfX32Edf9WVXPC1?J=U7 X-Complaints-To: usenet-abuse@arcor.de Xref: g2news2.google.com comp.lang.ada:8312 Date: 2009-09-13T18:17:28+02:00 List-Id: On Sun, 13 Sep 2009 10:36:58 -0500, Marc A. Criley wrote: > I'm confused about GNAT's implementation of some aspects of date/time > processing on Linux. I'm running GNAT GPL 2009 on Ubuntu Linux; I also > live in the US Central Time Zone and Daylight Savings Time is in effect > as I write this. > > This is probably a stupid misunderstanding or mistaken expectations or > feature misuse on my part, but I would really like to know what's going on. > > Basically what I'm trying to do is take the time I got from from > Ada.Real.Clock and convert it to a date/time rep. The result I'm coming > up with is always an hour off. (DST effect? Read on...) Code will follow > in a bit. > > I discovered that GNAT's implementation of Ada.Real_Time.Clock returns > the number of seconds since the UTC epoch start, which is very nice and > very handy. Using Real_Time.Split I can get that number of seconds into > a visible type, Seconds_Count. > > I can then get the start of the Unix/UTC epoch via: > UTC_Epoch_Start := Calendar.Time_Of(1970, 1, 1) > + Duration(Calendar.Time_Zones.UTC_Offset * 60); > -- For where I live, right now the UTC_Offset is -300 minutes, > -- i.e. -5 hours. > > Adding the Real_Time seconds count (as a Duration) to UTC_Epoch_Start > gives a Calendar.Time value containing the current UTC time, from which > I can generate an image...which is an hour off from the correct value. > > So I'm thinking it might be a DST problem, but shouldn't the affected > Calendar procedures be taking that into account? Hmm, it seems otherwise. It is DST now, and no DST for the time point you calculated the epoch. So the epoch time is incoherent to the time now. Your calculation presumes that (T + D1) + D2 = T + (D1 + D2) holds for any T, a political time and any D1, D2, durations. That is wrong for political time. (Ada.Calendar arithmetic is broken, when Ada.Calendar.Time is political time) The problem is that UTC_Offset is not a constant, but itself is a function of UTC time. > Maybe my conversion from Real_Time.Time to Calendar.Time is flawed...I > don't know. Any explanation or clarifications would be much appreciated. You have to sum all clock skews (forth and back) within the interval between the epoch and the time being converted. These skews will sum up to either 0 or 1 hour, or maybe 1 hour + possibly n leap seconds. Not an easy task. P.S. I wished Ada.Calendar.Time_Zones weren't broken. This was discussed in c.l.a. a couple of months ago. -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de