comp.lang.ada
 help / color / mirror / Atom feed
* Limits on type Duration and package Calendar
@ 1990-07-02 17:11 Marshall Brinn
  1990-07-06  2:13 ` Bob Kitzberger @sation
  0 siblings, 1 reply; 4+ messages in thread
From: Marshall Brinn @ 1990-07-02 17:11 UTC (permalink / raw)




I have come across a problem with package CALENDAR, and would be interested
in hearing what others have to say/have done about it.


In the LRM, it defines that type DURATION need only ranuge up to 84600.0,
ie., the number of seconds in a day (the definition of CALENDAR.DAY_DURATION).


However, package CALENDAR provides functions "+" and "-" where the difference
between two times is given as a DURATION. How then does this package handle
the difference between two days that are more that one day apart? Some 
compilers I've tried seem to have a reasonably high value for DURATION'last,
at least one (TELESOFT TELEGEN2 1.4) used the one-day upper bound.

Yes, I can "roll my own", but it seems a shame that I can't use the "standard"
calendar interface because it is not sufficient to such a simple task.


Any suggestions on the "Standard" ADA way to deal with time gaps > 1 day
would be appreciated.



Marshall Brinn (mbrinn@bbn.com)
70 Fawcett St.
Cambridge, MA 02138
617-873-2717

^ permalink raw reply	[flat|nested] 4+ messages in thread
* Limits on type Duration and package Calendar
@ 1990-07-08 18:46 "", Mats Weber
  0 siblings, 0 replies; 4+ messages in thread
From: "", Mats Weber @ 1990-07-08 18:46 UTC (permalink / raw)


RFC-822-Headers:
Received: from elcgl.epfl.ch by SIC.Epfl.CH with VMSmail ; Sun, 8 Jul 90 19:46:19 N
X-ST-Vmsmail-To: gw::"info-ada@ajpo.sei.cmu.edu"

==================

Marshall Brinn (mbrinn@bbn.com) writes:

>[stuff deleted...]
>Any suggestions on the "Standard" ADA way to deal with time gaps > 1 day
>would be appreciated.

There are good reasons for not requiring the type Duration to cover more 
that one day (fixed point type implementable using one machine-word on most 
CPUs).

However, I think that Calendar should have defined another Duration type 
that enables handling longer time intervals, as is done in the package spec 
below.

The complete portable implementation source code may be obtained on request 
by sending e-mail to:

Mats Weber
Swiss Federal Institute of Technology
EPFL DI LGL
1015 Lausanne
Switzerland

E-mail : madmats@elcgl.epfl.ch
phone  : +41 21 693 52 92
fax    : +41 21 693 39 09


-------------------------------------------------------------------------
-- ADDITIONAL CALENDAR FUNCTIONS
   -----------------------------

-- Creation : 19-JAN-1987 by Mats Weber.


with Calendar;

use Calendar;

package Extended_Calendar is
-------------------------

   type Long_Duration is private;

   type Day_Interval is 
      range -366 * Year_Number'Last..366 * Year_Number'Last;

   subtype Natural_Day_Interval is Day_Interval range 0..Day_Interval'Last;

   type Duration_Sign is ('+', '-');


   function To_Long_Duration (Days    : Natural_Day_Interval;
                              Seconds : Day_Duration;
                              Sign    : Duration_Sign := '+') 
      return Long_Duration;

   function To_Long_Duration (Seconds : Day_Duration;
                              Sign    : Duration_Sign := '+') 
      return Long_Duration;

   function To_Long_Duration (Days    : Natural_Day_Interval;
                              Sign    : Duration_Sign := '+') 
      return Long_Duration;

   function Days    (Delta_Time : Long_Duration) 
      return Natural_Day_Interval;
   function Seconds (Delta_Time : Long_Duration) return Day_Duration;
   function Sign    (Delta_Time : Long_Duration) return Duration_Sign;

   function To_Duration (Delta_Time : Long_Duration) return Duration;

   function Zero return Long_Duration;


   function "+" (A : Long_Duration) return Long_Duration;
   function "-" (A : Long_Duration) return Long_Duration;

   function "abs" (A : Long_Duration) return Long_Duration;

   function "+" (A, B : Long_Duration) return Long_Duration;
   function "-" (A, B : Long_Duration) return Long_Duration;

   function "*" (N : Integer; A : Long_Duration) return Long_Duration;
   function "*" (A : Long_Duration; N : Integer) return Long_Duration;
   function "/" (A : Long_Duration; N : Integer) return Long_Duration;

   function "<"  (A, B : Long_Duration) return Boolean;
   function "<=" (A, B : Long_Duration) return Boolean;
   function ">"  (A, B : Long_Duration) return Boolean;
   function ">=" (A, B : Long_Duration) return Boolean;

   function "+" (T : Time; A : Long_Duration) return Time;
   function "+" (A : Long_Duration; T : Time) return Time;
   function "-" (T : Time; A : Long_Duration) return Time;
   function "-" (T1, T2 : Time) return Long_Duration;
      -- Will raise TIME_ERROR if no valid time value can be returned.


   type Week_Day is (Monday, Tuesday, Wednesday, Thursday, 
                     Friday, Saturday, Sunday);

   function Succ (Day : Week_Day) return Week_Day;
   function Pred (Day : Week_Day) return Week_Day;

   function Day_Of_Week (Date : Time := Clock) return Week_Day;

   function Day_Of_Week (Year  : Year_Number;
                         Month : Month_Number;
                         Day   : Day_Number) return Week_Day;

private

   type Long_Duration is
      record
         Days    : Natural_Day_Interval;
         Seconds : Day_Duration;
         Sign    : Duration_Sign;
      end record;

end Extended_Calendar;

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~1990-07-08 18:46 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1990-07-02 17:11 Limits on type Duration and package Calendar Marshall Brinn
1990-07-06  2:13 ` Bob Kitzberger @sation
1990-07-06 14:30   ` Robert I. Eachus
  -- strict thread matches above, loose matches on Subject: below --
1990-07-08 18:46 "", Mats Weber

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