Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

246 lines
4.9 KiB

  1. #include "Procs.hxx"
  2. #define BAIL_ON_FAILURE(hr) \
  3. if (FAILED(hr)) { \
  4. goto error; \
  5. }\
  6. #define BAIL_ON_SUCCESS(hr) \
  7. if (SUCCEEDED(hr)) { \
  8. goto error; \
  9. }\
  10. HRESULT
  11. NTTimeFormattoDateFormat(
  12. LARGE_INTEGER *NTTimeFormat,
  13. DATE *DateFormat
  14. )
  15. {
  16. *DateFormat = (DATE)0;
  17. RRETURN(S_OK);
  18. }
  19. HRESULT
  20. ConvertDWORDtoDATE(
  21. DWORD dwDate,
  22. DATE * pdaDate,
  23. BOOL fIsGMT
  24. )
  25. {
  26. FILETIME fileTime;
  27. SYSTEMTIME SystemTime, LocalTime;
  28. LARGE_INTEGER tmpTime;
  29. HRESULT hr = S_OK;
  30. if (pdaDate) {
  31. memset(pdaDate, 0, sizeof(DATE));
  32. }
  33. memset(&fileTime, 0, sizeof(FILETIME));
  34. ::RtlSecondsSince1970ToTime(dwDate, &tmpTime );
  35. fileTime.dwLowDateTime = tmpTime.LowPart;
  36. fileTime.dwHighDateTime = tmpTime.HighPart;
  37. if(!fIsGMT)
  38. // OLE DB on NDS does not convert to local file time. We don't
  39. // convert here to be consistent.
  40. FileTimeToLocalFileTime(&fileTime, &fileTime);
  41. if (!FileTimeToSystemTime(&fileTime, &SystemTime)) {
  42. hr = HRESULT_FROM_WIN32(GetLastError());
  43. BAIL_ON_FAILURE(hr);
  44. }
  45. if (!SystemTimeToVariantTime(&SystemTime, pdaDate)) {
  46. hr = HRESULT_FROM_WIN32(GetLastError());
  47. BAIL_ON_FAILURE(hr);
  48. }
  49. error:
  50. RRETURN(hr);
  51. }
  52. HRESULT
  53. ConvertDATEtoDWORD(
  54. DATE daDate,
  55. DWORD *pdwDate,
  56. BOOL fIsGMT
  57. )
  58. {
  59. FILETIME fileTime;
  60. LARGE_INTEGER tmpTime;
  61. HRESULT hr = S_OK;
  62. SYSTEMTIME systemTime;
  63. if (!VariantTimeToSystemTime(daDate, &systemTime)) {
  64. hr = HRESULT_FROM_WIN32(GetLastError());
  65. BAIL_ON_FAILURE(hr);
  66. }
  67. if (!SystemTimeToFileTime(&systemTime, &fileTime)) {
  68. hr = HRESULT_FROM_WIN32(GetLastError());
  69. BAIL_ON_FAILURE(hr);
  70. }
  71. if(!fIsGMT)
  72. // OLE DB on NDS does not convert to local file time. We don't
  73. // convert here to be consistent.
  74. LocalFileTimeToFileTime(&fileTime, &fileTime);
  75. tmpTime.LowPart = fileTime.dwLowDateTime;
  76. tmpTime.HighPart = fileTime.dwHighDateTime;
  77. ::RtlTimeToSecondsSince1970(&tmpTime, (ULONG *)pdwDate);
  78. error:
  79. RRETURN(hr);
  80. }
  81. HRESULT
  82. ConvertDATEToDWORD(
  83. DATE daDate,
  84. DWORD *pdwDate
  85. )
  86. {
  87. RRETURN(S_OK);
  88. }
  89. HRESULT
  90. ConvertSystemTimeToDATE(
  91. SYSTEMTIME Time,
  92. DATE * pdaTime
  93. )
  94. {
  95. FILETIME ft;
  96. BOOL fRetval = FALSE;
  97. USHORT wDosDate;
  98. USHORT wDosTime;
  99. SYSTEMTIME LocalTime;
  100. //
  101. // Get Time-zone specific local time.
  102. //
  103. fRetval = SystemTimeToTzSpecificLocalTime(
  104. NULL,
  105. &Time,
  106. &LocalTime
  107. );
  108. if(!fRetval){
  109. RRETURN(HRESULT_FROM_WIN32(GetLastError()));
  110. }
  111. //
  112. // System Time To File Time.
  113. //
  114. fRetval = SystemTimeToFileTime(&LocalTime,
  115. &ft);
  116. if(!fRetval){
  117. RRETURN(HRESULT_FROM_WIN32(GetLastError()));
  118. }
  119. //
  120. // File Time to DosDateTime.
  121. //
  122. fRetval = FileTimeToDosDateTime(&ft,
  123. &wDosDate,
  124. &wDosTime);
  125. if(!fRetval){
  126. RRETURN(HRESULT_FROM_WIN32(GetLastError()));
  127. }
  128. //
  129. // DosDateTime to VariantTime.
  130. //
  131. fRetval = DosDateTimeToVariantTime(wDosDate,
  132. wDosTime,
  133. pdaTime );
  134. if(!fRetval){
  135. RRETURN(HRESULT_FROM_WIN32(GetLastError()));
  136. }
  137. RRETURN(S_OK);
  138. }
  139. HRESULT
  140. ConvertDWORDToDATE(
  141. DWORD dwTime,
  142. DATE * pdaTime
  143. )
  144. {
  145. RRETURN(S_OK);
  146. }
  147. HRESULT
  148. ConvertDATEToSYSTEMTIME(
  149. DATE daDate,
  150. SYSTEMTIME *pSysTime
  151. )
  152. {
  153. HRESULT hr;
  154. FILETIME ft;
  155. FILETIME lft; //local file time
  156. BOOL fRetval = FALSE;
  157. SYSTEMTIME LocalTime;
  158. USHORT wDosDate;
  159. USHORT wDosTime;
  160. fRetval = VariantTimeToDosDateTime(daDate,
  161. &wDosDate,
  162. &wDosTime );
  163. if(!fRetval){
  164. hr = HRESULT_FROM_WIN32(GetLastError());
  165. RRETURN(hr);
  166. }
  167. fRetval = DosDateTimeToFileTime(wDosDate,
  168. wDosTime,
  169. &lft);
  170. if(!fRetval){
  171. hr = HRESULT_FROM_WIN32(GetLastError());
  172. RRETURN(hr);
  173. }
  174. //
  175. // convert local file time to filetime
  176. //
  177. fRetval = LocalFileTimeToFileTime(&lft,
  178. &ft );
  179. if(!fRetval){
  180. hr = HRESULT_FROM_WIN32(GetLastError());
  181. RRETURN(hr);
  182. }
  183. fRetval = FileTimeToSystemTime(&ft,
  184. pSysTime );
  185. if(!fRetval){
  186. hr = HRESULT_FROM_WIN32(GetLastError());
  187. RRETURN(hr);
  188. }
  189. RRETURN(S_OK);
  190. }