File indexing completed on 2025-01-18 09:30:36
0001 #ifndef DATE_TIME_C_TIME_HPP___
0002 #define DATE_TIME_C_TIME_HPP___
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017 #include <ctime>
0018 #include <string> // to be able to convert from string literals to exceptions
0019 #include <stdexcept>
0020 #include <boost/throw_exception.hpp>
0021 #include <boost/date_time/compiler_config.hpp>
0022
0023
0024 #ifdef BOOST_NO_STDC_NAMESPACE
0025 namespace std { using ::time_t; using ::time; using ::localtime;
0026 using ::tm; using ::gmtime; }
0027 #endif
0028
0029
0030 #ifdef BOOST_HAS_GETTIMEOFDAY
0031 #include <sys/time.h>
0032 #endif
0033
0034 #ifdef BOOST_HAS_FTIME
0035 #include <time.h>
0036 #endif
0037
0038 namespace boost {
0039 namespace date_time {
0040
0041
0042
0043
0044
0045
0046
0047
0048
0049
0050
0051
0052 struct c_time {
0053 public:
0054 #if defined(BOOST_DATE_TIME_HAS_REENTRANT_STD_FUNCTIONS)
0055
0056 inline
0057 static std::tm* localtime(const std::time_t* t, std::tm* result)
0058 {
0059
0060 #if defined(__VMS) && __INITIAL_POINTER_SIZE == 64
0061 std::tm tmp;
0062 if(!localtime_r(t,&tmp))
0063 result = 0;
0064 else
0065 *result = tmp;
0066 #else
0067 result = localtime_r(t, result);
0068 #endif
0069 if (!result)
0070 boost::throw_exception(std::runtime_error("could not convert calendar time to local time"));
0071 return result;
0072 }
0073
0074 inline
0075 static std::tm* gmtime(const std::time_t* t, std::tm* result)
0076 {
0077
0078 #if defined(__VMS) && __INITIAL_POINTER_SIZE == 64
0079 std::tm tmp;
0080 if(!gmtime_r(t,&tmp))
0081 result = 0;
0082 else
0083 *result = tmp;
0084 #else
0085 result = gmtime_r(t, result);
0086 #endif
0087 if (!result)
0088 boost::throw_exception(std::runtime_error("could not convert calendar time to UTC time"));
0089 return result;
0090 }
0091 #else
0092
0093 #if defined(__clang__)
0094 #pragma clang diagnostic push
0095 #pragma clang diagnostic ignored "-Wdeprecated-declarations"
0096 #elif (defined(_MSC_VER) && (_MSC_VER >= 1400))
0097 #pragma warning(push)
0098 #pragma warning(disable : 4996)
0099 #endif
0100
0101 inline
0102 static std::tm* localtime(const std::time_t* t, std::tm* result)
0103 {
0104 result = std::localtime(t);
0105 if (!result)
0106 boost::throw_exception(std::runtime_error("could not convert calendar time to local time"));
0107 return result;
0108 }
0109
0110 inline
0111 static std::tm* gmtime(const std::time_t* t, std::tm* result)
0112 {
0113 result = std::gmtime(t);
0114 if (!result)
0115 boost::throw_exception(std::runtime_error("could not convert calendar time to UTC time"));
0116 return result;
0117 }
0118 #if defined(__clang__)
0119 #pragma clang diagnostic pop
0120 #elif (defined(_MSC_VER) && (_MSC_VER >= 1400))
0121 #pragma warning(pop)
0122 #endif
0123
0124 #endif
0125 };
0126 }}
0127
0128 #endif