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: g2news2.google.com!news2.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!wns14feed!worldnet.att.net!attbi_s21.POSTED!53ab2750!not-for-mail From: "Jeffrey R. Carter" User-Agent: Thunderbird 2.0.0.21 (Windows/20090302) MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: Newbie Q: How to program in UTC (time/calendar) ? References: <7f003dc4-3c3c-4e47-8ddf-d5001b310c17@g38g2000yqd.googlegroups.com> In-Reply-To: <7f003dc4-3c3c-4e47-8ddf-d5001b310c17@g38g2000yqd.googlegroups.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Message-ID: NNTP-Posting-Host: 173.16.158.68 X-Complaints-To: abuse@mchsi.com X-Trace: attbi_s21 1238173111 173.16.158.68 (Fri, 27 Mar 2009 16:58:31 GMT) NNTP-Posting-Date: Fri, 27 Mar 2009 16:58:31 GMT Organization: AT&T ASP.att.net Date: Fri, 27 Mar 2009 16:58:31 GMT Xref: g2news2.google.com comp.lang.ada:5345 Date: 2009-03-27T16:58:31+00:00 List-Id: reinkor wrote: > Time1 := Value("1970-01-01 00:00:00"); > Put(Image(Time1));New_Line; > Put(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 converting the supplied time from your computer's offset (Ada.Calendar.Time_Zones.UTC_Time_Offset) to the default offset of 0. Your offset seems to be 60 (GMT + 1 hr). To get the image of what you passed to 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 to 0 (UTC). It is therefore taking the supplied string, interpreting it as a time in UTC, and converting it to the corresponding time for your computer's offset (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 obtained 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 also with Ada.Calendar. I cannot understand why you would say "Duration (0)" when "0.0" is clearer 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