| 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 |
-- S p e c -- |
| 8 |
-- -- |
| 9 |
-- Copyright (C) 2008-2025, 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 |
-- This package provides various routines for conversion between Ada and Unix |
| 33 |
-- time models - Time, Duration, struct tm and struct timespec. |
| 34 |
|
| 35 |
with Interfaces.C; |
| 36 |
|
| 37 |
package Ada.Calendar.Conversions is |
| 38 |
|
| 39 |
function To_Ada_Time (Unix_Time : Interfaces.C.long) return Time; |
| 40 |
pragma Obsolescent |
| 41 |
(To_Ada_Time, "This function may be removed in a future version"); |
| 42 |
-- Old version which will overflow at the 2038 Epochalypse |
| 43 |
|
| 44 |
function To_Ada_Time_64 (Unix_Time : Interfaces.C.long_long) return Time; |
| 45 |
-- Convert a time value represented as number of seconds since the |
| 46 |
-- Unix Epoch to a time value relative to an Ada implementation-defined |
| 47 |
-- Epoch. The units of the result are nanoseconds on all targets. Raises |
| 48 |
-- Time_Error if the result cannot fit into a Time value. |
| 49 |
|
| 50 |
function To_Ada_Time |
| 51 |
(tm_year : Interfaces.C.int; |
| 52 |
tm_mon : Interfaces.C.int; |
| 53 |
tm_day : Interfaces.C.int; |
| 54 |
tm_hour : Interfaces.C.int; |
| 55 |
tm_min : Interfaces.C.int; |
| 56 |
tm_sec : Interfaces.C.int; |
| 57 |
tm_isdst : Interfaces.C.int) return Time; |
| 58 |
-- Convert a time value expressed in Unix-like fields of struct tm into |
| 59 |
-- a Time value relative to the Ada Epoch. The ranges of the formals are |
| 60 |
-- as follows: |
| 61 |
|
| 62 |
-- tm_year -- years since 1900 |
| 63 |
-- tm_mon -- months since January [0 .. 11] |
| 64 |
-- tm_day -- day of the month [1 .. 31] |
| 65 |
-- tm_hour -- hours since midnight [0 .. 24] |
| 66 |
-- tm_min -- minutes after the hour [0 .. 59] |
| 67 |
-- tm_sec -- seconds after the minute [0 .. 60] |
| 68 |
-- tm_isdst -- Daylight Savings Time flag [-1 .. 1] |
| 69 |
|
| 70 |
-- The returned value is in UTC and may or may not contain leap seconds |
| 71 |
-- depending on whether binder flag "-y" was used. Raises Time_Error if |
| 72 |
-- the input values are out of the defined ranges or if tm_sec equals 60 |
| 73 |
-- and the instance in time is not a leap second occurrence. |
| 74 |
|
| 75 |
function To_Duration |
| 76 |
(tv_sec : Interfaces.C.long; |
| 77 |
tv_nsec : Interfaces.C.long) return Duration; |
| 78 |
pragma |
| 79 |
Obsolescent |
| 80 |
(To_Duration, "This function may be removed in a future version"); |
| 81 |
-- Old version which will overflow at the 2038 Epochalypse |
| 82 |
|
| 83 |
function To_Duration_64 |
| 84 |
(tv_sec : Interfaces.C.long_long; |
| 85 |
tv_nsec : Interfaces.C.long) return Duration; |
| 86 |
-- Convert an elapsed time value expressed in Unix-like fields of struct |
| 87 |
-- timespec into a Duration value. The expected ranges are: |
| 88 |
|
| 89 |
-- tv_sec - seconds |
| 90 |
-- tv_nsec - nanoseconds |
| 91 |
|
| 92 |
procedure To_Struct_Timespec |
| 93 |
(D : Duration; |
| 94 |
tv_sec : out Interfaces.C.long; |
| 95 |
tv_nsec : out Interfaces.C.long); |
| 96 |
pragma |
| 97 |
Obsolescent |
| 98 |
(To_Struct_Timespec, |
| 99 |
"This function may be removed in a future version"); |
| 100 |
-- Old version which will overflow at the 2038 Epochalypse |
| 101 |
|
| 102 |
procedure To_Struct_Timespec_64 |
| 103 |
(D : Duration; |
| 104 |
tv_sec : out Interfaces.C.long_long; |
| 105 |
tv_nsec : out Interfaces.C.long); |
| 106 |
-- Convert a Duration value into the constituents of struct timespec. |
| 107 |
-- Formal tv_sec denotes seconds and tv_nsecs denotes nanoseconds. |
| 108 |
|
| 109 |
procedure To_Struct_Tm |
| 110 |
(T : Time; |
| 111 |
tm_year : out Interfaces.C.int; |
| 112 |
tm_mon : out Interfaces.C.int; |
| 113 |
tm_day : out Interfaces.C.int; |
| 114 |
tm_hour : out Interfaces.C.int; |
| 115 |
tm_min : out Interfaces.C.int; |
| 116 |
tm_sec : out Interfaces.C.int); |
| 117 |
-- Convert a Time value set in the Ada Epoch into the constituents of |
| 118 |
-- struct tm. The ranges of the out formals are as follows: |
| 119 |
|
| 120 |
-- tm_year -- years since 1900 |
| 121 |
-- tm_mon -- months since January [0 .. 11] |
| 122 |
-- tm_day -- day of the month [1 .. 31] |
| 123 |
-- tm_hour -- hours since midnight [0 .. 24] |
| 124 |
-- tm_min -- minutes after the hour [0 .. 59] |
| 125 |
-- tm_sec -- seconds after the minute [0 .. 60] |
| 126 |
-- tm_isdst -- Daylight Savings Time flag [-1 .. 1] |
| 127 |
|
| 128 |
-- The input date is considered to be in UTC |
| 129 |
|
| 130 |
function To_Unix_Time (Ada_Time : Time) return Interfaces.C.long; |
| 131 |
pragma |
| 132 |
Obsolescent |
| 133 |
(To_Unix_Time, "This function may be removed in a future version"); |
| 134 |
-- Old version which will overflow at the 2038 Epochalypse |
| 135 |
|
| 136 |
function To_Unix_Time_64 (Ada_Time : Time) return Interfaces.C.long_long; |
| 137 |
-- Convert a time value represented as number of time units since the Ada |
| 138 |
-- implementation-defined Epoch to a value relative to the Unix Epoch. The |
| 139 |
-- units of the result are seconds. Raises Time_Error if the result cannot |
| 140 |
-- fit into a Time value. |
| 141 |
|
| 142 |
function To_Unix_Nano_Time |
| 143 |
(Ada_Time : Time) return Interfaces.C.long_long; |
| 144 |
-- Convert a time value represented as number of time units since the Ada |
| 145 |
-- implementation-defined Epoch to a value relative to the Unix Epoch. The |
| 146 |
-- units of the result are nanoseconds. Raises Time_Error if the result |
| 147 |
-- cannot fit into a Time value. |
| 148 |
|
| 149 |
end Ada.Calendar.Conversions; |