File: opt70_pkg.adb

package info (click to toggle)
gcc-arm-none-eabi 15%3A12.2.rel1-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 959,712 kB
  • sloc: cpp: 3,275,382; ansic: 2,061,766; ada: 840,956; f90: 208,513; makefile: 76,132; asm: 73,433; xml: 50,448; exp: 34,146; sh: 32,436; objc: 15,637; fortran: 14,012; python: 11,991; pascal: 6,787; awk: 4,779; perl: 3,054; yacc: 338; ml: 285; lex: 201; haskell: 122
file content (55 lines) | stat: -rw-r--r-- 1,687 bytes parent folder | download | duplicates (2)
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
with Ada.Calendar;          use Ada.Calendar;
with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;
with GNAT.Calendar;         use GNAT.Calendar;

package body Opt70_Pkg is

   type Enum is (None, Zero, Space);

   type Sec_Number is mod 2 ** 64;

   function Image (N : Sec_Number; Pad : Enum; Length : Natural) return String;

   function Image (N : Natural; Pad : Enum; Length: Natural) return String is
   begin
      return Image (Sec_Number (N), Pad, Length);
   end;

   function Image (N : Sec_Number; Pad : Enum; Length : Natural) return String is

      function Pad_Char return String is
      begin
         case Pad is
            when None  => return "";
            when Zero  => return "00";
            when Space => return "  ";
         end case;
      end;

      NI  : constant String := Sec_Number'Image (N);
      NIP : constant String := Pad_Char & NI (2 .. NI'Last);

   begin
      return NIP (NIP'Last - Length + 1 .. NIP'Last);
   end;

   function Image (Date : Ada.Calendar.Time; S : String) return String is
      Result     : Unbounded_String := Null_Unbounded_String;
      Year       : Year_Number;
      Month      : Month_Number;
      Day        : Day_Number;
      Hour       : Hour_Number;
      Minute     : Minute_Number;
      Second     : Second_Number;
      Sub_Second : Second_Duration;
   begin
      Split (Date, Year, Month, Day, Hour, Minute, Second, Sub_Second);
      case S (S'First + 1) is
         when 'S' => Result := Result & Image (Second, Zero, 2);
         when 'y' => Result := Result & Image (Sec_Number (1), Zero, 2);
         when others => null;
      end case;
      return To_String (Result);
   end;

end Opt70_Pkg;