From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on ip-172-31-74-118.ec2.internal X-Spam-Level: X-Spam-Status: No, score=-2.9 required=3.0 tests=BAYES_00,NICE_REPLY_A autolearn=ham autolearn_force=no version=3.4.6 Path: eternal-september.org!reader02.eternal-september.org!news.swapon.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Niklas Holsti Newsgroups: comp.lang.ada 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 Organization: Tidorum Ltd Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Trace: individual.net nHfJpfMszHNOHCEheXWcXwwXOPjjkiebpJhZ/vZICYS7GydqmW Cancel-Lock: sha1:6XQD4xXmivJEW4PkLNQFJXQOA6w= User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:78.0) Gecko/20100101 Thunderbird/78.13.0 In-Reply-To: Content-Language: en-US Xref: reader02.eternal-september.org comp.lang.ada:62639 List-Id: 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.