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.

192 lines
6.7 KiB

  1. /**********************************************************************/
  2. /** Microsoft Windows/NT **/
  3. /** Copyright(c) Microsoft Corp., 1991 **/
  4. /**********************************************************************/
  5. /*
  6. ctime.hxx
  7. Header file for TIME class
  8. FILE HISTORY:
  9. terryk 27-Aug-91 Created
  10. terryk 13-Sep-91 Code review changes. Attend: davidbul
  11. o-simop beng
  12. terryk 14-Oct-91 Add comment. It will not work for date
  13. before 1980.
  14. terryk 30-Nov-91 Change _ptmTime to _tmTime ( for
  15. multiple copy of the object )
  16. Yi-HsinS 5-Dec-92 Restructure to use WIN32 APIs instead
  17. of C Runtimes
  18. */
  19. #ifndef _CTIME_HXX_
  20. #define _CTIME_HXX_
  21. #include "base.hxx"
  22. /*************************************************************************
  23. NAME: WIN_TIME
  24. SYNOPSIS: Wrapper class for WIN32 TIME functions
  25. INTERFACE:
  26. WIN_TIME() - construct and set the object to current time or
  27. a specified time.
  28. ALWAYS PASS THE GMT TIME, even if fStoreAsGMT is FALSE.
  29. SetCurrentTime() - set the object to current time. ONLY CALL THIS
  30. WHEN _fStoreAsGMT IS TRUE!
  31. SetTime() - set the object to a specified time. The
  32. time value represents the seconds elapsed since
  33. 00:00:00 January 1,1970. However it will not
  34. work for date prior to January 1980.
  35. ALWAYS PASS THE GMT TIME, even if _fStoreAsGMT is FALSE.
  36. SetGMT() - set the present method to local time or GMT time
  37. These methods set a component of the time:
  38. SetHour() - set the hour field ( 0-23 )
  39. SetMinute() - set the minute field ( 0-59 )
  40. SetSecond() - set the second field ( 0-59 )
  41. SetMilliseconds() - set the millisecond field ( 0-999 )
  42. SetYear() - set the year field ( e.g. 1992 )
  43. SetMonth() - set the month field ( 1-12, 1-January )
  44. SetDay() - set day of month field ( 1-31 )
  45. Normalize() - set the DayofWeek and year day
  46. appropriately. Always call this after you are
  47. finished calling the Set[component] methods
  48. and before you use the WIN_TIME in any other way.
  49. QueryTime() - return the time in ULONG format ( the
  50. second elapsed since 00:00:00, January 1, 1970.)
  51. Always returns GMT time regardless of _fStoreAsGMT.
  52. QueryFileTime() - return the GMT time in FILETIME format
  53. Always returns GMT time regardless of _fStoreAsGMT.
  54. QueryLocalTime() - return the time in ULONG format ( the
  55. second elapsed since 00:00:00, January 1, 1970.)
  56. Always returns local time regardless of _fStoreAsGMT.
  57. QueryLocalTime() - return the GMT time in FILETIME format
  58. Always returns local time regardless of _fStoreAsGMT.
  59. These APIs return a component of the time:
  60. QueryHour() - return hour field value ( 0-23 )
  61. QueryMinute() - return minute field value ( 0-59 )
  62. QuerySecond() - return second field value ( 0-59 )
  63. QueryMilliseconds() - return the millisecond field value ( 0-999)
  64. QueryYear() - return year field value ( e.g. 1992 )
  65. QueryMonth() - return month field value ( 1-12, 1-January )
  66. QueryDay() - return Day field value ( 1- 31 )
  67. QueryDayOfWeek() - return day of week field value
  68. ( 0 - 6, Sunday = 0 )
  69. NOTES: WIN_TIME stores time internally in either local time
  70. or GMT time, depending on the setting of the _fStoreAsGMT flag.
  71. HISTORY:
  72. terryk 27-Aug-91 Created
  73. Yi-HsinS 5-Dec-92 Inherit from BASE
  74. JonN 15-Apr-1992 GMT improvements
  75. **************************************************************************/
  76. DLL_CLASS WIN_TIME : public BASE
  77. {
  78. private:
  79. BOOL _fStoreAsGMT;
  80. FILETIME _fileTime;
  81. SYSTEMTIME _sysTime;
  82. public:
  83. WIN_TIME( BOOL fStoreAsGMT = FALSE );
  84. WIN_TIME( ULONG tTimeGMT, BOOL fStoreAsGMT = FALSE );
  85. WIN_TIME( FILETIME fileTimeGMT, BOOL fStoreAsGMT = FALSE );
  86. //
  87. // Set time methods
  88. //
  89. APIERR SetCurrentTime();
  90. APIERR SetCurrentTimeGMT()
  91. { return SetCurrentTime(); }
  92. APIERR SetTime( ULONG tTimeGMT );
  93. APIERR SetTime( FILETIME fileTimeGMT );
  94. APIERR SetTimeGMT( ULONG tTimeGMT )
  95. { return SetTime( tTimeGMT ); }
  96. APIERR SetTimeGMT( FILETIME fileTimeGMT )
  97. { return SetTime( fileTimeGMT ); }
  98. APIERR SetTimeLocal( ULONG tTimeLocal );
  99. APIERR SetTimeLocal( FILETIME fileTimeLocal );
  100. APIERR SetGMT ( BOOL fStoreAsGMT );
  101. //
  102. // Query time methods
  103. //
  104. APIERR QueryTime( ULONG *ptTimeGMT ) const;
  105. APIERR QueryFileTime( FILETIME *pfileTimeGMT ) const;
  106. APIERR QueryTimeGMT( ULONG *ptTimeGMT ) const
  107. { return QueryTime( ptTimeGMT ); }
  108. APIERR QueryFileTimeGMT( FILETIME *pfileTimeGMT ) const
  109. { return QueryFileTime( pfileTimeGMT ); }
  110. APIERR QueryTimeLocal( ULONG *ptTimeLocal ) const;
  111. APIERR QueryFileTimeLocal( FILETIME *pfileTimeLocal ) const;
  112. //
  113. // Set individual field methods
  114. //
  115. VOID SetHour( INT nHour )
  116. { _sysTime.wHour = (WORD)nHour; }
  117. VOID SetMinute( INT nMinute )
  118. { _sysTime.wMinute = (WORD)nMinute; }
  119. VOID SetSecond( INT nSecond )
  120. { _sysTime.wSecond = (WORD)nSecond; }
  121. VOID SetMilliseconds( INT nMilliseconds )
  122. { _sysTime.wMilliseconds = (WORD)nMilliseconds; }
  123. VOID SetYear( INT nYear )
  124. { _sysTime.wYear = (WORD)nYear; }
  125. VOID SetMonth( INT nMonth )
  126. { _sysTime.wMonth = (WORD)nMonth; }
  127. VOID SetDay( INT nDay )
  128. { _sysTime.wDay = (WORD)nDay; }
  129. APIERR Normalize();
  130. //
  131. // Query individual field methods
  132. //
  133. INT QueryHour() const
  134. { return _sysTime.wHour; }
  135. INT QueryMinute() const
  136. { return _sysTime.wMinute; }
  137. INT QuerySecond() const
  138. { return _sysTime.wSecond; }
  139. INT QueryMilliseconds() const
  140. { return _sysTime.wMilliseconds; }
  141. INT QueryYear() const
  142. { return _sysTime.wYear; }
  143. INT QueryMonth() const
  144. { return _sysTime.wMonth; }
  145. INT QueryDay() const
  146. { return _sysTime.wDay; }
  147. INT QueryDayOfWeek() const
  148. { return _sysTime.wDayOfWeek; }
  149. };
  150. #endif // _CTIME_HXX_