]> git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/ada/libgnat/a-calcon.adb
[Ada] Bump copyright year
[thirdparty/gcc.git] / gcc / ada / libgnat / a-calcon.adb
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT RUN-TIME COMPONENTS --
4 -- --
5 -- A D A . C A L E N D A R . C O N V E R S I O N S --
6 -- --
7 -- B o d y --
8 -- --
9 -- Copyright (C) 2008-2020, Free Software Foundation, Inc. --
10 -- --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. --
17 -- --
18 -- As a special exception under Section 7 of GPL version 3, you are granted --
19 -- additional permissions described in the GCC Runtime Library Exception, --
20 -- version 3.1, as published by the Free Software Foundation. --
21 -- --
22 -- You should have received a copy of the GNU General Public License and --
23 -- a copy of the GCC Runtime Library Exception along with this program; --
24 -- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
25 -- <http://www.gnu.org/licenses/>. --
26 -- --
27 -- GNAT was originally developed by the GNAT team at New York University. --
28 -- Extensive contributions were provided by Ada Core Technologies Inc. --
29 -- --
30 ------------------------------------------------------------------------------
31
32 with Interfaces.C; use Interfaces.C;
33 with Interfaces.C.Extensions; use Interfaces.C.Extensions;
34
35 package body Ada.Calendar.Conversions is
36
37 -----------------
38 -- To_Ada_Time --
39 -----------------
40
41 function To_Ada_Time (Unix_Time : long) return Time is
42 Val : constant Long_Integer := Long_Integer (Unix_Time);
43 begin
44 return Conversion_Operations.To_Ada_Time (Val);
45 end To_Ada_Time;
46
47 -----------------
48 -- To_Ada_Time --
49 -----------------
50
51 function To_Ada_Time
52 (tm_year : int;
53 tm_mon : int;
54 tm_day : int;
55 tm_hour : int;
56 tm_min : int;
57 tm_sec : int;
58 tm_isdst : int) return Time
59 is
60 Year : constant Integer := Integer (tm_year);
61 Month : constant Integer := Integer (tm_mon);
62 Day : constant Integer := Integer (tm_day);
63 Hour : constant Integer := Integer (tm_hour);
64 Minute : constant Integer := Integer (tm_min);
65 Second : constant Integer := Integer (tm_sec);
66 DST : constant Integer := Integer (tm_isdst);
67 begin
68 return
69 Conversion_Operations.To_Ada_Time
70 (Year, Month, Day, Hour, Minute, Second, DST);
71 end To_Ada_Time;
72
73 -----------------
74 -- To_Duration --
75 -----------------
76
77 function To_Duration
78 (tv_sec : long;
79 tv_nsec : long) return Duration
80 is
81 Secs : constant Long_Integer := Long_Integer (tv_sec);
82 Nano_Secs : constant Long_Integer := Long_Integer (tv_nsec);
83 begin
84 return Conversion_Operations.To_Duration (Secs, Nano_Secs);
85 end To_Duration;
86
87 ------------------------
88 -- To_Struct_Timespec --
89 ------------------------
90
91 procedure To_Struct_Timespec
92 (D : Duration;
93 tv_sec : out long;
94 tv_nsec : out long)
95 is
96 Secs : Long_Integer;
97 Nano_Secs : Long_Integer;
98
99 begin
100 Conversion_Operations.To_Struct_Timespec (D, Secs, Nano_Secs);
101
102 tv_sec := long (Secs);
103 tv_nsec := long (Nano_Secs);
104 end To_Struct_Timespec;
105
106 ------------------
107 -- To_Struct_Tm --
108 ------------------
109
110 procedure To_Struct_Tm
111 (T : Time;
112 tm_year : out int;
113 tm_mon : out int;
114 tm_day : out int;
115 tm_hour : out int;
116 tm_min : out int;
117 tm_sec : out int)
118 is
119 Year : Integer;
120 Month : Integer;
121 Day : Integer;
122 Hour : Integer;
123 Minute : Integer;
124 Second : Integer;
125
126 begin
127 Conversion_Operations.To_Struct_Tm
128 (T, Year, Month, Day, Hour, Minute, Second);
129
130 tm_year := int (Year);
131 tm_mon := int (Month);
132 tm_day := int (Day);
133 tm_hour := int (Hour);
134 tm_min := int (Minute);
135 tm_sec := int (Second);
136 end To_Struct_Tm;
137
138 ------------------
139 -- To_Unix_Time --
140 ------------------
141
142 function To_Unix_Time (Ada_Time : Time) return long is
143 Val : constant Long_Integer :=
144 Conversion_Operations.To_Unix_Time (Ada_Time);
145 begin
146 return long (Val);
147 end To_Unix_Time;
148
149 -----------------------
150 -- To_Unix_Nano_Time --
151 -----------------------
152
153 function To_Unix_Nano_Time (Ada_Time : Time) return long_long is
154 pragma Unsuppress (Overflow_Check);
155 Ada_Rep : constant Time_Rep := Time_Rep (Ada_Time);
156
157 begin
158 return long_long (Ada_Rep + Epoch_Offset);
159
160 exception
161 when Constraint_Error =>
162 raise Time_Error;
163 end To_Unix_Nano_Time;
164
165 end Ada.Calendar.Conversions;