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.9 required=5.0 tests=BAYES_00,FORGED_GMAIL_RCVD, FREEMAIL_FROM autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,aa60d56d22a287d1 X-Google-Attributes: gid103376,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII Path: g2news2.google.com!postnews.google.com!v38g2000yqb.googlegroups.com!not-for-mail From: reinkor Newsgroups: comp.lang.ada Subject: Re: Newbie Q: How to program in UTC (time/calendar) ? Date: Mon, 30 Mar 2009 05:37:25 -0700 (PDT) Organization: http://groups.google.com Message-ID: <8aad6593-efb8-441f-9eac-27cf2fe7a124@v38g2000yqb.googlegroups.com> References: <7f003dc4-3c3c-4e47-8ddf-d5001b310c17@g38g2000yqd.googlegroups.com> NNTP-Posting-Host: 193.156.99.217 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: posting.google.com 1238416645 29462 127.0.0.1 (30 Mar 2009 12:37:25 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Mon, 30 Mar 2009 12:37:25 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: v38g2000yqb.googlegroups.com; posting-host=193.156.99.217; posting-account=bPTmZAoAAAC_6HP9XLKB9aAAxBa6BuOR User-Agent: G2/1.0 X-HTTP-UserAgent: Opera/9.64 (X11; Linux x86_64; U; en) Presto/2.1.1,gzip(gfe),gzip(gfe) Xref: g2news2.google.com comp.lang.ada:5354 Date: 2009-03-30T05:37:25-07:00 List-Id: 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 :=3D Value("1970-01-01 00:00:00"); Time2 :=3D 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 =3D 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 =3D 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) ? I here fight with my intuition :-) reinert On 27 Mar, 18:58, "Jeffrey R. Carter" wrote: > reinkor wrote: > > =A0 =A0Time1 :=3D Value("1970-01-01 00:00:00"); > > =A0 =A0Put(Image(Time1));New_Line; > > =A0 =A0Put(Image(Ada.Calendar.Time_Of(1970,1,1,Duration(0)))); > > > 1970-01-01 00:00:00 > > 1969-12-31 23:00:00 > > > The last output line here reflects the fact that Ada takes > > "local time" from the computer - and the result would be > > different if I wait to run my program till next Monday > > (this weekend we change to summer daylight saving time). > > No. It reflects the fact that Image takes an Ada.Calendar.Time_Zones.Time= _Offset > parameter (Time_Zone) that defaults to 0 (UTC). Image is therefore conver= ting > the supplied time from your computer's offset > (Ada.Calendar.Time_Zones.UTC_Time_Offset) to the default offset of 0. You= r > offset seems to be 60 (GMT + 1 hr). To get the image of what you passed t= o it, > you must specify an offset of UTC_Time_Offset. > > The 1st value comes out as expected because Value also takes an > Ada.Calendar.Time_Zones.Time_Offset parameter (Time_Zone) that defaults t= o 0 > (UTC). It is therefore taking the supplied string, interpreting it as a t= ime in > UTC, and converting it to the corresponding time for your computer's offs= et > (UTC_Time_Offset). When you pass this time to Image with the default for > Time_Zone, the conversion is then reversed as described above. > > You can compare the representations provided by Image with the values obt= ained > by Ada.Calendar.Split to observe the conversions that the operations in > Ada.Calendar.Formatting perform. > > Two comments on your code: "with Ada.Calendar.Formatting;" makes Ada, > Ada.Calendar, and Ada.Calendar.Formatting visible; there is no need to al= so with > Ada.Calendar. > > I cannot understand why you would say "Duration (0)" when "0.0" is cleare= r and > shorter. > > -- > Jeff Carter > "My mind is a raging torrent, flooded with rivulets of > thought, cascading into a waterfall of creative alternatives." > Blazing Saddles > 89