00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00047 #ifndef WINSTL_INCL_WINSTL_TIME_H_CONVERSION_FUNCTIONS
00048 #define WINSTL_INCL_WINSTL_TIME_H_CONVERSION_FUNCTIONS
00049
00050 #ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
00051 # define WINSTL_VER_WINSTL_TIME_H_CONVERSION_FUNCTIONS_MAJOR 4
00052 # define WINSTL_VER_WINSTL_TIME_H_CONVERSION_FUNCTIONS_MINOR 0
00053 # define WINSTL_VER_WINSTL_TIME_H_CONVERSION_FUNCTIONS_REVISION 5
00054 # define WINSTL_VER_WINSTL_TIME_H_CONVERSION_FUNCTIONS_EDIT 49
00055 #endif
00056
00057
00058
00059
00060
00061 #ifndef WINSTL_INCL_WINSTL_H_WINSTL
00062 # include <winstl/winstl.h>
00063 #endif
00064 #ifndef STLSOFT_INCL_STLSOFT_UTIL_H_LIMIT_TRAITS
00065 # include <stlsoft/util/limit_traits.h>
00066 #endif
00067
00068 #ifndef STLSOFT_INCL_H_TIME
00069 # define STLSOFT_INCL_H_TIME
00070 # include <time.h>
00071 #endif
00072
00073
00074
00075
00076
00077 #if !defined(_WINSTL_NO_NAMESPACE) && \
00078 !defined(STLSOFT_DOCUMENTATION_SKIP_SECTION)
00079 # if defined(_STLSOFT_NO_NAMESPACE)
00080
00081 namespace winstl
00082 {
00083 # else
00084
00085
00086 namespace stlsoft
00087 {
00088
00089 namespace winstl_project
00090 {
00091
00092 # endif
00093 #endif
00094
00095
00096
00097
00098
00105 STLSOFT_INLINE void winstl__UNIXTimeToFILETIME(time_t t, FILETIME *ft)
00106 {
00107 const ws_uint64_t i = UInt32x32To64(t, 10000000) + STLSOFT_GEN_UINT64_SUFFIX(116444736000000000);
00108
00109 WINSTL_ASSERT(NULL != ft);
00110
00111 ft->dwLowDateTime = (DWORD)i;
00112 ft->dwHighDateTime = (DWORD)(i >> 32);
00113 }
00114
00115 STLSOFT_INLINE void winstl__UNIXTimeToFILETIME_us(time_t t, ws_sint32_t usec, FILETIME *ft)
00116 {
00117 ws_uint64_t i = UInt32x32To64(t, 10000000) + Int32x32To64(usec, 10) + STLSOFT_GEN_UINT64_SUFFIX(116444736000000000);
00118
00119 WINSTL_ASSERT(NULL != ft);
00120
00121 ft->dwLowDateTime = (DWORD)i;
00122 ft->dwHighDateTime = (DWORD)(i >> 32);
00123 }
00124
00125 STLSOFT_INLINE time_t winstl__FILETIMEToUNIXTime(FILETIME const* ft, ws_sint32_t *microseconds)
00126 {
00127 ws_sint64_t i;
00128
00129 i = ft->dwHighDateTime;
00130 i <<= 32;
00131 i |= ft->dwLowDateTime;
00132
00133 i -= STLSOFT_GEN_UINT64_SUFFIX(116444736000000000);
00134 if(NULL != microseconds)
00135 {
00136 *microseconds = stlsoft_static_cast(ws_sint32_t, (i % 10000000) / 10);
00137
00138 WINSTL_ASSERT(*microseconds >= 0 && *microseconds <= 999999);
00139 }
00140 i /= 10000000;
00141
00142 return stlsoft_static_cast(time_t, i);
00143 }
00144
00145
00146
00147
00148
00149 #ifdef STLSOFT_DOCUMENTATION_SKIP_SECTION
00150 namespace winstl
00151 {
00152 #endif
00153
00154
00155
00156
00157
00158 #ifdef __cplusplus
00159
00160 # ifdef STLSOFT_CF_64BIT_INT_SUPPORT
00161
00168 inline void UNIXTimeToFILETIME(time_t t, FILETIME &ft)
00169 {
00170 winstl__UNIXTimeToFILETIME(t, &ft);
00171 }
00172
00179 inline FILETIME UNIXTimeToFILETIME(time_t t)
00180 {
00181 FILETIME ft;
00182
00183 winstl__UNIXTimeToFILETIME(t, &ft);
00184
00185 return ft;
00186 }
00187
00194 inline void UNIXTimeToFILETIME(time_t t, ws_sint32_t usec, FILETIME &ft)
00195 {
00196 winstl__UNIXTimeToFILETIME_us(t, usec, &ft);
00197 }
00198
00205 inline FILETIME UNIXTimeToFILETIME(time_t t, ws_sint32_t usec)
00206 {
00207 FILETIME ft;
00208
00209 winstl__UNIXTimeToFILETIME_us(t, usec, &ft);
00210
00211 return ft;
00212 }
00213
00218 inline time_t FILETIMEToUNIXTime(FILETIME const& ft, ws_sint32_t *microseconds = NULL)
00219 {
00220 return winstl__FILETIMEToUNIXTime(&ft, microseconds);
00221 }
00222
00227 inline void FILETIMEToUNIXTime(FILETIME const& ft, time_t &t)
00228 {
00229 t = winstl__FILETIMEToUNIXTime(&ft, NULL);
00230 }
00231
00236 inline void FILETIMEToUNIXTime(FILETIME const& ft, time_t &t, ws_sint32_t µseconds)
00237 {
00238 t = winstl__FILETIMEToUNIXTime(&ft, µseconds);
00239 }
00240
00241 # endif
00242
00243 #endif
00244
00245
00246
00247
00248
00249 #ifdef STLSOFT_UNITTEST
00250 # include "./unittest/conversion_functions_unittest_.h"
00251 #endif
00252
00253
00254
00255 #ifndef _WINSTL_NO_NAMESPACE
00256 # if defined(_STLSOFT_NO_NAMESPACE) || \
00257 defined(STLSOFT_DOCUMENTATION_SKIP_SECTION)
00258 }
00259 # else
00260 }
00261 }
00262 # endif
00263 #endif
00264
00265
00266
00267 #endif
00268
00269