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-Thread: 103376,aa60d56d22a287d1 X-Google-Attributes: gid103376,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news2.google.com!news.glorb.com!aioe.org!nospam From: "John B. Matthews" Newsgroups: comp.lang.ada Subject: Re: Newbie Q: How to program in UTC (time/calendar) ? Date: Mon, 30 Mar 2009 09:45:18 -0400 Organization: The Wasteland Message-ID: References: <7f003dc4-3c3c-4e47-8ddf-d5001b310c17@g38g2000yqd.googlegroups.com> <8aad6593-efb8-441f-9eac-27cf2fe7a124@v38g2000yqb.googlegroups.com> NNTP-Posting-Host: d/vAHeaHCjT0Il2G2Ij6fw.user.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Complaints-To: abuse@aioe.org NNTP-Posting-Date: Mon, 30 Mar 2009 13:44:40 +0000 (UTC) X-Notice: Filtered by postfilter v. 0.7.7 Cancel-Lock: sha1:H2H0Qlp2XA9Qdezyj6ANZ/vMowE= User-Agent: MT-NewsWatcher/3.5.3b3 (PPC Mac OS X) Xref: g2news1.google.com comp.lang.ada:4385 Date: 2009-03-30T09:45:18-04:00 List-Id: In article <8aad6593-efb8-441f-9eac-27cf2fe7a124@v38g2000yqb.googlegroups.com>, reinkor wrote: > Sorry, I now realized that this was not so intuitive for me. > Given the following (modified) code: > > ------------------------------------------------ > with Text_IO; > use Text_IO; > > with Ada.Calendar.Formatting,Ada.Calendar.Time_Zones; > use Ada.Calendar,Ada.Calendar.Formatting,Ada.Calendar.Time_Zones; > > procedure t1 is > > package Int_Io is new Text_IO.Integer_Io (Integer); > use Int_Io; > > Time1,Time2 : Time; > > begin > > Time1 := Value("1970-01-01 00:00:00"); > Time2 := Ada.Calendar.Time_Of(1970,1,1,0.0); > > Put("Time1: ");Put(Image(Time1));New_Line; > Put("Time2: ");Put(Image(Time2));New_Line; > > Put("UTC_Time_Offset: ");Put(Integer(UTC_Time_Offset),8); > > end t1; > ------------------------------------ > > This gives the following output on my computer: > > Time1: 1970-01-01 00:00:00 > Time2: 1969-12-31 23:00:00 > UTC_Time_Offset: 120 > > The first line I now understand reflects that both "Value" and > "Image" has parameter Time_Zone = 0 (UTC). I.e. "Time1" can be > understood to have value 1970-01-01 00:00:00 (UTC). "But "Time2" is > 1970-01-01 00:00:00 *minus* one hour (only), and UTC_Time_Offset = > 120 (2 hours). I would expect that it should be UTC - 2 hours (i.e. > 1969-12-31 22:00:00 and *not* 1969-12-31 23:00:00) ? Time1 uses Ada.Calendar.Formatting.Value, with a default Time_Zone of 0. In contrast, Time2 is the result ofAda.Calendar.Time_Of, which is local time. I'm guessing you're on Summer (Daylight) time, now; but back on New Year's day of 1970, you were on standard time. Here is an example that highlights some of the differences: with Ada.Calendar; use Ada.Calendar; with Ada.Calendar.Formatting; with Ada.Calendar.Time_Zones; use type Ada.Calendar.Time_Zones.Time_Offset; with Ada.Text_IO; use Ada.Text_IO; procedure Times is T : Time := Clock; D : Time_Zones.Time_Offset; begin D := Time_Zones.UTC_Time_Offset(T); Put("UTC_Time_Offset: "); Put(D'Img); New_Line; Put("GMT: "); Put(Formatting.Image(T)); New_Line; Put("Local: "); Put(Formatting.Image(T, False, D)); New_Line; Put_Line("--"); T := Time_Of(1970, 1, 1, 0.0); Put(Formatting.Image(T)); New_Line; Put(Formatting.Image(T, False, -300)); New_Line; Put_Line("--"); T := Formatting.Time_Of(1970, 1, 1, 0.0); Put(Formatting.Image(T)); New_Line; Put(Formatting.Image(T, False, -300)); New_Line; Put(Formatting.Image(T, False, +60)); New_Line; end times; Here's what I see in a New York time zone: ./times UTC_Time_Offset: -240 GMT: 2009-03-30 13:43:26 Local: 2009-03-30 09:43:26 -- 1970-01-01 05:00:00 1970-01-01 00:00:00 -- 1970-01-01 00:00:00 1969-12-31 19:00:00 1970-01-01 01:00:00 > I here fight with my intuition :-) You may want to use the "use" clause a little more sparingly -- John B. Matthews trashgod at gmail dot com