From: mfeldman@seas.gwu.edu (Michael Feldman)
Subject: Re: Calendar_Utilities package (long posting)
Date: 6 Jul 90 21:37:40 GMT [thread overview]
Message-ID: <2013@sparko.gwu.edu> (raw)
In-Reply-To: EMERY.90Jul6094911@aries.linus.mitre.org
Dave Emery's calendar utilities package is really nice. A quick scan of it
reveals a small flaw that has bitten me and my students more than once: in
extracting the integer part of Calendar.Seconds(Calendar.Time) the package
is converting to predefined integer. This is not portable, because if it's
late in the day and integer'size = 16 (as is the case on PC's, usually),
the conversion will raise constraint_error. "Mainframe" Ada's generally use
32-bit integer, which is clearly bigger than 86400.0, but Meridian and
Janus both use 16-bit integer. Bad news here. My hack is to convert to
float first. I'm not sure what accuracy problems this might present if
you're working in fractions of a second, but you all get the idea.
Anybody got a cleaner hack than mine? Have a look at this code:
(obviously My_Int_IO is the usual instantiation for predefined integer).
I've tested on both Unix and PC Ada's.
(Please don't flame about the simple-minded repetitive calculations;
I broke it out so the novice could easily understand it).
WITH Text_IO;
WITH My_Int_IO;
WITH Calendar;
PROCEDURE TimeOfDay IS
CurrentTime : Calendar.Time;
SecsPastMidnight : Calendar.Day_Duration;
MinsPastMidnight : Natural;
Secs : Natural;
Mins : Natural;
Hrs : Natural;
BEGIN -- show time as hh:mm:ss, 24-hr time
CurrentTime := Calendar.Clock;
SecsPastMidnight := Calendar.Seconds(CurrentTime);
MinsPastMidnight := Natural(Float(SecsPastMidnight)/60.0 - 0.5);
Secs := Natural(Float(SecsPastMidnight) - 60.0 * Float(MinsPastMidnight));
Mins := MinsPastMidnight REM 60;
Hrs := MinsPastMidnight / 60;
My_Int_IO.Put (Item => Hrs, Width => 1);
Text_IO.Put (Item => ':');
IF Mins < 10 THEN
Text_IO.Put (Item => '0');
END IF;
My_Int_IO.Put (Item => Mins, Width => 1);
Text_IO.Put (Item => ':');
IF Secs < 10 THEN
Text_IO.Put (Item => '0');
END IF;
My_Int_IO.Put (Item => Secs, Width => 1);
Text_IO.New_Line;
END TimeOfDay;
prev parent reply other threads:[~1990-07-06 21:37 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
1990-07-06 13:49 Calendar_Utilities package (long posting) David Emery
1990-07-06 21:37 ` Michael Feldman [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