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.

176 lines
5.3 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1993.
  5. //
  6. // File: time.hxx
  7. //
  8. // Contents: Time/date common routines.
  9. //
  10. // History: 08-Sep-95 EricB Created.
  11. // 01-Dec-95 MarkBl Split from util.hxx.
  12. //
  13. //----------------------------------------------------------------------------
  14. #ifndef __TIME_HXX__
  15. #define __TIME_HXX__
  16. //#include "runobj.hxx"
  17. //
  18. // Time/date constants
  19. //
  20. const WORD JOB_MIN_MONTH = 1;
  21. const WORD JOB_MAX_MONTH = 12;
  22. const WORD JOB_MONTHS_PER_YEAR = JOB_MAX_MONTH ;
  23. const WORD JOB_MIN_DAY = 1;
  24. const WORD JOB_MAX_DAY = 31;
  25. const WORD JOB_DAYS_PER_MONTHMAX = JOB_MAX_DAY;
  26. const WORD JOB_MIN_HOUR = 0;
  27. const WORD JOB_MAX_HOUR = 23;
  28. const WORD JOB_MIN_MINUTE = 0;
  29. const WORD JOB_MAX_MINUTE = 59;
  30. const WORD JOB_MILLISECONDS_PER_SECOND = 1000;
  31. const WORD JOB_MILLISECONDS_PER_MINUTE = 60 * JOB_MILLISECONDS_PER_SECOND;
  32. const WORD JOB_MINS_PER_HOUR = 60;
  33. const WORD JOB_HOURS_PER_DAY = 24;
  34. const WORD JOB_MINS_PER_DAY = JOB_HOURS_PER_DAY * JOB_MINS_PER_HOUR;
  35. const WORD JOB_DAYS_PER_WEEK = 7;
  36. const DWORD JOB_RGFDAYS_MAX = 0x7fffffff;
  37. const WORD JOB_RGFDOW_MAX = 0x7f;
  38. const WORD JOB_RGFMONTHS_MAX = 0xfff;
  39. const WORD JOB_MONTH_FEBRUARY = 2;
  40. const int JOB_TIMEBUF_LEN = 40;
  41. const short MAX_INTERVAL_MINUTES = 720;
  42. const short MAX_INTERVAL_HOURS = 12;
  43. const unsigned long FILETIMES_PER_MILLISECOND = 10000;
  44. const DWORD FILETIMES_PER_SECOND = JOB_MILLISECONDS_PER_SECOND *
  45. FILETIMES_PER_MILLISECOND;
  46. const DWORD FILETIMES_PER_MINUTE = FILETIMES_PER_MILLISECOND *
  47. JOB_MILLISECONDS_PER_MINUTE;
  48. //
  49. // BUGBUG: neither of these are currently working without CRT initialization.
  50. // BUG # 37752.
  51. //
  52. //const __int64 FILETIMES_PER_HOUR = (__int64)FILETIMES_PER_MINUTE
  53. // * JOB_MINS_PER_HOUR;
  54. //const __int64 FILETIMES_PER_DAY = FILETIMES_PER_HOUR * JOB_HOURS_PER_DAY;
  55. //
  56. // Logically, this should be MAX_FILETIME = { MAXDWORD, MAXDWORD };
  57. // but CompareFileTime on NT 4 is broken for FILETIMEs larger than the
  58. // one below (NT bug 88901).
  59. // Also, the FILETIME below is the largest FILETIME accepted by
  60. // FileTimeToSystemTime().
  61. //
  62. const FILETIME MAX_FILETIME = { MAXULONG, 0x7fffffff };
  63. const BYTE g_rgMonthDays[] =
  64. {
  65. 0, // make January's index 1
  66. 31, // January
  67. 28, // February
  68. 31, // March
  69. 30, // April
  70. 31, // May
  71. 30, // June
  72. 31, // July
  73. 31, // August
  74. 30, // September
  75. 31, // October
  76. 30, // November
  77. 31 // December
  78. };
  79. //
  80. // Time/date common routines.
  81. //
  82. HRESULT MonthDays(WORD wMonth, WORD wYear, WORD *pwDays);
  83. BOOL IsLeapYear(WORD wYear);
  84. BOOL IsValidDate(WORD wMonth, WORD wDay, WORD wYear);
  85. //+----------------------------------------------------------------------------
  86. //
  87. // Function: IsFirstDateEarlier
  88. //
  89. // Synopsis: Compares the date portion of the two params
  90. //
  91. // Arguments: [pstFirst, pstSecond] - the dates to compare
  92. //
  93. // Returns: TRUE if the first date is earlier than the second
  94. //
  95. //-----------------------------------------------------------------------------
  96. inline BOOL
  97. IsFirstDateEarlier(const SYSTEMTIME * pstFirst, const SYSTEMTIME * pstSecond)
  98. {
  99. if (pstFirst->wYear > pstSecond->wYear ||
  100. (pstFirst->wYear == pstSecond->wYear &&
  101. (pstFirst->wMonth > pstSecond->wMonth ||
  102. (pstFirst->wMonth == pstSecond->wMonth &&
  103. pstFirst->wDay >= pstSecond->wDay))))
  104. {
  105. return FALSE;
  106. }
  107. return TRUE;
  108. }
  109. //+----------------------------------------------------------------------------
  110. //
  111. // Function: IsFirstTimeEarlier
  112. //
  113. // Synopsis: Compares two SYSTEMTIMES
  114. //
  115. // Arguments: [pstFirst, pstSecond] - the dates to compare
  116. //
  117. // Returns: TRUE if the first date-time is earlier than the second
  118. //
  119. //-----------------------------------------------------------------------------
  120. inline BOOL
  121. IsFirstTimeEarlier(const SYSTEMTIME *pstFirst, const SYSTEMTIME *pstSecond)
  122. {
  123. FILETIME ftFirst, ftSecond;
  124. SystemTimeToFileTime(pstFirst, &ftFirst);
  125. SystemTimeToFileTime(pstSecond, &ftSecond);
  126. return (CompareFileTime(&ftFirst, &ftSecond) < 0);
  127. }
  128. //+----------------------------------------------------------------------------
  129. //
  130. // Function: IncrementMonth
  131. //
  132. // Synopsis: increases the SYSTEMTIME month value by one and corrects for
  133. // overflow
  134. //
  135. // Arguments: [pst] - the date to increment
  136. //
  137. //-----------------------------------------------------------------------------
  138. inline void
  139. IncrementMonth(LPSYSTEMTIME pst)
  140. {
  141. if (pst->wMonth < JOB_MONTHS_PER_YEAR)
  142. {
  143. pst->wMonth++;
  144. }
  145. else
  146. {
  147. pst->wMonth = 1;
  148. pst->wYear++;
  149. }
  150. }
  151. //+----------------------------------------------------------------------------
  152. //
  153. // Function: IncrementDau
  154. //
  155. // Synopsis: increases the SYSTEMTIME day value by one and corrects for
  156. // overflow
  157. //
  158. // Arguments: [pst] - the date to increment
  159. //
  160. //-----------------------------------------------------------------------------
  161. void
  162. IncrementDay(LPSYSTEMTIME pst);
  163. #endif // __TIME_HXX__