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.6 required=5.0 tests=BAYES_00,DATE_IN_PAST_24_48 autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: a07f3367d7,59c3b3f9911c9191 X-Google-Attributes: gida07f3367d7,public,usenet X-Google-NewGroupId: yes X-Google-Language: ENGLISH,ASCII-7-bit Received: by 10.66.85.231 with SMTP id k7mr1812131paz.38.1343315841925; Thu, 26 Jul 2012 08:17:21 -0700 (PDT) Path: b9ni65040893pbl.0!nntp.google.com!border1.nntp.dca.giganews.com!border4.nntp.dca.giganews.com!border2.nntp.dca.giganews.com!nntp.giganews.com!border6.newsrouter.astraweb.com!news.astraweb.com!border6.a.newsrouter.astraweb.com!feed.xsnews.nl!border-1.ams.xsnews.nl!newsfeed.straub-nv.de!news.swapon.de!news.glorb.com!npeer02.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail From: Adam Beneschan Newsgroups: comp.lang.ada Subject: Re: Ada.Calendar and NTP (and Unix Epoch) Date: Tue, 24 Jul 2012 09:26:46 -0700 (PDT) Organization: http://groups.google.com Message-ID: <5513b36d-560f-42ee-b6b6-bdb456097780@googlegroups.com> References: <500dc548$0$2936$f40e02c5@shockwave.dk.telia.net> <18893cca-baa2-4930-bfb4-4c4f7eb7e983@googlegroups.com> <60c9c92b-280b-4178-a410-2bc8756c6b5e@googlegroups.com> NNTP-Posting-Host: 66.126.103.122 Mime-Version: 1.0 X-Trace: posting.google.com 1343147630 28609 127.0.0.1 (24 Jul 2012 16:33:50 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Tue, 24 Jul 2012 16:33:50 +0000 (UTC) In-Reply-To: <60c9c92b-280b-4178-a410-2bc8756c6b5e@googlegroups.com> Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=66.126.103.122; posting-account=duW0ogkAAABjRdnxgLGXDfna0Gc6XqmQ User-Agent: G2/1.0 X-Received-Bytes: 3807 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Date: 2012-07-24T09:26:46-07:00 List-Id: On Tuesday, July 24, 2012 12:24:17 AM UTC-7, erlo....@gmail.com wrote: > NTP epoch 1 started 1-1-1900 0:00, just like the Unix epoch started 1-1-1= 970 > 0:00. So when I get a time from an NTP-server, I get seconds from the sta= rt of=20 > the NTP epoch. All right, then. First of all, I don't know what Ada.Calendar.Conversions = is. It's not defined by the language, but rather by one particular impleme= ntor. IMHO you should prefer to use the language-defined packages if at al= l feasible. It will be more portable, plus a lot of work goes into making = sure things in the Standard have precise definitions. =20 If you have an integer value N representing the number of seconds since 1/1= /1900, I think you want to convert this to an Ada.Calendar.Time that repres= ents the same point in time, so that you can then compare it easily to anot= her value of Ada.Calendar.Time. If Ada had a Time that represented 1/1/190= 0, you could just take that Time and add N seconds to it. But, as you foun= d out, it didn't, so the first step is to convert N to a value N2 represent= ing the number of seconds since 1/1/1901. You can do this by setting N2 := =3D N - constant (you'd better be able to figure out what the constant is!)= . As I implied before, if N2 is negative then some very weird stuff is goi= ng on, so don't worry about that possibility. Now, use Ada.Calendar.Time_Of to create a Time T_Base representing 1/1/1901= .=20 Or, better, if the NTP time is always UTC, then you should probably use Ada= .Calendar.Formatting.Time_Of to create a time that represents midnight of 1= /1/1901 in UTC time; I think you do this by passing Time_Zone =3D> Ada.Cale= ndar.Time_Zones.UTC_Time_Offset. (Somebody please correct me if I'm suppos= ed to negate the value.) Now, you *may* be able to create a Time T representing your NTP time just b= y setting T :=3D T_Base + Duration(N2); This will work on some implementations. On other implementations, though, = Duration isn't guaranteed to have a range that covers 112 years or more (th= e language only requires that it covers one day). You can get around this = by breaking N2 into "days" and "seconds": N2_Days :=3D N2 / 86_400; N2_Seconds :=3D N2 mod 86_400; T :=3D T_Base + Day_Count (N2_Days) + Duration (N2_Seconds); The Day_Count type is defined in Ada.Calendar.Arithmetic. Now T will be a Time value that represents the point in time that occurred = N seconds after midnight on 1/1/1900 (UTC), and you can compare this to any= other Time value. -- Adam