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.

142 lines
4.2 KiB

  1. class CTimeSpan; // time/date difference
  2. class CTime; // absolute time/date
  3. /////////////////////////////////////////////////////////////////////////////
  4. // CTimeSpan and CTime
  5. //typedef long time_t;
  6. #include <time.h>
  7. class CTimeSpan
  8. {
  9. public:
  10. // Constructors
  11. CTimeSpan();
  12. CTimeSpan(time_t time);
  13. CTimeSpan(LONG lDays, int nHours, int nMins, int nSecs);
  14. CTimeSpan(const CTimeSpan& timeSpanSrc);
  15. const CTimeSpan& operator=(const CTimeSpan& timeSpanSrc);
  16. // Attributes
  17. // extract parts
  18. LONG GetDays() const; // total # of days
  19. LONG GetTotalHours() const;
  20. int GetHours() const;
  21. LONG GetTotalMinutes() const;
  22. int GetMinutes() const;
  23. time_t GetTotalSeconds() const;
  24. int GetSeconds() const;
  25. // Operations
  26. // time math
  27. CTimeSpan operator-(CTimeSpan timeSpan) const;
  28. CTimeSpan operator+(CTimeSpan timeSpan) const;
  29. const CTimeSpan& operator+=(CTimeSpan timeSpan);
  30. const CTimeSpan& operator-=(CTimeSpan timeSpan);
  31. BOOL operator==(CTimeSpan timeSpan) const;
  32. BOOL operator!=(CTimeSpan timeSpan) const;
  33. BOOL operator<(CTimeSpan timeSpan) const;
  34. BOOL operator>(CTimeSpan timeSpan) const;
  35. BOOL operator<=(CTimeSpan timeSpan) const;
  36. BOOL operator>=(CTimeSpan timeSpan) const;
  37. CString Format(LPCTSTR pFormat) const;
  38. #ifdef _ALL_CTIME_FORMATS_
  39. #ifdef _UNICODE
  40. // for compatibility with MFC 3.x
  41. CString Format(LPCSTR pFormat) const;
  42. #endif
  43. CString Format(LPCTSTR pFormat) const;
  44. CString Format(UINT nID) const;
  45. #endif //_ALL_CTIME_FORMATS_
  46. // serialization
  47. #ifdef _DEBUG
  48. friend CDumpContext& AFXAPI operator<<(CDumpContext& dc,CTimeSpan timeSpan);
  49. #endif
  50. friend CArchive& AFXAPI operator<<(CArchive& ar, CTimeSpan timeSpan);
  51. friend CArchive& AFXAPI operator>>(CArchive& ar, CTimeSpan& rtimeSpan);
  52. private:
  53. time_t m_timeSpan;
  54. friend class CTime;
  55. };
  56. class CTime
  57. {
  58. public:
  59. // Constructors
  60. static CTime PASCAL GetCurrentTime();
  61. CTime();
  62. CTime(time_t time);
  63. CTime(int nYear, int nMonth, int nDay, int nHour, int nMin, int nSec,
  64. int nDST = -1);
  65. CTime(WORD wDosDate, WORD wDosTime, int nDST = -1);
  66. CTime(const CTime& timeSrc);
  67. CTime(const SYSTEMTIME& sysTime, int nDST = -1);
  68. CTime(const FILETIME& fileTime, int nDST = -1);
  69. const CTime& operator=(const CTime& timeSrc);
  70. const CTime& operator=(time_t t);
  71. // Attributes
  72. struct tm* GetGmtTm(struct tm* ptm = NULL) const;
  73. struct tm* GetLocalTm(struct tm* ptm = NULL) const;
  74. time_t GetTime() const;
  75. int GetYear() const;
  76. int GetMonth() const; // month of year (1 = Jan)
  77. int GetDay() const; // day of month
  78. int GetHour() const;
  79. int GetMinute() const;
  80. int GetSecond() const;
  81. int GetDayOfWeek() const; // 1=Sun, 2=Mon, ..., 7=Sat
  82. // Operations
  83. // time math
  84. CTimeSpan operator-(CTime time) const;
  85. CTime operator-(CTimeSpan timeSpan) const;
  86. CTime operator+(CTimeSpan timeSpan) const;
  87. const CTime& operator+=(CTimeSpan timeSpan);
  88. const CTime& operator-=(CTimeSpan timeSpan);
  89. BOOL operator==(CTime time) const;
  90. BOOL operator!=(CTime time) const;
  91. BOOL operator<(CTime time) const;
  92. BOOL operator>(CTime time) const;
  93. BOOL operator<=(CTime time) const;
  94. BOOL operator>=(CTime time) const;
  95. CString Format(LPCTSTR pFormat) const;
  96. #ifdef _ALL_CTIME_FORMATS_
  97. // formatting using "C" strftime
  98. CString FormatGmt(LPCTSTR pFormat) const;
  99. CString Format(UINT nFormatID) const;
  100. CString FormatGmt(UINT nFormatID) const;
  101. #ifdef _UNICODE
  102. // for compatibility with MFC 3.x
  103. CString Format(LPCSTR pFormat) const;
  104. CString FormatGmt(LPCSTR pFormat) const;
  105. #endif
  106. #endif //_ALL_CTIME_FORMATS_
  107. // serialization
  108. #ifdef _DEBUG
  109. friend CDumpContext& AFXAPI operator<<(CDumpContext& dc, CTime time);
  110. #endif
  111. friend CArchive& AFXAPI operator<<(CArchive& ar, CTime time);
  112. friend CArchive& AFXAPI operator>>(CArchive& ar, CTime& rtime);
  113. private:
  114. time_t m_time;
  115. };
  116. #include "ctime.inl"