summaryrefslogtreecommitdiff
path: root/src/simple_time.adb
blob: cf1995c8e85be857aed9f9e0e731b686c43d2b0c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
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;