summaryrefslogtreecommitdiff
path: root/src/simple_time.adb
diff options
context:
space:
mode:
authorJed Barber <jjbarber@y7mail.com>2017-07-03 19:09:38 +1000
committerJed Barber <jjbarber@y7mail.com>2017-07-03 19:09:38 +1000
commitbb80ba1f9c02be0f99690ca392644ae4404aecc7 (patch)
tree0f53ac6781abd28df9a428f1ced62f18252f92c0 /src/simple_time.adb
parent8b6cc411cceb51b26579f8fcf94424b4842ef0bf (diff)
String output of Time/Durations now neater
Diffstat (limited to 'src/simple_time.adb')
-rw-r--r--src/simple_time.adb22
1 files changed, 18 insertions, 4 deletions
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;