From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=0.7 required=5.0 tests=BAYES_00,INVALID_DATE, MSGID_SHORT,REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!uunet!seas.gwu.edu!mfeldman From: mfeldman@seas.gwu.edu (Michael Feldman) Newsgroups: comp.lang.ada Subject: Re: Calendar_Utilities package (long posting) Message-ID: <2013@sparko.gwu.edu> Date: 6 Jul 90 21:37:40 GMT References: Reply-To: mfeldman@seas.gwu.edu () Distribution: comp.lang.ada Organization: The George Washington University, Washington D.C. List-Id: 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;