From bb80ba1f9c02be0f99690ca392644ae4404aecc7 Mon Sep 17 00:00:00 2001 From: Jed Barber Date: Mon, 3 Jul 2017 19:09:38 +1000 Subject: String output of Time/Durations now neater --- src/simple_time.adb | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) (limited to 'src/simple_time.adb') diff --git a/src/simple_time.adb b/src/simple_time.adb index 6c31a89..f206f13 100644 --- a/src/simple_time.adb +++ b/src/simple_time.adb @@ -15,7 +15,7 @@ use package body Simple_Time is - function To_String + function Image (Moment : in Time) return String is @@ -27,17 +27,31 @@ package body Simple_Time is Year_Str : String (1 .. 4); Month_Str, Day_Str, Hour_Str, Minute_Str : String (1 .. 2); - Second_Str : String (1 .. 12); + Second_Str : String (1 .. 9); begin Move (Trim (Year_Number'Image (Year (Moment)), Left), Year_Str, Left, Right, '0'); Move (Trim (Month_Number'Image (Month (Moment)), Left), Month_Str, Left, Right, '0'); Move (Trim (Day_Number'Image (Day (Moment)), Left), Day_Str, Left, Right, '0'); Move (Trim (Integer'Image (Hours), Left), Hour_Str, Left, Right, '0'); Move (Trim (Integer'Image (Minutes), Left), Minute_Str, Left, Right, '0'); - Move (Trim (Duration'Image (Seconds), Left), Second_Str, Left, Right, '0'); + Move (Image (Seconds), Second_Str, Left, Right, '0'); return Year_Str & '-' & Month_Str & '-' & Day_Str & " " & Hour_Str & ':' & Minute_Str & ':' & Second_Str; - end To_String; + end Image; + + + + + function Image + (Moment : in Duration) + return String + is + Duration_Trim : String := Trim (Duration'Image (Moment), Left); + begin + -- Drop unnecessary trailing zeros, of which there are always three. + -- Is this a Linux-specific thing? Probably. + return Duration_Trim (1 .. (Duration_Trim'Length - 3)); + end Image; end Simple_Time; -- cgit