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.

252 lines
4.2 KiB

  1. /*++
  2. Copyright (C) Microsoft Corporation, 1997 - 1998
  3. All rights reserved.
  4. Module Name:
  5. time.cxx
  6. Abstract:
  7. time related functions.
  8. Author:
  9. Steve Kiraly (SteveKi) 18-Dec-1997
  10. --*/
  11. #include "precomp.hxx"
  12. #pragma hdrstop
  13. #include "time.hxx"
  14. #include "persist.hxx"
  15. /*++
  16. Routine Name:
  17. GetTimeZoneBias
  18. Routine Description:
  19. Returns the time zone bias.
  20. Arguments:
  21. Nothing.
  22. Return Value:
  23. Value of the time zone specific bias.
  24. --*/
  25. LONG
  26. lGetTimeZoneBias(
  27. VOID
  28. )
  29. {
  30. LONG lBias;
  31. TIME_ZONE_INFORMATION tzi;
  32. //
  33. // Get the time zone specific bias.
  34. //
  35. switch( GetTimeZoneInformation( &tzi ) ){
  36. case TIME_ZONE_ID_DAYLIGHT:
  37. lBias = (tzi.Bias + tzi.DaylightBias);
  38. break;
  39. case TIME_ZONE_ID_STANDARD:
  40. lBias = (tzi.Bias + tzi.StandardBias);
  41. break;
  42. case TIME_ZONE_ID_UNKNOWN:
  43. lBias = tzi.Bias;
  44. break;
  45. default:
  46. DBGMSG(DBG_ERROR, ("GetTimeZoneInformation failed: %d\n", GetLastError()));
  47. lBias = 0;
  48. break;
  49. }
  50. return lBias;
  51. }
  52. /*++
  53. Routine Name:
  54. SystemTimeToLocalTime
  55. Routine Description:
  56. Converts the system time in minutes to local time in minutes.
  57. Arguments:
  58. System time in minutes to convert.
  59. Return Value:
  60. The converted local time in minutes if sucessful,
  61. otherwize returns the original system time.
  62. --*/
  63. DWORD
  64. SystemTimeToLocalTime(
  65. IN DWORD Minutes
  66. )
  67. {
  68. //
  69. // Ensure there is no wrap around. Add a full day to
  70. // prevent biases
  71. //
  72. Minutes += (24*60);
  73. //
  74. // Adjust for bias.
  75. //
  76. Minutes -= lGetTimeZoneBias();
  77. //
  78. // Now discard extra day.
  79. //
  80. Minutes = Minutes % (24*60);
  81. return Minutes;
  82. }
  83. /*++
  84. Routine Name:
  85. LocalTimeToSystemTime
  86. Routine Description:
  87. Converts the local time in minutes to system time in minutes.
  88. Arguments:
  89. Local time in minutes to convert.
  90. Return Value:
  91. The converted system time in minutes if sucessful,
  92. otherwize returns the original local time.
  93. --*/
  94. DWORD
  95. LocalTimeToSystemTime(
  96. IN DWORD Minutes
  97. )
  98. {
  99. //
  100. // Ensure there is no wrap around. Add a full day to
  101. // prevent biases
  102. //
  103. Minutes += (24*60);
  104. //
  105. // Adjust for bias.
  106. //
  107. Minutes += lGetTimeZoneBias();
  108. //
  109. // Now discard extra day.
  110. //
  111. Minutes = Minutes % (24*60);
  112. return Minutes;
  113. }
  114. /*++
  115. Routine Name:
  116. bGetTimeFormatString(
  117. Routine Description:
  118. Get the time format string for the time picker
  119. control without the second specifier.
  120. Arguments:
  121. Refernece to string class where to return string.
  122. Return Value:
  123. TRUE format string returned. FALSE error occurred.
  124. --*/
  125. BOOL
  126. bGetTimeFormatString(
  127. IN TString &strFormatString
  128. )
  129. {
  130. //
  131. // Setup the time picker controls to use a short time format with no seconds.
  132. //
  133. TCHAR szTimeFormat[MAX_PATH] = {0};
  134. TCHAR szTimeSep[MAX_PATH] = {0};
  135. LPTSTR pszTimeFormat = szTimeFormat;
  136. BOOL bStatus = FALSE;
  137. if( GetLocaleInfo( LOCALE_USER_DEFAULT,
  138. LOCALE_STIMEFORMAT,
  139. szTimeFormat,
  140. COUNTOF(szTimeFormat)) &&
  141. GetLocaleInfo( LOCALE_USER_DEFAULT,
  142. LOCALE_STIME,
  143. szTimeSep,
  144. COUNTOF(szTimeSep)))
  145. {
  146. INT cchTimeSep = _tcslen(szTimeSep);
  147. TCHAR szShortTimeFormat[MAX_PATH];
  148. LPTSTR pszShortTimeFormat = szShortTimeFormat;
  149. //
  150. // Remove the seconds format string and preceeding separator.
  151. //
  152. while (*pszTimeFormat)
  153. {
  154. if ((*pszTimeFormat != TEXT('s')) && (*pszTimeFormat != TEXT('S')))
  155. {
  156. *pszShortTimeFormat++ = *pszTimeFormat;
  157. }
  158. else
  159. {
  160. *pszShortTimeFormat = TEXT('\0');
  161. bTrimString(szShortTimeFormat, TEXT(" "));
  162. bTrimString(szShortTimeFormat, szTimeSep);
  163. pszShortTimeFormat = szShortTimeFormat + lstrlen(szShortTimeFormat);
  164. }
  165. pszTimeFormat++;
  166. }
  167. *pszShortTimeFormat = TEXT('\0');
  168. bStatus = strFormatString.bUpdate( szShortTimeFormat );
  169. }
  170. return bStatus;
  171. }