From c2f324ac23ea143dfea308229f0ac0376ed4f745 Mon Sep 17 00:00:00 2001 From: Jed Barber Date: Mon, 6 Feb 2017 02:32:14 +1100 Subject: Most of the Main procedure done, a Simple Time package added --- src/simple_time.adb | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 src/simple_time.adb (limited to 'src/simple_time.adb') diff --git a/src/simple_time.adb b/src/simple_time.adb new file mode 100644 index 0000000..cf1995c --- /dev/null +++ b/src/simple_time.adb @@ -0,0 +1,32 @@ + + +with Ada.Calendar; use Ada.Calendar; +with Ada.Strings; use Ada.Strings; +with Ada.Strings.Fixed; use Ada.Strings.Fixed; + + +package body Simple_Time is + + + function To_String + (Moment : in Time) + return String + is + Raw_Secs : Day_Duration := Seconds (Moment); + + Hours : Integer := Integer (Raw_Secs) / 3600; + Minutes : Integer := (Integer (Raw_Secs) - Hours * 3600) / 60; + Seconds : Duration := Raw_Secs - Duration (Hours) * 3600 - Duration (Minutes) * 60; + begin + return Trim (Year_Number'Image (Year (Moment)), Both) & "-" & + Trim (Month_Number'Image (Month (Moment)), Both) & "-" & + Trim (Day_Number'Image (Day (Moment)), Both) & " " & + Trim (Integer'Image (Hours), Both) & ":" & + Trim (Integer'Image (Minutes), Both) & ":" & + Trim (Duration'Image (Seconds), Both); + end To_String; + + +end Simple_Time; + + -- cgit