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-2009 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 35with Interfaces.C; 36 37package Ada.Calendar.Conversions is 38 39 function To_Ada_Time (Unix_Time : Interfaces.C.long) return Time; 40 -- Convert a time value represented as number of seconds since the Unix 41 -- Epoch to a time value relative to an Ada implementation-defined Epoch. 42 -- The units of the result are 100 nanoseconds on VMS and nanoseconds on 43 -- all other targets. Raises Time_Error if the result cannot fit into a 44 -- Time value. 45 46 function To_Ada_Time 47 (tm_year : Interfaces.C.int; 48 tm_mon : Interfaces.C.int; 49 tm_day : Interfaces.C.int; 50 tm_hour : Interfaces.C.int; 51 tm_min : Interfaces.C.int; 52 tm_sec : Interfaces.C.int; 53 tm_isdst : Interfaces.C.int) return Time; 54 -- Convert a time value expressed in Unix-like fields of struct tm into 55 -- a Time value relative to the Ada Epoch. The ranges of the formals are 56 -- as follows: 57 58 -- tm_year -- years since 1900 59 -- tm_mon -- months since January [0 .. 11] 60 -- tm_day -- day of the month [1 .. 31] 61 -- tm_hour -- hours since midnight [0 .. 24] 62 -- tm_min -- minutes after the hour [0 .. 59] 63 -- tm_sec -- seconds after the minute [0 .. 60] 64 -- tm_isdst -- Daylight Savings Time flag [-1 .. 1] 65 66 -- The returned value is in UTC and may or may not contain leap seconds 67 -- depending on whether binder flag "-y" was used. Raises Time_Error if 68 -- the input values are out of the defined ranges or if tm_sec equals 60 69 -- and the instance in time is not a leap second occurrence. 70 71 function To_Duration 72 (tv_sec : Interfaces.C.long; 73 tv_nsec : Interfaces.C.long) return Duration; 74 -- Convert an elapsed time value expressed in Unix-like fields of struct 75 -- timespec into a Duration value. The expected ranges are: 76 77 -- tv_sec - seconds 78 -- tv_nsec - nanoseconds 79 80 procedure To_Struct_Timespec 81 (D : Duration; 82 tv_sec : out Interfaces.C.long; 83 tv_nsec : out Interfaces.C.long); 84 -- Convert a Duration value into the constituents of struct timespec. 85 -- Formal tv_sec denotes seconds and tv_nsecs denotes nanoseconds. 86 87 procedure To_Struct_Tm 88 (T : Time; 89 tm_year : out Interfaces.C.int; 90 tm_mon : out Interfaces.C.int; 91 tm_day : out Interfaces.C.int; 92 tm_hour : out Interfaces.C.int; 93 tm_min : out Interfaces.C.int; 94 tm_sec : out Interfaces.C.int); 95 -- Convert a Time value set in the Ada Epoch into the constituents of 96 -- struct tm. The ranges of the out formals are as follows: 97 98 -- tm_year -- years since 1900 99 -- tm_mon -- months since January [0 .. 11] 100 -- tm_day -- day of the month [1 .. 31] 101 -- tm_hour -- hours since midnight [0 .. 24] 102 -- tm_min -- minutes after the hour [0 .. 59] 103 -- tm_sec -- seconds after the minute [0 .. 60] 104 -- tm_isdst -- Daylight Savings Time flag [-1 .. 1] 105 106 -- The input date is considered to be in UTC 107 108 function To_Unix_Time (Ada_Time : Time) return Interfaces.C.long; 109 -- Convert a time value represented as number of time units since the Ada 110 -- implementation-defined Epoch to a value relative to the Unix Epoch. The 111 -- units of the result are seconds. Raises Time_Error if the result cannot 112 -- fit into a Time value. 113 114end Ada.Calendar.Conversions; 115