Source code of Windows XP (NT5)
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.

308 lines
6.2 KiB

  1. /*++
  2. Copyright (c) 1989 Microsoft Corporation
  3. Module Name:
  4. TimeSup.c
  5. Abstract:
  6. This module implements the Rx Time conversion support routines
  7. Author:
  8. Gary Kimura [GaryKi] 19-Feb-1990
  9. Revision History:
  10. --*/
  11. #include "precomp.h"
  12. #pragma hdrstop
  13. //
  14. // The Bug check file id for this module
  15. //
  16. #define BugCheckFileId (RDBSS_BUG_CHECK_TIMESUP)
  17. //
  18. // The local debug trace level
  19. //
  20. #define Dbg (DEBUG_TRACE_TIMESUP)
  21. #ifdef ALLOC_PRAGMA
  22. #pragma alloc_text(PAGE, RxNtTimeToRxTime)
  23. #pragma alloc_text(PAGE, RxRxDateToNtTime)
  24. #pragma alloc_text(PAGE, RxRxTimeToNtTime)
  25. #pragma alloc_text(PAGE, RxGetCurrentRxTime)
  26. #endif
  27. BOOLEAN
  28. RxNtTimeToRxTime (
  29. IN PRX_CONTEXT RxContext,
  30. IN LARGE_INTEGER NtTime,
  31. OUT PRDBSS_TIME_STAMP RxTime
  32. )
  33. /*++
  34. Routine Description:
  35. This routine converts an NtTime value to its corresponding Rx time value.
  36. Arguments:
  37. NtTime - Supplies the Nt GMT Time value to convert from
  38. RxTime - Receives the equivalent Rx time value
  39. Return Value:
  40. BOOLEAN - TRUE if the Nt time value is within the range of Rx's
  41. time range, and FALSE otherwise
  42. --*/
  43. {
  44. TIME_FIELDS TimeFields;
  45. //
  46. // Convert the input to the a time field record. Always add
  47. // almost two seconds to round up to the nearest double second.
  48. //
  49. NtTime.QuadPart = NtTime.QuadPart + (LONGLONG)AlmostTwoSeconds;
  50. RxSystemTimeToLocalTime( &NtTime, &NtTime );
  51. RtlTimeToTimeFields( &NtTime, &TimeFields );
  52. //
  53. // Check the range of the date found in the time field record
  54. //
  55. if ((TimeFields.Year < 1980) || (TimeFields.Year > (1980 + 127))) {
  56. return FALSE;
  57. }
  58. //
  59. // The year will fit in Rx so simply copy over the information
  60. //
  61. RxTime->Time.DoubleSeconds = (USHORT)(TimeFields.Second / 2);
  62. RxTime->Time.Minute = (USHORT)(TimeFields.Minute);
  63. RxTime->Time.Hour = (USHORT)(TimeFields.Hour);
  64. RxTime->Date.Year = (USHORT)(TimeFields.Year - 1980);
  65. RxTime->Date.Month = (USHORT)(TimeFields.Month);
  66. RxTime->Date.Day = (USHORT)(TimeFields.Day);
  67. UNREFERENCED_PARAMETER( RxContext );
  68. return TRUE;
  69. }
  70. LARGE_INTEGER
  71. RxRxDateToNtTime (
  72. IN PRX_CONTEXT RxContext,
  73. IN RDBSS_DATE RxDate
  74. )
  75. /*++
  76. Routine Description:
  77. This routine converts a Rx datev value to its corresponding Nt GMT
  78. Time value.
  79. Arguments:
  80. RxDate - Supplies the Rx Date to convert from
  81. Return Value:
  82. LARGE_INTEGER - Receives the corresponding Nt Time value
  83. --*/
  84. {
  85. TIME_FIELDS TimeFields;
  86. LARGE_INTEGER Time;
  87. //
  88. // Pack the input time/date into a time field record
  89. //
  90. TimeFields.Year = (USHORT)(RxDate.Year + 1980);
  91. TimeFields.Month = (USHORT)(RxDate.Month);
  92. TimeFields.Day = (USHORT)(RxDate.Day);
  93. TimeFields.Hour = (USHORT)0;
  94. TimeFields.Minute = (USHORT)0;
  95. TimeFields.Second = (USHORT)0;
  96. TimeFields.Milliseconds = (USHORT)0;
  97. //
  98. // Convert the time field record to Nt LARGE_INTEGER, and set it to zero
  99. // if we were given a bogus time.
  100. //
  101. if (!RtlTimeFieldsToTime( &TimeFields, &Time )) {
  102. Time.LowPart = 0;
  103. Time.HighPart = 0;
  104. } else {
  105. RxLocalTimeToSystemTime( &Time, &Time );
  106. }
  107. return Time;
  108. UNREFERENCED_PARAMETER( RxContext );
  109. }
  110. LARGE_INTEGER
  111. RxRxTimeToNtTime (
  112. IN PRX_CONTEXT RxContext,
  113. IN RDBSS_TIME_STAMP RxTime,
  114. IN UCHAR TenMilliSeconds
  115. )
  116. /*++
  117. Routine Description:
  118. This routine converts a Rx time value pair to its corresponding Nt GMT
  119. Time value.
  120. Arguments:
  121. RxTime - Supplies the Rx Time to convert from
  122. TenMilliSeconds - A 10 Milisecond resolution
  123. Return Value:
  124. LARGE_INTEGER - Receives the corresponding Nt GMT Time value
  125. --*/
  126. {
  127. TIME_FIELDS TimeFields;
  128. LARGE_INTEGER Time;
  129. //
  130. // Pack the input time/date into a time field record
  131. //
  132. TimeFields.Year = (USHORT)(RxTime.Date.Year + 1980);
  133. TimeFields.Month = (USHORT)(RxTime.Date.Month);
  134. TimeFields.Day = (USHORT)(RxTime.Date.Day);
  135. TimeFields.Hour = (USHORT)(RxTime.Time.Hour);
  136. TimeFields.Minute = (USHORT)(RxTime.Time.Minute);
  137. TimeFields.Second = (USHORT)(RxTime.Time.DoubleSeconds * 2);
  138. if (TenMilliSeconds != 0) {
  139. TimeFields.Second += (USHORT)(TenMilliSeconds / 100);
  140. TimeFields.Milliseconds = (USHORT)(TenMilliSeconds % 100);
  141. } else {
  142. TimeFields.Milliseconds = (USHORT)0;
  143. }
  144. //
  145. // If the second value is greater than 59 then we truncate it to 0.
  146. //
  147. if (TimeFields.Second > 59) {
  148. TimeFields.Second = 0;
  149. }
  150. //
  151. // Convert the time field record to Nt LARGE_INTEGER, and set it to zero
  152. // if we were given a bogus time.
  153. //
  154. if (!RtlTimeFieldsToTime( &TimeFields, &Time )) {
  155. Time.LowPart = 0;
  156. Time.HighPart = 0;
  157. } else {
  158. RxLocalTimeToSystemTime( &Time, &Time );
  159. }
  160. return Time;
  161. UNREFERENCED_PARAMETER( RxContext );
  162. }
  163. RDBSS_TIME_STAMP
  164. RxGetCurrentRxTime (
  165. IN PRX_CONTEXT RxContext
  166. )
  167. /*++
  168. Routine Description:
  169. This routine returns the current system time in Rx time
  170. Arguments:
  171. Return Value:
  172. RDBSS_TIME_STAMP - Receives the current system time
  173. --*/
  174. {
  175. LARGE_INTEGER Time;
  176. TIME_FIELDS TimeFields;
  177. RDBSS_TIME_STAMP RxTime;
  178. //
  179. // Get the current system time, and map it into a time field record.
  180. //
  181. RxQuerySystemTime( &Time );
  182. RxSystemTimeToLocalTime( &Time, &Time );
  183. //
  184. // Always add almost two seconds to round up to the nearest double second.
  185. //
  186. Time.QuadPart = Time.QuadPart + (LONGLONG)AlmostTwoSeconds;
  187. (VOID)RtlTimeToTimeFields( &Time, &TimeFields );
  188. //
  189. // Now simply copy over the information
  190. //
  191. RxTime.Time.DoubleSeconds = (USHORT)(TimeFields.Second / 2);
  192. RxTime.Time.Minute = (USHORT)(TimeFields.Minute);
  193. RxTime.Time.Hour = (USHORT)(TimeFields.Hour);
  194. RxTime.Date.Year = (USHORT)(TimeFields.Year - 1980);
  195. RxTime.Date.Month = (USHORT)(TimeFields.Month);
  196. RxTime.Date.Day = (USHORT)(TimeFields.Day);
  197. UNREFERENCED_PARAMETER( RxContext );
  198. return RxTime;
  199. }