1 ------------------------------------------------------------------------------
3 -- GNAT RUN-TIME COMPONENTS --
5 -- A D A . C A L E N D A R . C O N V E R S I O N S --
9 -- Copyright (C) 2008-2020, Free Software Foundation, Inc. --
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. --
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. --
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/>. --
27 -- GNAT was originally developed by the GNAT team at New York University. --
28 -- Extensive contributions were provided by Ada Core Technologies Inc. --
30 ------------------------------------------------------------------------------
32 with Interfaces.C; use Interfaces.C;
33 with Interfaces.C.Extensions; use Interfaces.C.Extensions;
35 package body Ada.Calendar.Conversions is
41 function To_Ada_Time (Unix_Time : long) return Time is
42 Val : constant Long_Integer := Long_Integer (Unix_Time);
44 return Conversion_Operations.To_Ada_Time (Val);
58 tm_isdst : int) return Time
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);
69 Conversion_Operations.To_Ada_Time
70 (Year, Month, Day, Hour, Minute, Second, DST);
79 tv_nsec : long) return Duration
81 Secs : constant Long_Integer := Long_Integer (tv_sec);
82 Nano_Secs : constant Long_Integer := Long_Integer (tv_nsec);
84 return Conversion_Operations.To_Duration (Secs, Nano_Secs);
87 ------------------------
88 -- To_Struct_Timespec --
89 ------------------------
91 procedure To_Struct_Timespec
97 Nano_Secs : Long_Integer;
100 Conversion_Operations.To_Struct_Timespec (D, Secs, Nano_Secs);
102 tv_sec := long (Secs);
103 tv_nsec := long (Nano_Secs);
104 end To_Struct_Timespec;
110 procedure To_Struct_Tm
127 Conversion_Operations.To_Struct_Tm
128 (T, Year, Month, Day, Hour, Minute, Second);
130 tm_year := int (Year);
131 tm_mon := int (Month);
133 tm_hour := int (Hour);
134 tm_min := int (Minute);
135 tm_sec := int (Second);
142 function To_Unix_Time (Ada_Time : Time) return long is
143 Val : constant Long_Integer :=
144 Conversion_Operations.To_Unix_Time (Ada_Time);
149 -----------------------
150 -- To_Unix_Nano_Time --
151 -----------------------
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);
158 return long_long (Ada_Rep + Epoch_Offset);
161 when Constraint_Error =>
163 end To_Unix_Nano_Time;
165 end Ada.Calendar.Conversions;