comp.lang.ada
 help / color / mirror / Atom feed
From: "Björn Lundin" <b.f.lundin@gmail.com>
Subject: Re: Trivial question: how to avoid confusing sec, min, hour and day in a program?
Date: Sun, 24 Oct 2021 14:09:30 +0200	[thread overview]
Message-ID: <sl3idr$ghe$1@dont-email.me> (raw)
In-Reply-To: <5dcbccb3-1e2b-42cb-91e1-4be31442a647n@googlegroups.com>

Den 2021-10-24 kl. 08:52, skrev reinert:
> Ada seems to guarantee that Duration covers 24 hours (?). What you do when you need to represent for example 5 years?

we use a types of our own at work

   subtype Year_Type is Integer_2 range 1901 .. 2099;
   subtype Month_Type is Integer_2 range 01 .. 12;
   subtype Day_Type is Integer_2 range 01 .. 31;
   subtype Hour_Type is Integer_2 range 00 .. 23;
   subtype Minute_Type is Integer_2 range 00 .. 59;
   subtype Second_Type is Integer_2 range 00 .. 59;
   subtype Millisecond_Type is Integer_2 range 000 .. 999;

   subtype Week_Type is Integer_2 range 1 .. 53;
   subtype Year_Day_Type is Integer_2 range 1 .. 366;
   type Week_Day_Type is (
                          Monday,
                          Tuesday,
                          Wednesday,
                          Thursday,
                          Friday,
                          Saturday,
                          Sunday);

   subtype Interval_Day_Type is Integer_4 range 0 .. Integer_4'Last;
   subtype Seconds_Type is Integer_4 range 0 .. Integer_4'Last;




  type Time_Type is tagged record
     Year        : Year_Type;
     Month       : Month_Type;
     Day         : Day_Type;
     Hour        : Hour_Type;
     Minute      : Minute_Type;
     Second      : Second_Type;
     Millisecond : Millisecond_Type;
   end record;

and


  type Interval_Type is tagged record
     Days         : Interval_Day_Type;
     Hours        : Hour_Type;
     Minutes      : Minute_Type;
     Seconds      : Second_Type;
     Milliseconds : Millisecond_Type;
   end record;


with functions and conversion to handle

"+" "-" and some more ( Time - Time results in duration)


we have a limited need of dates from the past and into the future, and 
ms is usually enough granularity.
(This was designed in the late 80:ies but still usefull)

This is to cover the needs of our administrative system


>> The user interface is responsible to convert anything to Duration and back.
>>
>> -- 
>> Regards,
>> Dmitry A. Kazakov
>> http://www.dmitry-kazakov.de

and Dmitry is right in saying the user interface should convert to the 
units the user likes


-- 
Björn

      parent reply	other threads:[~2021-10-24 12:09 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
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 [this message]
replies disabled

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