+
+public:
+ // current time
+ wxTime() : m_time(wxDateTime::Now()) { }
+ wxTime(clockTy s) : m_time((time_t)(s - wxTIME_EPOCH_DIFF)) { }
+ void operator=(const wxTime& t) { m_time = t.m_time; }
+ wxTime(const wxTime& t) { *this = t; }
+ wxTime(hourTy h, minuteTy m, secondTy s = 0, bool WXUNUSED(dst) = FALSE)
+ : m_time(h, m, s) { }
+
+ wxTime(const wxDate& d, hourTy h = 0, minuteTy m = 0, secondTy s = 0,
+ bool WXUNUSED(dst) = FALSE)
+ : m_time(d.GetDay(), (wxDateTime::Month)d.GetMonth(), d.GetYear(),
+ h, m, s) { }
+
+ wxTime(const wxDateTime& time) : m_time(time) { }
+
+ // Convert to string
+#ifndef __SALFORDC__
+ operator wxChar *() const { return FormatTime(); }
+ operator wxDate() const { return wxDate(m_time); }
+#endif
+
+ bool operator< (const wxTime& t) const { return m_time < t.m_time; }
+ bool operator<=(const wxTime& t) const { return m_time <= t.m_time; }
+ bool operator> (const wxTime& t) const { return m_time > t.m_time; }
+ bool operator>=(const wxTime& t) const { return m_time >= t.m_time; }
+ bool operator==(const wxTime& t) const { return m_time == t.m_time; }
+ bool operator!=(const wxTime& t) const { return m_time != t.m_time; }
+
+ friend wxTime WXDLLEXPORT operator+(const wxTime& t, long s)
+ { return wxTime(t.m_time + wxTimeSpan::Seconds((int)s)); }
+ friend wxTime WXDLLEXPORT operator+(long s, const wxTime& t)
+ { return wxTime(t.m_time + wxTimeSpan::Seconds((int)s)); }
+
+ long operator-(const wxTime& t) const
+ { return (m_time - t.m_time).GetValue().ToLong(); }
+ wxTime operator-(long s) const
+ { return wxTime(m_time - wxTimeSpan::Seconds((int)s)); }
+ void operator+=(long s) { m_time += wxTimeSpan::Seconds((int)s); }
+ void operator-=(long s) { m_time -= wxTimeSpan::Seconds((int)s); }
+ bool IsBetween(const wxTime& a, const wxTime& b) const
+ { return *this >= a && *this <= b; }
+
+ // Get day
+ int GetDay() const { return m_time.GetDay(); }
+ // Get month
+ int GetMonth() const { return m_time.GetMonth(); }
+ // Get year
+ int GetYear() const { return m_time.GetYear(); }
+ // Get day of week (0=Sunday 6=Saturday)
+ int GetDayOfWeek() const { return m_time.GetWeekDay(); }
+
+ hourTy GetHour() const { return (hourTy)m_time.GetHour(); }
+ hourTy GetHourGMT() const { return (hourTy)m_time.GetHour(wxDateTime::GMT0); }
+ minuteTy GetMinute() const { return (hourTy)m_time.GetMinute(); }
+ minuteTy GetMinuteGMT() const { return (hourTy)m_time.GetMinute(wxDateTime::GMT0); }
+ secondTy GetSecond() const { return (hourTy)m_time.GetSecond(); }
+ secondTy GetSecondGMT() const { return (hourTy)m_time.GetSecond(wxDateTime::GMT0); }
+
+ clockTy GetSeconds() const { return (clockTy)m_time.GetValue().ToLong(); }
+
+ wxTime Max(const wxTime& t) const { return (t < *this) ? *this : t; }
+ wxTime Min(const wxTime& t) const { return (t > *this) ? *this : t; }
+
+ static void SetFormat(const tFormat lFormat = wx12h,
+ const tPrecision lPrecision = wxStdMinSec)
+ {
+ ms_Format = lFormat;
+ ms_Precision = lPrecision;
+ }
+
+ // (VZ: DANGER: returns pointer to static buffer)
+ wxChar *FormatTime() const
+ {
+ static const wxChar *formats[2][2] =
+ {
+ // wxStdMinSec wxStdMin
+ { _T("%I:%M:%S %p"), _T("%I:%M %p") }, // wx12h
+ { _T("%H:%M:%S"), _T("%H:%M") } // wx24h
+ };
+
+ wxStrncpy(ms_bufTime, m_time.Format(formats[ms_Format][ms_Precision]),
+ WXSIZEOF(ms_bufTime));
+
+ return ms_bufTime;
+ }
+