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.

71 lines
2.9 KiB

  1. // CIMFUtil.h : Declaration of the CIMFUtil class
  2. #ifndef __CIMFUTIL_H_
  3. #define __CIMFUTIL_H_
  4. class CIMFUtil
  5. {
  6. public:
  7. /************************************************************************************************
  8. Member: CIMFUtil::SystemTimeToIMFDate, protected
  9. Synopsis: Converts a SYSTEMTIME to a string conforming to the IMF format (RFC 822).
  10. Used by the AddReceivedHeader function.
  11. Arguments: [in] pst - SYSTEMTIME to be analyzed.
  12. [out] lpszIMFDate - string that will receive the date in the IMF-required format.
  13. Notes: 1. Adapted from the original POP3 code by Virtual Motion (general.cpp).
  14. 2. Result stays ANSI (single byte). The IMF date is a 7-bit string for header.
  15. History: 03/08/2001 - created, Luciano Passuello (lucianop).
  16. ************************************************************************************************/
  17. static void SystemTimeToIMFDate(SYSTEMTIME* pst, LPSTR lpszIMFDate)
  18. {
  19. static const LPCSTR rgszMonthsOfTheYear[] =
  20. {
  21. "Jan", "Feb", "Mar", "Apr", "May", "Jun",
  22. "Jul", "Aug", "Sep", "Oct", "Nov", "Dec",
  23. NULL
  24. };
  25. static const LPCSTR rgszDaysOfTheWeek[] =
  26. {
  27. "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", NULL
  28. };
  29. TIME_ZONE_INFORMATION tzi;
  30. long ltzBias = 0;
  31. DWORD dwTimeZoneId = GetTimeZoneInformation (&tzi);
  32. switch (dwTimeZoneId)
  33. {
  34. case TIME_ZONE_ID_DAYLIGHT:
  35. ltzBias = tzi.Bias + tzi.DaylightBias;
  36. break;
  37. case TIME_ZONE_ID_STANDARD:
  38. case TIME_ZONE_ID_UNKNOWN:
  39. default:
  40. ltzBias = tzi.Bias + tzi.StandardBias;
  41. break;
  42. }
  43. long ltzHour = ltzBias / 60;
  44. long ltzMinute = ltzBias % 60;
  45. char cDiff = (ltzHour < 0) ? '+' : '-';
  46. assert((pst->wMonth - 1) >= 0);
  47. // puts everything together
  48. sprintf(lpszIMFDate,
  49. "%3s, %d %3s %4d %02d:%02d:%02d %c%02d%02d", // "ddd, dd mmm yyyy hh:mm:ss +/- hhmm\0"
  50. rgszDaysOfTheWeek[pst->wDayOfWeek], // "ddd"
  51. pst->wDay, // "dd"
  52. rgszMonthsOfTheYear[pst->wMonth - 1], // "mmm"
  53. pst->wYear, // "yyyy"
  54. pst->wHour, // "hh"
  55. pst->wMinute, // "mm"
  56. pst->wSecond, // "ss"
  57. cDiff, // "+" / "-"
  58. abs(ltzHour), // "hh"
  59. abs(ltzMinute)); // "mm"
  60. }
  61. };
  62. #endif //__CIMFUTIL_H_