comp.lang.ada
 help / color / mirror / Atom feed
From: Niklas Holsti <niklas.holsti@tidorum.invalid>
Subject: Re: Trivial question: how to avoid confusing sec, min, hour and day in a program?
Date: Sun, 5 Sep 2021 15:42:49 +0300	[thread overview]
Message-ID: <ipjsa9Fi441U1@mid.individual.net> (raw)
In-Reply-To: <sh1rha$14d6$1@gioia.aioe.org>

On 2021-09-05 10:27, Dmitry A. Kazakov wrote:
> On 2021-09-05 08:56, reinert wrote:
>> Anybody with good ideas on how (in a simplest possible way) to avoid 
>> to confuse between representation of time as seconds, minutes, hours 
>> and days in an Ada program?
> 
> Just use the standard type Duration.


But note that:

- Duration is a fixed-point type, not floating point, so it has a fixed 
resolution, Duration'Small.

- The resolution and range of Duration are implementation-defined, and 
the standard does not guarantee much. RM 9.6(27) says:

"The implementation of the type Duration shall allow representation of 
time intervals (both positive and negative) up to at least 86400 seconds 
(one day); Duration'Small shall not be greater than twenty milliseconds."

(Aside: I wonder why this paragraph is not in RM A.1, "The Package 
Standard", where the Duration type is introduced.)

If you want your code to be portable, define your own type for "time in 
seconds", choosing the properties your application needs.

That said, I believe that GNAT versions typically provide a 64-bit 
Duration type that has enough precision and range for most applications 
dealing with times on human scales. But perhaps not on nuclear, 
geological or astrophysical scales.

  reply	other threads:[~2021-09-05 12:42 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-05  6:56 Trivial question: how to avoid confusing sec, min, hour and day in a program? reinert
2021-09-05  7:27 ` Dmitry A. Kazakov
2021-09-05 12:42   ` Niklas Holsti [this message]
2021-09-06  7:20   ` ldries46
2021-09-06  9:47     ` Dmitry A. Kazakov
2021-09-06 13:06       ` ldries46
2021-09-06 13:43         ` J-P. Rosen
2021-09-06 14:13           ` ldries46
2021-09-06 15:10             ` Dennis Lee Bieber
2021-09-06 15:55       ` AdaMagica
2021-09-08 22:00     ` Shark8
2021-10-24  6:52   ` reinert
2021-10-24  7:24     ` J-P. Rosen
2021-10-24 10:39       ` Jeffrey R.Carter
2021-10-24 10:08     ` G.B.
2021-10-24 10:48     ` Simon Wright
2021-10-24 12:09     ` Björn Lundin
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox