2008-05-30 Vladimir Makarov <vmakarov@redhat.com>
[official-gcc.git] / gcc / ada / a-calcon.adb
blobe946c5ea79350037d701a0c17f7b1ff8f7f12980
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, 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 2, 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. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING. If not, write --
19 -- to the Free Software Foundation, 51 Franklin Street, Fifth Floor, --
20 -- Boston, MA 02110-1301, USA. --
21 -- --
22 -- As a special exception, if other files instantiate generics from this --
23 -- unit, or you link this unit with other files to produce an executable, --
24 -- this unit does not by itself cause the resulting executable to be --
25 -- covered by the GNU General Public License. This exception does not --
26 -- however invalidate any other reasons why the executable file might be --
27 -- covered by the GNU Public License. --
28 -- --
29 -- GNAT was originally developed by the GNAT team at New York University. --
30 -- Extensive contributions were provided by Ada Core Technologies Inc. --
31 -- --
32 ------------------------------------------------------------------------------
34 with Interfaces.C; use Interfaces.C;
36 package body Ada.Calendar.Conversions is
38 -----------------
39 -- To_Ada_Time --
40 -----------------
42 function To_Ada_Time (Unix_Time : long) return Time is
43 Val : constant Long_Integer := Long_Integer (Unix_Time);
44 begin
45 return Conversion_Operations.To_Ada_Time (Val);
46 end To_Ada_Time;
48 -----------------
49 -- To_Ada_Time --
50 -----------------
52 function To_Ada_Time
53 (tm_year : int;
54 tm_mon : int;
55 tm_day : int;
56 tm_hour : int;
57 tm_min : int;
58 tm_sec : int;
59 tm_isdst : int) return Time
61 Year : constant Integer := Integer (tm_year);
62 Month : constant Integer := Integer (tm_mon);
63 Day : constant Integer := Integer (tm_day);
64 Hour : constant Integer := Integer (tm_hour);
65 Minute : constant Integer := Integer (tm_min);
66 Second : constant Integer := Integer (tm_sec);
67 DST : constant Integer := Integer (tm_isdst);
68 begin
69 return
70 Conversion_Operations.To_Ada_Time
71 (Year, Month, Day, Hour, Minute, Second, DST);
72 end To_Ada_Time;
74 -----------------
75 -- To_Duration --
76 -----------------
78 function To_Duration
79 (tv_sec : long;
80 tv_nsec : long) return Duration
82 Secs : constant Long_Integer := Long_Integer (tv_sec);
83 Nano_Secs : constant Long_Integer := Long_Integer (tv_nsec);
84 begin
85 return Conversion_Operations.To_Duration (Secs, Nano_Secs);
86 end To_Duration;
88 ------------------------
89 -- To_Struct_Timespec --
90 ------------------------
92 procedure To_Struct_Timespec
93 (D : Duration;
94 tv_sec : out long;
95 tv_nsec : out long)
97 Secs : Long_Integer;
98 Nano_Secs : Long_Integer;
100 begin
101 Conversion_Operations.To_Struct_Timespec (D, Secs, Nano_Secs);
103 tv_sec := long (Secs);
104 tv_nsec := long (Nano_Secs);
105 end To_Struct_Timespec;
107 ------------------
108 -- To_Struct_Tm --
109 ------------------
111 procedure To_Struct_Tm
112 (T : Time;
113 tm_year : out int;
114 tm_mon : out int;
115 tm_day : out int;
116 tm_hour : out int;
117 tm_min : out int;
118 tm_sec : out int)
120 Year : Integer;
121 Month : Integer;
122 Day : Integer;
123 Hour : Integer;
124 Minute : Integer;
125 Second : Integer;
127 begin
128 Conversion_Operations.To_Struct_Tm
129 (T, Year, Month, Day, Hour, Minute, Second);
131 tm_year := int (Year);
132 tm_mon := int (Month);
133 tm_day := int (Day);
134 tm_hour := int (Hour);
135 tm_min := int (Minute);
136 tm_sec := int (Second);
137 end To_Struct_Tm;
139 ------------------
140 -- To_Unix_Time --
141 ------------------
143 function To_Unix_Time (Ada_Time : Time) return long is
144 Val : constant Long_Integer :=
145 Conversion_Operations.To_Unix_Time (Ada_Time);
146 begin
147 return long (Val);
148 end To_Unix_Time;
150 end Ada.Calendar.Conversions;