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=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,8da181ade72859cf X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news1.google.com!newshub.sdsu.edu!elnk-nf2-pas!newsfeed.earthlink.net!stamper.news.pas.earthlink.net!newsread1.news.pas.earthlink.net.POSTED!a6202946!not-for-mail From: Jeffrey Carter Organization: jrcarter commercial-at acm [period | full stop] org User-Agent: Mozilla/5.0 (Windows; U; Win98; en-US; rv:1.4) Gecko/20030624 MSIE X-Accept-Language: en-us, en MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: timeouts References: In-Reply-To: Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Message-ID: Date: Sun, 22 Aug 2004 19:56:34 GMT NNTP-Posting-Host: 63.184.8.69 X-Complaints-To: abuse@earthlink.net X-Trace: newsread1.news.pas.earthlink.net 1093204594 63.184.8.69 (Sun, 22 Aug 2004 12:56:34 PDT) NNTP-Posting-Date: Sun, 22 Aug 2004 12:56:34 PDT Xref: g2news1.google.com comp.lang.ada:2925 Date: 2004-08-22T19:56:34+00:00 List-Id: Brian May wrote: > Nothing that I can see: > > function Strip(Value : in String) return String is > I : Natural := Value'First; > Continue : Boolean := True; > begin > while I <= Value'Last and Continue loop > if Value(I) = ' ' then > I := I + 1; > else > Continue := False; > end if; > end loop; > return Value(I..Value'Last); > end Strip; Ada.Strings.Fixed.Trim? > function To_String(The_Time : in Time) return String is > Duration : Integer; > H : Integer range 0..23; > M : Integer range 0..60; > S : Integer range 0..60; > begin > Duration := Integer(Seconds(The_Time)); > > S := Duration mod 60; > Duration := (Duration-S)/60; > > M := Duration mod 60; > Duration := (Duration-M)/60; > > H := Duration mod 24; > > return Strip(Integer'Image(H))&":" > &Strip(Integer'Image(M))&":" > &Strip(Integer'Image(S)); This can give things like "7:16:3", which I consider ugly. PragmARC.Images.Image lets you say Image (H, Width => 2, Zero_Filled => True); which can produce prettier time images. PragmARC.Date_Handler uses this internal procedure to split the seconds value from Ada.Calendar into hour, minute, and seconds: procedure Split (Seconds : in out Calendar.Day_Duration; Hour : out Hour_Number; Minute : out Minute_Number) is Seconds_Per_Minute : constant := 60; Minutes_Per_Hour : constant := 60; Seconds_Per_Hour : constant := Minutes_Per_Hour * Seconds_Per_Minute; begin -- Split if Seconds >= Calendar.Day_Duration'Last then Seconds := 0.0; Hour := 0; Minute := 0; return; end if; Hour := Integer'Max (Integer (Seconds / Seconds_Per_Hour - 0.5), Hour_Number'First); Seconds := Seconds - Calendar.Day_Duration (Hour) * Seconds_Per_Hour; Minute := Integer'Max (Integer (Seconds / Seconds_Per_Minute - 0.5), Minute_Number'First); Seconds := Seconds - Calendar.Day_Duration (Minute) * Seconds_Per_Minute; end Split; where subtype Hour_Number is Integer range 0 .. 23; subtype Minute_Number is Integer range 0 .. 59; FWIW. > end To_String; -- Jeff Carter "Now go away or I shall taunt you a second time." Monty Python & the Holy Grail 07