1 #ifndef DATE_TIME_C_TIME_HPP___
2 #define DATE_TIME_C_TIME_HPP___
4 /* Copyright (c) 2002,2003,2005 CrystalClear Software, Inc.
5 * Use, modification and distribution is subject to the
6 * Boost Software License, Version 1.0. (See accompanying
7 * file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
8 * Author: Jeff Garland, Bart Garst
14 Provide workarounds related to the ctime header
18 #include <string> // to be able to convert from string literals to exceptions
20 #include <boost/throw_exception.hpp>
21 #include <boost/date_time/compiler_config.hpp>
23 //Work around libraries that don't put time_t and time in namespace std
24 #ifdef BOOST_NO_STDC_NAMESPACE
25 namespace std { using ::time_t; using ::time; using ::localtime;
26 using ::tm; using ::gmtime; }
27 #endif // BOOST_NO_STDC_NAMESPACE
29 //The following is used to support high precision time clocks
30 #ifdef BOOST_HAS_GETTIMEOFDAY
34 #ifdef BOOST_HAS_FTIME
40 //! Provides a uniform interface to some 'ctime' functions
41 /*! Provides a uniform interface to some ctime functions and
42 * their '_r' counterparts. The '_r' functions require a pointer to a
43 * user created std::tm struct whereas the regular functions use a
44 * staticly created struct and return a pointer to that. These wrapper
45 * functions require the user to create a std::tm struct and send in a
46 * pointer to it. This struct may be used to store the resulting time.
47 * The returned pointer may or may not point to this struct, however,
48 * it will point to the result of the corresponding function.
49 * All functions do proper checking of the C function results and throw
50 * exceptions on error. Therefore the functions will never return NULL.
54 #if defined(BOOST_DATE_TIME_HAS_REENTRANT_STD_FUNCTIONS)
55 //! requires a pointer to a user created std::tm struct
57 static std::tm* localtime(const std::time_t* t, std::tm* result)
59 // localtime_r() not in namespace std???
60 #if defined(__VMS) && __INITIAL_POINTER_SIZE == 64
62 if(!localtime_r(t,&tmp))
67 result = localtime_r(t, result);
70 boost::throw_exception(std::runtime_error("could not convert calendar time to local time"));
73 //! requires a pointer to a user created std::tm struct
75 static std::tm* gmtime(const std::time_t* t, std::tm* result)
77 // gmtime_r() not in namespace std???
78 #if defined(__VMS) && __INITIAL_POINTER_SIZE == 64
85 result = gmtime_r(t, result);
88 boost::throw_exception(std::runtime_error("could not convert calendar time to UTC time"));
91 #else // BOOST_DATE_TIME_HAS_REENTRANT_STD_FUNCTIONS
93 #if (defined(_MSC_VER) && (_MSC_VER >= 1400))
94 #pragma warning(push) // preserve warning settings
95 #pragma warning(disable : 4996) // disable depricated localtime/gmtime warning on vc8
96 #endif // _MSC_VER >= 1400
97 //! requires a pointer to a user created std::tm struct
99 static std::tm* localtime(const std::time_t* t, std::tm* result)
101 result = std::localtime(t);
103 boost::throw_exception(std::runtime_error("could not convert calendar time to local time"));
106 //! requires a pointer to a user created std::tm struct
108 static std::tm* gmtime(const std::time_t* t, std::tm* result)
110 result = std::gmtime(t);
112 boost::throw_exception(std::runtime_error("could not convert calendar time to UTC time"));
115 #if (defined(_MSC_VER) && (_MSC_VER >= 1400))
116 #pragma warning(pop) // restore warnings to previous state
117 #endif // _MSC_VER >= 1400
119 #endif // BOOST_DATE_TIME_HAS_REENTRANT_STD_FUNCTIONS
123 #endif // DATE_TIME_C_TIME_HPP___