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.

179 lines
5.1 KiB

  1. // FaxTime.cpp: implementation of the CFaxTime class.
  2. //
  3. //////////////////////////////////////////////////////////////////////
  4. #include "stdafx.h"
  5. #define __FILE_ID__ 9
  6. CString
  7. CFaxDuration::FormatByUserLocale () const
  8. /*++
  9. Routine name : CFaxDuration::FormatByUserLocale
  10. Routine description:
  11. Formats the duration according to the locale of the current user
  12. Author:
  13. Eran Yariv (EranY), Jan, 2000
  14. Arguments:
  15. Return Value:
  16. String of result duration
  17. --*/
  18. {
  19. DWORD dwRes = ERROR_SUCCESS;
  20. DBG_ENTER(TEXT("CFaxDuration::FormatByUserLocale"));
  21. TCHAR szTimeSep[20];
  22. //
  23. // Make sure the duration is less than 24Hrs
  24. //
  25. if (GetDays ())
  26. {
  27. ASSERTION_FAILURE;
  28. AfxThrowUserException ();
  29. }
  30. //
  31. // Get the string (MSDN says its up to 4 characters) seperating time units
  32. //
  33. if (!GetLocaleInfo (LOCALE_USER_DEFAULT,
  34. LOCALE_STIME,
  35. szTimeSep,
  36. sizeof (szTimeSep) / sizeof (szTimeSep[0])))
  37. {
  38. dwRes = GetLastError ();
  39. CALL_FAIL (RESOURCE_ERR, TEXT("GetLocaleInfo"), dwRes);
  40. PopupError (dwRes);
  41. AfxThrowResourceException ();
  42. }
  43. //
  44. // Create a string specifying the duration
  45. //
  46. CString cstrResult;
  47. cstrResult.Format (TEXT("%d%s%02d%s%02d"),
  48. GetHours (),
  49. szTimeSep,
  50. GetMinutes (),
  51. szTimeSep,
  52. GetSeconds ());
  53. return cstrResult;
  54. } // CFaxDuration::FormatByUserLocale
  55. CString
  56. CFaxTime::FormatByUserLocale (BOOL bLocal) const
  57. /*++
  58. Routine name : CFaxTime::FormatByUserLocale
  59. Routine description:
  60. Formats the date and time according to the locale of the current user
  61. Author:
  62. Eran Yariv (EranY), Jan, 2000
  63. Arguments:
  64. bLocal [in] - if TRUE no need to convert from UTC to a local time
  65. Return Value:
  66. String of result date and time
  67. --*/
  68. {
  69. DWORD dwRes = ERROR_SUCCESS;
  70. DBG_ENTER(TEXT("CFaxTime::FormatByUserLocale"));
  71. CString cstrRes;
  72. TCHAR szTimeBuf[40];
  73. TCHAR szDateBuf[120];
  74. SYSTEMTIME sysTime;
  75. FILETIME fileSysTime, fileLocalTime;
  76. if(!GetAsSystemTime (sysTime))
  77. {
  78. dwRes = GetLastError ();
  79. CALL_FAIL (RESOURCE_ERR, TEXT("CTime::GetAsSystemTime"), dwRes);
  80. PopupError (dwRes);
  81. AfxThrowResourceException ();
  82. }
  83. if(!bLocal)
  84. {
  85. //
  86. // convert the time from UTC to a local time
  87. //
  88. if(!SystemTimeToFileTime(&sysTime, &fileSysTime))
  89. {
  90. dwRes = GetLastError ();
  91. CALL_FAIL (RESOURCE_ERR, TEXT("SystemTimeToFileTime"), dwRes);
  92. PopupError (dwRes);
  93. AfxThrowResourceException ();
  94. }
  95. if(!FileTimeToLocalFileTime(&fileSysTime, &fileLocalTime))
  96. {
  97. dwRes = GetLastError ();
  98. CALL_FAIL (RESOURCE_ERR, TEXT("FileTimeToLocalFileTime"), dwRes);
  99. PopupError (dwRes);
  100. AfxThrowResourceException ();
  101. }
  102. if(!FileTimeToSystemTime(&fileLocalTime, &sysTime))
  103. {
  104. dwRes = GetLastError ();
  105. CALL_FAIL (RESOURCE_ERR, TEXT("FileTimeToSystemTime"), dwRes);
  106. PopupError (dwRes);
  107. AfxThrowResourceException ();
  108. }
  109. }
  110. //
  111. // Create a string specifying the date
  112. //
  113. if (!GetY2KCompliantDate(LOCALE_USER_DEFAULT, // Get user's locale
  114. DATE_SHORTDATE, // Short date format
  115. &sysTime, // Source date/time
  116. szDateBuf, // Output buffer
  117. sizeof(szDateBuf) / sizeof(szDateBuf[0]) // Output buffer size
  118. ))
  119. {
  120. dwRes = GetLastError ();
  121. CALL_FAIL (RESOURCE_ERR, TEXT("GetY2KCompliantDate()"), dwRes);
  122. PopupError (dwRes);
  123. AfxThrowResourceException ();
  124. }
  125. //
  126. // Create a string specifying the time
  127. //
  128. if (!FaxTimeFormat (LOCALE_USER_DEFAULT, // Get user's locale
  129. 0, // No special format
  130. &sysTime, // Source date/time
  131. NULL, // Use format from locale
  132. szTimeBuf, // Output buffer
  133. sizeof(szTimeBuf) / sizeof(szTimeBuf[0]) // Output buffer size
  134. ))
  135. {
  136. dwRes = GetLastError ();
  137. CALL_FAIL (RESOURCE_ERR, TEXT("FaxTimeFormat"), dwRes);
  138. PopupError (dwRes);
  139. AfxThrowResourceException ();
  140. }
  141. //
  142. // Append time after date with a seperating space character
  143. //
  144. cstrRes.Format (TEXT("%s %s"), szDateBuf, szTimeBuf);
  145. return cstrRes;
  146. } // CFaxTime::FormatByUserLocale