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.

160 lines
4.6 KiB

  1. /**********************************************************************/
  2. /** Microsoft Windows/NT **/
  3. /** Copyright(c) Microsoft Corporation, 1995 - 1999 **/
  4. /**********************************************************************/
  5. /*
  6. FILE HISTORY:
  7. */
  8. #ifndef _INTLTIME_H_
  9. #define _INTLTIME_H_
  10. //
  11. // Utility functions
  12. //
  13. void FormatDateTime(CString & strOutput, SYSTEMTIME * psystemtime, BOOL fLongDate = FALSE);
  14. void FormatDateTime(CString & strOutput, FILETIME * pfiletime, BOOL fLongDate = FALSE);
  15. void FormatDateTime(CString & strOutput, CTime & time, BOOL fLongDate = FALSE);
  16. //
  17. // CIntlTime class definition
  18. //
  19. class CIntlTime : public CTime
  20. {
  21. //
  22. // Attributes
  23. //
  24. public:
  25. enum _TIME_FORMAT_REQUESTS
  26. {
  27. TFRQ_TIME_ONLY,
  28. TFRQ_DATE_ONLY,
  29. TFRQ_TIME_AND_DATE,
  30. TFRQ_TIME_OR_DATE,
  31. TFRQ_MILITARY_TIME,
  32. };
  33. public:
  34. // Same contructors as CTime
  35. CIntlTime();
  36. CIntlTime(const CTime &timeSrc);
  37. CIntlTime(time_t time);
  38. CIntlTime(int nYear, int nMonth, int nDay, int nHour, int nMin, int nSec);
  39. CIntlTime(WORD wDosDate, WORD wDosTime);
  40. #ifdef _WIN32
  41. CIntlTime(const SYSTEMTIME& sysTime);
  42. CIntlTime(const FILETIME& fileTime);
  43. #endif // _WIN32
  44. // New for CIntlTime
  45. CIntlTime(const CIntlTime &timeSrc);
  46. CIntlTime(const CString &strTime, int nFormat = TFRQ_TIME_OR_DATE, time_t * ptmOldValue = NULL);
  47. public:
  48. virtual ~CIntlTime();
  49. // Operations
  50. public:
  51. // Assignment operators
  52. const CIntlTime& operator=(time_t tmValue);
  53. const CIntlTime& operator=(const CString& strValue);
  54. const CIntlTime& operator=(const CTime & time);
  55. const CIntlTime& operator=(const CIntlTime & time);
  56. // Conversion operators
  57. operator const time_t() const;
  58. operator CString() const;
  59. operator const CString() const;
  60. const CString IntlFormat(int nFormat) const
  61. {
  62. return(ConvertToString(nFormat));
  63. }
  64. // Validation checks
  65. BOOL IsValid() const
  66. {
  67. return(m_fInitOk);
  68. }
  69. static BOOL IsIntlValid()
  70. {
  71. return(CIntlTime::m_fIntlOk);
  72. }
  73. public:
  74. // ... Input and output
  75. #ifdef _DEBUG
  76. friend CDumpContext& AFXAPI operator<<(CDumpContext& dc, const CIntlTime& tim);
  77. #endif // _DEBUG
  78. friend CArchive& AFXAPI operator <<(CArchive& ar, const CIntlTime& tim);
  79. friend CArchive& AFXAPI operator >>(CArchive& ar, CIntlTime& tim);
  80. // Implementation
  81. public:
  82. static void Reset();
  83. static void SetBadDateAndTime(CString strBadDate = "--", CString strBadTime = "--")
  84. {
  85. m_strBadDate = strBadDate;
  86. m_strBadTime = strBadTime;
  87. }
  88. static CString& GetBadDate()
  89. {
  90. return(m_strBadDate);
  91. }
  92. static CString& GetBadTime()
  93. {
  94. return(m_strBadTime);
  95. }
  96. static time_t ConvertFromString (const CString & str, int nFormat, time_t * ptmOldValue, BOOL * pfOk);
  97. static BOOL IsLeapYear(UINT nYear); // Complete year value
  98. static BOOL IsValidDate(UINT nMonth, UINT nDay, UINT nYear);
  99. static BOOL IsValidTime(UINT nHour, UINT nMinute, UINT nSecond);
  100. private:
  101. enum _DATE_FORMATS
  102. {
  103. _DFMT_MDY, // Day, month, year
  104. _DFMT_DMY, // Month, day, year
  105. _DFMT_YMD, // Year, month, day
  106. };
  107. typedef struct _INTL_TIME_SETTINGS
  108. {
  109. CString strDateSeperator; // String used between date fields
  110. CString strTimeSeperator; // String used between time fields.
  111. CString strAM; // Suffix string used for 12 hour clock AM times
  112. CString strPM; // Suffix string used for 12 hour clock PM times
  113. int nDateFormat; // see _DATE_FORMATS enum above.
  114. BOOL f24HourClock; // TRUE = 24 hours, FALSE is AM/PM
  115. BOOL fCentury; // If TRUE, uses 4 digits for the century
  116. BOOL fLeadingTimeZero; // If TRUE, uses leading 0 in time format
  117. BOOL fLeadingDayZero; // If TRUE, uses leading 0 in day
  118. BOOL fLeadingMonthZero; // If TRUE, uses leading 0 in month
  119. } INTL_TIME_SETTINGS;
  120. static INTL_TIME_SETTINGS m_itsInternationalSettings;
  121. static CString m_strBadTime;
  122. static CString m_strBadDate;
  123. private:
  124. static BOOL SetIntlTimeSettings();
  125. static BOOL m_fIntlOk;
  126. private:
  127. const CString GetDateString() const;
  128. const CString GetTimeString() const;
  129. const CString GetMilitaryTime() const;
  130. const CString ConvertToString(int nFormat) const;
  131. private:
  132. BOOL m_fInitOk;
  133. };
  134. #endif _INTLTIME_H