with Ada.Calendar; use Ada.Calendar; with Ada.Strings; use Ada.Strings; with Ada.Strings.Fixed; use Ada.Strings.Fixed; -- This source is licensed under Creative Commons CC0 v1.0. -- -- To read the full text, see license.txt in the main directory of this repository -- or go to https://creativecommons.org/publicdomain/zero/1.0/legalcode.txt -- -- For a human readable summary, go to https://creativecommons.org/publicdomain/zero/1.0/ 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; Year_Str : String (1 .. 4); Month_Str, Day_Str, Hour_Str, Minute_Str : String (1 .. 2); Second_Str : String (1 .. 12); 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'); return Year_Str & '-' & Month_Str & '-' & Day_Str & " " & Hour_Str & ':' & Minute_Str & ':' & Second_Str; end To_String; end Simple_Time;