2014-11-18 Christophe Lyon <christophe.lyon@linaro.org>
[official-gcc.git] / gcc / ada / a-calcon.adb
blobf24b971b226369c8295275c9657ea86431f4505d
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-2012, 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 ------------------------------------------------------------------------------
32 with Interfaces.C; use Interfaces.C;
34 package body Ada.Calendar.Conversions is
36 -----------------
37 -- To_Ada_Time --
38 -----------------
40 function To_Ada_Time (Unix_Time : long) return Time is
41 Val : constant Long_Integer := Long_Integer (Unix_Time);
42 begin
43 return Conversion_Operations.To_Ada_Time (Val);
44 end To_Ada_Time;
46 -----------------
47 -- To_Ada_Time --
48 -----------------
50 function To_Ada_Time
51 (tm_year : int;
52 tm_mon : int;
53 tm_day : int;
54 tm_hour : int;
55 tm_min : int;
56 tm_sec : int;
57 tm_isdst : int) return Time
59 Year : constant Integer := Integer (tm_year);
60 Month : constant Integer := Integer (tm_mon);
61 Day : constant Integer := Integer (tm_day);
62 Hour : constant Integer := Integer (tm_hour);
63 Minute : constant Integer := Integer (tm_min);
64 Second : constant Integer := Integer (tm_sec);
65 DST : constant Integer := Integer (tm_isdst);
66 begin
67 return
68 Conversion_Operations.To_Ada_Time
69 (Year, Month, Day, Hour, Minute, Second, DST);
70 end To_Ada_Time;
72 -----------------
73 -- To_Duration --
74 -----------------
76 function To_Duration
77 (tv_sec : long;
78 tv_nsec : long) return Duration
80 Secs : constant Long_Integer := Long_Integer (tv_sec);
81 Nano_Secs : constant Long_Integer := Long_Integer (tv_nsec);
82 begin
83 return Conversion_Operations.To_Duration (Secs, Nano_Secs);
84 end To_Duration;
86 ------------------------
87 -- To_Struct_Timespec --
88 ------------------------
90 procedure To_Struct_Timespec
91 (D : Duration;
92 tv_sec : out long;
93 tv_nsec : out long)
95 Secs : Long_Integer;
96 Nano_Secs : Long_Integer;
98 begin
99 Conversion_Operations.To_Struct_Timespec (D, Secs, Nano_Secs);
101 tv_sec := long (Secs);
102 tv_nsec := long (Nano_Secs);
103 end To_Struct_Timespec;
105 ------------------
106 -- To_Struct_Tm --
107 ------------------
109 procedure To_Struct_Tm
110 (T : Time;
111 tm_year : out int;
112 tm_mon : out int;
113 tm_day : out int;
114 tm_hour : out int;
115 tm_min : out int;
116 tm_sec : out int)
118 Year : Integer;
119 Month : Integer;
120 Day : Integer;
121 Hour : Integer;
122 Minute : Integer;
123 Second : Integer;
125 begin
126 Conversion_Operations.To_Struct_Tm
127 (T, Year, Month, Day, Hour, Minute, Second);
129 tm_year := int (Year);
130 tm_mon := int (Month);
131 tm_day := int (Day);
132 tm_hour := int (Hour);
133 tm_min := int (Minute);
134 tm_sec := int (Second);
135 end To_Struct_Tm;
137 ------------------
138 -- To_Unix_Time --
139 ------------------
141 function To_Unix_Time (Ada_Time : Time) return long is
142 Val : constant Long_Integer :=
143 Conversion_Operations.To_Unix_Time (Ada_Time);
144 begin
145 return long (Val);
146 end To_Unix_Time;
148 end Ada.Calendar.Conversions;