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.

210 lines
4.1 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 FILETIME &ft ) ;
  71. WBEMTime operator+ ( const WBEMTimeSpan &ts ) const;
  72. WBEMTime operator- ( const WBEMTimeSpan &sub ) const;
  73. BOOL GetSYSTEMTIME ( SYSTEMTIME *pst ) const;
  74. BOOL GetDMTF ( SYSTEMTIME &st, long &offset ) const;
  75. BOOL GetFILETIME ( FILETIME *pst ) const;
  76. bool IsOk () const { return m_uTime != INVALID_TIME ? true : false; }
  77. static LONG WINAPI GetLocalOffsetForDate(const SYSTEMTIME *pst);
  78. private:
  79. ULONGLONG m_uTime;
  80. };
  81. private:
  82. VARIANT_BOOL m_bYearSpecified;
  83. VARIANT_BOOL m_bMonthSpecified;
  84. VARIANT_BOOL m_bDaySpecified;
  85. VARIANT_BOOL m_bHoursSpecified;
  86. VARIANT_BOOL m_bMinutesSpecified;
  87. VARIANT_BOOL m_bSecondsSpecified;
  88. VARIANT_BOOL m_bMicrosecondsSpecified;
  89. VARIANT_BOOL m_bUTCSpecified;
  90. VARIANT_BOOL m_bIsInterval;
  91. long m_iYear;
  92. long m_iMonth;
  93. long m_iDay;
  94. long m_iHours;
  95. long m_iMinutes;
  96. long m_iSeconds;
  97. long m_iMicroseconds;
  98. long m_iUTC;
  99. bool CheckField (
  100. LPWSTR pValue,
  101. ULONG len,
  102. VARIANT_BOOL &bIsSpecified,
  103. long &iValue,
  104. long maxValue,
  105. long minValue
  106. );
  107. bool CheckUTC (
  108. LPWSTR pValue,
  109. VARIANT_BOOL &bIsSpecified,
  110. long &iValue,
  111. bool bParseSign = true
  112. );
  113. protected:
  114. public:
  115. CWbemDateTime(void);
  116. virtual ~CWbemDateTime(void);
  117. // ISWbemDateTime methods
  118. HRESULT GetValue ( BSTR *value ) ;
  119. HRESULT PutValue ( BSTR value ) ;
  120. HRESULT GetDay ( long *value )
  121. {
  122. *value = m_iDay;
  123. return S_OK;
  124. }
  125. HRESULT GetHours ( long *value )
  126. {
  127. *value = m_iHours;
  128. return S_OK;
  129. }
  130. HRESULT GetMinutes ( long *value )
  131. {
  132. *value = m_iMinutes;
  133. return S_OK;
  134. }
  135. HRESULT GetSeconds ( long *value )
  136. {
  137. *value = m_iSeconds;
  138. return S_OK;
  139. }
  140. HRESULT GetMicroseconds ( long *value )
  141. {
  142. *value = m_iMicroseconds;
  143. return S_OK;
  144. }
  145. HRESULT GetIsInterval ( VARIANT_BOOL *value )
  146. {
  147. *value = m_bIsInterval;
  148. return S_OK;
  149. }
  150. HRESULT GetFileTimeDate (
  151. FILETIME &fFileTime
  152. ) ;
  153. HRESULT GetSystemTimeDate (
  154. SYSTEMTIME &fSystemTime
  155. ) ;
  156. HRESULT SetFileTimeDate (
  157. FILETIME fFileTime,
  158. VARIANT_BOOL bIsLocal
  159. ) ;
  160. BOOL Preceeds ( CWbemDateTime &a_Time ) ;
  161. };
  162. #endif // _DATETIME_H