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.

495 lines
9.5 KiB

  1. //***************************************************************************
  2. //
  3. // Copyright (c) 2000-2001 Microsoft Corporation
  4. //
  5. // datetime.h
  6. //
  7. // alanbos 20-Jan-00 Created.
  8. //
  9. // Datetime helper implementation.
  10. //
  11. //***************************************************************************
  12. #ifndef _DATETIME_H_
  13. #define _DATETIME_H_
  14. #define WBEMDT_DMTF_LEN 25
  15. #define WBEMDT_DMTF_SPOS 14
  16. #define WBEMDT_DMTF_UPOS 21
  17. #define WBEMDT_MIN_YEAR 0
  18. #define WBEMDT_MAX_YEAR 9999
  19. #define WBEMDT_MIN_MONTH 1
  20. #define WBEMDT_MAX_MONTH 12
  21. #define WBEMDT_MIN_DAY 1
  22. #define WBEMDT_MAX_DAY 31
  23. #define WBEMDT_MIN_DAYINT 0
  24. #define WBEMDT_MAX_DAYINT 999999
  25. #define WBEMDT_MIN_HOURS 0
  26. #define WBEMDT_MAX_HOURS 23
  27. #define WBEMDT_MIN_MINUTES 0
  28. #define WBEMDT_MAX_MINUTES 59
  29. #define WBEMDT_MIN_SECONDS 0
  30. #define WBEMDT_MAX_SECONDS 59
  31. #define WBEMDT_MIN_MICROSEC 0
  32. #define WBEMDT_MAX_MICROSEC 999999
  33. #define WBEMDT_MIN_UTC -720
  34. #define WBEMDT_MAX_UTC 720
  35. #define INVALID_TIME 0xffffffffffffffff
  36. //***************************************************************************
  37. //
  38. // CLASS NAME:
  39. //
  40. // CWbemDateTime
  41. //
  42. // DESCRIPTION:
  43. //
  44. // Implements the ISWbemDateTime interface.
  45. //
  46. //***************************************************************************
  47. class CWbemDateTime
  48. {
  49. private:
  50. // Private helper class for all the messy business
  51. class WBEMTime
  52. {
  53. private:
  54. class WBEMTimeSpan
  55. {
  56. private:
  57. ULONGLONG m_Time;
  58. friend class WBEMTime;
  59. public:
  60. WBEMTimeSpan (
  61. int iMinutes
  62. )
  63. {
  64. m_Time = iMinutes * 60;
  65. m_Time *= 10000000;
  66. }
  67. };
  68. public:
  69. WBEMTime () { m_uTime = INVALID_TIME ; }
  70. WBEMTime ( const SYSTEMTIME &st ) { *this = st ; }
  71. WBEMTime ( const FILETIME &ft ) ;
  72. const WBEMTime &operator= ( const SYSTEMTIME &st ) ;
  73. const WBEMTime &operator= ( const FILETIME &ft ) ;
  74. WBEMTime operator+ ( const WBEMTimeSpan &ts ) const;
  75. WBEMTime operator- ( const WBEMTimeSpan &sub ) const;
  76. BOOL GetSYSTEMTIME ( SYSTEMTIME *pst ) const;
  77. BOOL GetFILETIME ( FILETIME *pst ) const;
  78. BOOL GetDMTF ( SYSTEMTIME &st, long &offset ) const;
  79. BOOL GetDMTF ( SYSTEMTIME &st ) const;
  80. void Clear ( void ) { m_uTime = INVALID_TIME ; }
  81. bool IsOk () const { return m_uTime != INVALID_TIME ? true : false; }
  82. static LONG WINAPI GetLocalOffsetForDate(const SYSTEMTIME *pst);
  83. private:
  84. ULONGLONG m_uTime;
  85. };
  86. VARIANT_BOOL m_bYearSpecified;
  87. VARIANT_BOOL m_bMonthSpecified;
  88. VARIANT_BOOL m_bDaySpecified;
  89. VARIANT_BOOL m_bHoursSpecified;
  90. VARIANT_BOOL m_bMinutesSpecified;
  91. VARIANT_BOOL m_bSecondsSpecified;
  92. VARIANT_BOOL m_bMicrosecondsSpecified;
  93. VARIANT_BOOL m_bUTCSpecified;
  94. VARIANT_BOOL m_bIsInterval;
  95. long m_iYear;
  96. long m_iMonth;
  97. long m_iDay;
  98. long m_iHours;
  99. long m_iMinutes;
  100. long m_iSeconds;
  101. long m_iMicroseconds;
  102. long m_iUTC;
  103. bool CheckField (
  104. LPWSTR pValue,
  105. ULONG len,
  106. VARIANT_BOOL &bIsSpecified,
  107. long &iValue,
  108. long maxValue,
  109. long minValue
  110. );
  111. bool CheckUTC (
  112. LPWSTR pValue,
  113. VARIANT_BOOL &bIsSpecified,
  114. long &iValue,
  115. bool bParseSign = true
  116. );
  117. protected:
  118. public:
  119. CWbemDateTime(void);
  120. virtual ~CWbemDateTime(void);
  121. // ISWbemDateTime methods
  122. HRESULT GetValue ( BSTR *value ) ;
  123. HRESULT PutValue ( BSTR value ) ;
  124. HRESULT GetYear ( long *value )
  125. {
  126. *value = m_iYear;
  127. return S_OK;
  128. }
  129. HRESULT PutYear ( long value )
  130. {
  131. HRESULT hr = WBEM_S_NO_ERROR;
  132. if ((value > WBEMDT_MAX_YEAR) || (value < WBEMDT_MIN_YEAR))
  133. hr = WBEM_E_VALUE_OUT_OF_RANGE;
  134. else
  135. m_iYear = value;
  136. return hr;
  137. }
  138. HRESULT GetMonth ( long *value )
  139. {
  140. *value = m_iMonth;
  141. return S_OK;
  142. }
  143. HRESULT PutMonth ( long value )
  144. {
  145. HRESULT hr = WBEM_S_NO_ERROR;
  146. if ((value > WBEMDT_MAX_MONTH) || (value < WBEMDT_MIN_MONTH))
  147. hr = WBEM_E_VALUE_OUT_OF_RANGE;
  148. else
  149. m_iMonth = value;
  150. return hr;
  151. }
  152. HRESULT GetDay ( long *value )
  153. {
  154. *value = m_iDay;
  155. return S_OK;
  156. }
  157. HRESULT PutDay ( long value )
  158. {
  159. HRESULT hr = S_OK ;
  160. if (((VARIANT_TRUE == m_bIsInterval) && ((value > WBEMDT_MAX_DAYINT) || (value < WBEMDT_MIN_DAYINT))) ||
  161. ((VARIANT_FALSE == m_bIsInterval) &&((value > WBEMDT_MAX_DAY) || (value < WBEMDT_MIN_DAY))))
  162. hr = WBEM_E_VALUE_OUT_OF_RANGE;
  163. else
  164. m_iDay = value;
  165. return hr;
  166. }
  167. HRESULT GetHours ( long *value )
  168. {
  169. *value = m_iHours;
  170. return S_OK;
  171. }
  172. HRESULT PutHours ( long value )
  173. {
  174. HRESULT hr = S_OK;
  175. if ((value > WBEMDT_MAX_HOURS) || (value < WBEMDT_MIN_HOURS))
  176. hr = WBEM_E_VALUE_OUT_OF_RANGE;
  177. else
  178. m_iHours = value;
  179. return hr;
  180. }
  181. HRESULT GetMinutes ( long *value )
  182. {
  183. *value = m_iMinutes;
  184. return S_OK;
  185. }
  186. HRESULT PutMinutes ( long value )
  187. {
  188. HRESULT hr = S_OK;
  189. if ((value > WBEMDT_MAX_MINUTES) || (value < WBEMDT_MIN_MINUTES))
  190. hr = WBEM_E_VALUE_OUT_OF_RANGE;
  191. else
  192. m_iMinutes = value;
  193. return hr;
  194. }
  195. HRESULT GetSeconds ( long *value )
  196. {
  197. *value = m_iSeconds;
  198. return S_OK;
  199. }
  200. HRESULT PutSeconds ( long value )
  201. {
  202. HRESULT hr = S_OK;
  203. if ((value > WBEMDT_MAX_SECONDS) || (value < WBEMDT_MIN_SECONDS))
  204. hr = WBEM_E_VALUE_OUT_OF_RANGE;
  205. else
  206. m_iSeconds = value;
  207. return hr;
  208. }
  209. HRESULT GetMicroseconds ( long *value )
  210. {
  211. *value = m_iMicroseconds;
  212. return S_OK;
  213. }
  214. HRESULT PutMicroseconds ( long value )
  215. {
  216. HRESULT hr = S_OK;
  217. if ((value > WBEMDT_MAX_MICROSEC) || (value < WBEMDT_MIN_MICROSEC))
  218. hr = WBEM_E_VALUE_OUT_OF_RANGE;
  219. else
  220. m_iMicroseconds = value;
  221. return hr;
  222. }
  223. HRESULT GetUTC ( long *value )
  224. {
  225. *value = m_iUTC;
  226. return S_OK;
  227. }
  228. HRESULT PutUTC( long value )
  229. {
  230. HRESULT hr = S_OK;
  231. if ((value > WBEMDT_MAX_UTC) || (value < WBEMDT_MIN_UTC))
  232. hr = WBEM_E_VALUE_OUT_OF_RANGE;
  233. else
  234. m_iUTC = value;
  235. return hr;
  236. }
  237. HRESULT GetYearSpecified ( VARIANT_BOOL *value )
  238. {
  239. *value = m_bYearSpecified;
  240. return S_OK;
  241. }
  242. HRESULT PutYearSpecified ( VARIANT_BOOL value )
  243. {
  244. HRESULT hr = S_OK;
  245. if ((VARIANT_TRUE == m_bIsInterval) && (VARIANT_TRUE == value))
  246. hr = WBEM_E_FAILED ;
  247. else
  248. m_bYearSpecified = value;
  249. return hr;
  250. }
  251. HRESULT GetMonthSpecified ( VARIANT_BOOL *value )
  252. {
  253. *value = m_bMonthSpecified;
  254. return S_OK;
  255. }
  256. HRESULT PutMonthSpecified ( VARIANT_BOOL value )
  257. {
  258. HRESULT hr = S_OK;
  259. if ((VARIANT_TRUE == m_bIsInterval) && (VARIANT_TRUE == value))
  260. hr = WBEM_E_FAILED;
  261. else
  262. m_bMonthSpecified = value;
  263. return hr;
  264. }
  265. HRESULT GetDaySpecified ( VARIANT_BOOL *value )
  266. {
  267. *value = m_bDaySpecified;
  268. return S_OK;
  269. }
  270. HRESULT PutDaySpecified ( VARIANT_BOOL value )
  271. {
  272. m_bDaySpecified = value;
  273. return S_OK;
  274. }
  275. HRESULT GetHoursSpecified ( VARIANT_BOOL *value )
  276. {
  277. *value = m_bHoursSpecified;
  278. return S_OK;
  279. }
  280. HRESULT PutHoursSpecified ( VARIANT_BOOL value )
  281. {
  282. m_bHoursSpecified = value;
  283. return S_OK;
  284. }
  285. HRESULT GetMinutesSpecified ( VARIANT_BOOL *value )
  286. {
  287. *value = m_bMinutesSpecified;
  288. return S_OK;
  289. }
  290. HRESULT PutMinutesSpecified ( VARIANT_BOOL value )
  291. {
  292. m_bMinutesSpecified = value;
  293. return S_OK;
  294. }
  295. HRESULT GetSecondsSpecified ( VARIANT_BOOL *value )
  296. {
  297. *value = m_bSecondsSpecified;
  298. return S_OK;
  299. }
  300. HRESULT PutSecondsSpecified ( VARIANT_BOOL value )
  301. {
  302. m_bSecondsSpecified = value;
  303. return S_OK;
  304. }
  305. HRESULT GetMicrosecondsSpecified ( VARIANT_BOOL *value )
  306. {
  307. *value = m_bMicrosecondsSpecified;
  308. return S_OK;
  309. }
  310. HRESULT PutMicrosecondsSpecified ( VARIANT_BOOL value )
  311. {
  312. m_bMicrosecondsSpecified = value;
  313. return S_OK;
  314. }
  315. HRESULT GetUTCSpecified ( VARIANT_BOOL *value )
  316. {
  317. *value = m_bUTCSpecified;
  318. return S_OK;
  319. }
  320. HRESULT PutUTCSpecified ( VARIANT_BOOL value )
  321. {
  322. HRESULT hr = S_OK;
  323. if ((VARIANT_TRUE == m_bIsInterval) && (VARIANT_TRUE == value))
  324. hr = WBEM_E_FAILED;
  325. else
  326. m_bUTCSpecified = value;
  327. return hr;
  328. }
  329. HRESULT GetIsInterval ( VARIANT_BOOL *value )
  330. {
  331. *value = m_bIsInterval;
  332. return S_OK;
  333. }
  334. HRESULT PutIsInterval( VARIANT_BOOL value )
  335. {
  336. if ((VARIANT_TRUE == m_bIsInterval) && (VARIANT_FALSE == value))
  337. {
  338. if (0 == m_iDay)
  339. m_iDay = 1;
  340. else if (WBEMDT_MAX_DAY < m_iDay)
  341. m_iDay = WBEMDT_MAX_DAY;
  342. }
  343. else if ((VARIANT_TRUE == value) && (VARIANT_FALSE == m_bIsInterval))
  344. {
  345. m_bDaySpecified = VARIANT_TRUE;
  346. m_bHoursSpecified = VARIANT_TRUE;
  347. m_bMinutesSpecified = VARIANT_TRUE;
  348. m_bSecondsSpecified = VARIANT_TRUE;
  349. m_bMicrosecondsSpecified = VARIANT_TRUE;
  350. }
  351. m_bIsInterval = value;
  352. return S_OK;
  353. }
  354. HRESULT GetVarDate (
  355. VARIANT_BOOL bIsLocal,
  356. DATE *dVarDate
  357. ) ;
  358. HRESULT SetVarDate (
  359. DATE dVarDate,
  360. VARIANT_BOOL bIsLocal
  361. ) ;
  362. HRESULT GetSystemTimeDate (
  363. SYSTEMTIME &fSystemTime
  364. ) ;
  365. HRESULT GetFileTimeDate (
  366. FILETIME &fFileTime
  367. ) ;
  368. HRESULT SetFileTimeDate (
  369. FILETIME fFileTime,
  370. VARIANT_BOOL bIsLocal
  371. ) ;
  372. BOOL Preceeds ( CWbemDateTime &a_Time ) ;
  373. };
  374. #endif // _DATETIME_H