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.

148 lines
6.0 KiB

  1. //***************************************************************************
  2. //
  3. // Copyright � Microsoft Corporation. All rights reserved.
  4. //
  5. // wbemtime.h
  6. //
  7. // Purpose: declares the WBEMTime and WBEMTimeSpan objects which are
  8. // similar to the MFC CTime and CTimeSpan objects. The WBEM versions
  9. // are capable of storing down to the nsec and also have functions for
  10. // Creating from and getting BSTRs.
  11. //
  12. // Note; The current implementation of WBEMTime does not support dates
  13. // before 1601;
  14. //
  15. //***************************************************************************
  16. #if _MSC_VER > 1000
  17. #pragma once
  18. #endif
  19. #ifndef WBEMTIME_HEADERFILE_IS_INCLUDED
  20. #define WBEMTIME_HEADERFILE_IS_INCLUDED
  21. #define INVALID_TIME 0xffffffffffffffff
  22. #include <polarity.h>
  23. #include <time.h>
  24. #pragma warning( disable : 4290 ) // Ignore 'C++ Exception Specification ignored'
  25. #include <ProvExce.h>
  26. ///////////////////////////////////////////////////////////////////////////
  27. // WBEMTimeSpan - This class holds time span values.
  28. class POLARITY WBEMTimeSpan
  29. {
  30. private:
  31. ULONGLONG m_Time;
  32. friend class WBEMTime;
  33. public:
  34. WBEMTimeSpan () { m_Time = INVALID_TIME ; }
  35. WBEMTimeSpan ( const BSTR bstrDMTFFormat ) { *this = bstrDMTFFormat ; }
  36. WBEMTimeSpan (
  37. int iDays ,
  38. int iHours ,
  39. int iMinutes ,
  40. int iSeconds ,
  41. int iMSec=0 ,
  42. int iUSec=0,
  43. int iNSec=0
  44. ) ;
  45. WBEMTimeSpan operator+ (const WBEMTimeSpan &uAdd ) const ;
  46. const WBEMTimeSpan &operator+= ( const WBEMTimeSpan &uAdd ) ;
  47. WBEMTimeSpan operator- (const WBEMTimeSpan &uSub ) const ;
  48. const WBEMTimeSpan &operator-= ( const WBEMTimeSpan &uSub ) ;
  49. const WBEMTimeSpan &operator= ( const BSTR pDMTFFormat ) ;
  50. BOOL operator== ( const WBEMTimeSpan &a ) const { return m_Time == a.m_Time ; }
  51. BOOL operator!= ( const WBEMTimeSpan &a ) const { return m_Time != a.m_Time ; }
  52. BOOL operator< ( const WBEMTimeSpan &a ) const { return m_Time < a.m_Time ; }
  53. BOOL operator<= ( const WBEMTimeSpan &a ) const { return m_Time <= a.m_Time ; }
  54. BOOL operator> ( const WBEMTimeSpan &a ) const { return m_Time > a.m_Time ; }
  55. BOOL operator>= ( const WBEMTimeSpan &a ) const { return m_Time >= a.m_Time ; }
  56. BSTR GetBSTR ( void ) const throw ( CHeap_Exception ) ;
  57. bool IsOk () const { return m_Time != INVALID_TIME ? true : false; }
  58. ULONGLONG GetTime () const { return m_Time ; }
  59. void Clear ( void ) { m_Time = INVALID_TIME ; }
  60. // These are all deprecated
  61. WBEMTimeSpan ( const FILETIME &ft ) ;
  62. WBEMTimeSpan ( const time_t & t ) ;
  63. const WBEMTimeSpan &operator= ( const FILETIME &ft ) ;
  64. const WBEMTimeSpan &operator= ( const time_t &t ) ;
  65. BOOL Gettime_t ( time_t *ptime_t ) const ;
  66. BOOL GetFILETIME ( FILETIME *pst ) const ;
  67. };
  68. ///////////////////////////////////////////////////////////////////////////
  69. // WBEMTime - This class holds time values.
  70. class POLARITY WBEMTime
  71. {
  72. public:
  73. WBEMTime () { m_uTime = INVALID_TIME ; }
  74. WBEMTime ( const BSTR bstrDMTFFormat ) { *this = bstrDMTFFormat ; }
  75. WBEMTime ( const SYSTEMTIME &st ) { *this = st ; }
  76. WBEMTime ( const FILETIME &ft ) { *this = ft ; }
  77. WBEMTime ( const struct tm &tmin ) { *this = tmin ; }
  78. WBEMTime ( const time_t &t ) { *this = t ; }
  79. WBEMTime operator+ ( const WBEMTimeSpan &uAdd ) const ;
  80. const WBEMTime &operator+=( const WBEMTimeSpan &ts ) ;
  81. WBEMTimeSpan operator- ( const WBEMTime &sub ) ;
  82. WBEMTime operator- ( const WBEMTimeSpan &sub ) const;
  83. const WBEMTime &operator-=( const WBEMTimeSpan &sub );
  84. const WBEMTime &operator= ( const BSTR bstrDMTFFormat ) ;
  85. const WBEMTime &operator= ( const SYSTEMTIME &st ) ;
  86. const WBEMTime &operator= ( const FILETIME &ft ) ;
  87. const WBEMTime &operator= ( const struct tm &tmin ) ;
  88. const WBEMTime &operator= ( const time_t & t) ;
  89. BOOL operator== ( const WBEMTime &a ) const { return m_uTime == a.m_uTime ; }
  90. BOOL operator!= ( const WBEMTime &a ) const { return m_uTime != a.m_uTime ; }
  91. BOOL operator< ( const WBEMTime &a ) const { return m_uTime < a.m_uTime ; }
  92. BOOL operator<= ( const WBEMTime &a ) const { return m_uTime <= a.m_uTime ; }
  93. BOOL operator> ( const WBEMTime &a ) const { return m_uTime > a.m_uTime ; }
  94. BOOL operator>= ( const WBEMTime &a ) const { return m_uTime >= a.m_uTime ; }
  95. BSTR GetBSTR ( void ) const throw ( CHeap_Exception ) ;
  96. BOOL GetStructtm (struct tm *ptm ) const;
  97. BOOL Gettime_t ( time_t *ptime_t ) const;
  98. BOOL GetSYSTEMTIME ( SYSTEMTIME *pst ) const;
  99. BOOL GetFILETIME ( FILETIME *pst ) const;
  100. BOOL SetDMTF ( const BSTR wszText ) ;
  101. BSTR GetDMTF ( BOOL bLocal = FALSE ) const throw ( CHeap_Exception ) ;
  102. BSTR GetDMTFNonNtfs(void) const ;
  103. void Clear ( void ) { m_uTime = INVALID_TIME ; }
  104. bool IsOk () const { return m_uTime != INVALID_TIME ? true : false; }
  105. ULONGLONG GetTime () const { return m_uTime ; }
  106. static LONG WINAPI GetLocalOffsetForDate(const struct tm *tmin);
  107. static LONG WINAPI GetLocalOffsetForDate(const SYSTEMTIME *pst);
  108. static LONG WINAPI GetLocalOffsetForDate(const FILETIME *pft);
  109. static LONG WINAPI GetLocalOffsetForDate(const time_t &t);
  110. private:
  111. ULONGLONG m_uTime;
  112. };
  113. #endif