]> git.saurik.com Git - wxWidgets.git/blob - include/wx/time.h
applied wxDirSelector() patch and regenerated the makefiles to include the new src...
[wxWidgets.git] / include / wx / time.h
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: wx/time.h
3 // Purpose: wxTime class, from NIHCL: this class is deprecated, use
4 // wxDateTime instead
5 // Author: Julian Smart, after K. E. Gorlen
6 // Modified by: 18.12.99 by VZ to use the new wxDateTime class
7 // Created: 01/02/97
8 // RCS-ID: $Id$
9 // Copyright: (c) Julian Smart and Markus Holzem
10 // Licence: wxWindows licence
11 ///////////////////////////////////////////////////////////////////////////////
12
13 #ifndef _WX_TIMEH__
14 #define _WX_TIMEH__
15
16 #include "wx/defs.h"
17
18 #if wxUSE_TIMEDATE
19
20 #include "wx/object.h"
21 #include "wx/datetime.h"
22 #include "wx/date.h"
23
24 #ifdef __GNUG__
25 #pragma interface "time.h"
26 #endif
27
28 class WXDLLEXPORT wxDate;
29
30 typedef unsigned short hourTy;
31 typedef unsigned short minuteTy;
32 typedef unsigned short secondTy;
33 typedef unsigned long clockTy;
34
35 // seconds from 1/1/01 to 1/1/70
36 #define wxTIME_EPOCH_DIFF 2177452800UL
37
38 class WXDLLEXPORT wxTime : public wxObject
39 {
40 public:
41 // type definitions
42 enum tFormat { wx12h, wx24h };
43 enum tPrecision { wxStdMinSec, wxStdMin };
44
45 public:
46 // current time
47 wxTime() : m_time(wxDateTime::Now()) { }
48 wxTime(clockTy s) : m_time((time_t)(s - wxTIME_EPOCH_DIFF)) { }
49 void operator=(const wxTime& t) { m_time = t.m_time; }
50 wxTime(const wxTime& t) { *this = t; }
51 wxTime(hourTy h, minuteTy m, secondTy s = 0, bool WXUNUSED(dst) = FALSE)
52 : m_time(h, m, s) { }
53
54 wxTime(const wxDate& d, hourTy h = 0, minuteTy m = 0, secondTy s = 0,
55 bool WXUNUSED(dst) = FALSE)
56 : m_time(d.GetDay(), (wxDateTime::Month)d.GetMonth(), d.GetYear(),
57 h, m, s) { }
58
59 wxTime(const wxDateTime& time) : m_time(time) { }
60
61 // Convert to string
62 #ifndef __SALFORDC__
63 operator wxChar *() const { return FormatTime(); }
64 operator wxDate() const { return wxDate(m_time); }
65 #endif
66
67 bool operator< (const wxTime& t) const { return m_time < t.m_time; }
68 bool operator<=(const wxTime& t) const { return m_time <= t.m_time; }
69 bool operator> (const wxTime& t) const { return m_time > t.m_time; }
70 bool operator>=(const wxTime& t) const { return m_time >= t.m_time; }
71 bool operator==(const wxTime& t) const { return m_time == t.m_time; }
72 bool operator!=(const wxTime& t) const { return m_time != t.m_time; }
73
74 friend wxTime WXDLLEXPORT operator+(const wxTime& t, long s)
75 { return wxTime(t.m_time + wxTimeSpan::Seconds((int)s)); }
76 friend wxTime WXDLLEXPORT operator+(long s, const wxTime& t)
77 { return wxTime(t.m_time + wxTimeSpan::Seconds((int)s)); }
78
79 long operator-(const wxTime& t) const
80 { return (m_time - t.m_time).GetValue().ToLong(); }
81 wxTime operator-(long s) const
82 { return wxTime(m_time - wxTimeSpan::Seconds((int)s)); }
83 void operator+=(long s) { m_time += wxTimeSpan::Seconds((int)s); }
84 void operator-=(long s) { m_time -= wxTimeSpan::Seconds((int)s); }
85 bool IsBetween(const wxTime& a, const wxTime& b) const
86 { return *this >= a && *this <= b; }
87
88 // Get day
89 int GetDay() const { return m_time.GetDay(); }
90 // Get month
91 int GetMonth() const { return m_time.GetMonth(); }
92 // Get year
93 int GetYear() const { return m_time.GetYear(); }
94 // Get day of week (0=Sunday 6=Saturday)
95 int GetDayOfWeek() const { return m_time.GetWeekDay(); }
96
97 hourTy GetHour() const { return (hourTy)m_time.GetHour(); }
98 hourTy GetHourGMT() const { return (hourTy)m_time.GetHour(wxDateTime::GMT0); }
99 minuteTy GetMinute() const { return (hourTy)m_time.GetMinute(); }
100 minuteTy GetMinuteGMT() const { return (hourTy)m_time.GetMinute(wxDateTime::GMT0); }
101 secondTy GetSecond() const { return (hourTy)m_time.GetSecond(); }
102 secondTy GetSecondGMT() const { return (hourTy)m_time.GetSecond(wxDateTime::GMT0); }
103
104 clockTy GetSeconds() const { return (clockTy)m_time.GetValue().ToLong(); }
105
106 wxTime Max(const wxTime& t) const { return (t < *this) ? *this : t; }
107 wxTime Min(const wxTime& t) const { return (t > *this) ? *this : t; }
108
109 static void SetFormat(const tFormat lFormat = wx12h,
110 const tPrecision lPrecision = wxStdMinSec)
111 {
112 ms_Format = lFormat;
113 ms_Precision = lPrecision;
114 }
115
116 // (VZ: DANGER: returns pointer to static buffer)
117 wxChar *FormatTime() const
118 {
119 static const wxChar *formats[2][2] =
120 {
121 // wxStdMinSec wxStdMin
122 { _T("%I:%M:%S %p"), _T("%I:%M %p") }, // wx12h
123 { _T("%H:%M:%S"), _T("%H:%M") } // wx24h
124 };
125
126 wxStrncpy(ms_bufTime, m_time.Format(formats[ms_Format][ms_Precision]),
127 WXSIZEOF(ms_bufTime));
128
129 return ms_bufTime;
130 }
131
132 private:
133 static tFormat ms_Format;
134 static tPrecision ms_Precision;
135 static wxChar ms_bufTime[128];
136
137 #if 0 // old wxTime members unused any more
138 clockTy sec; /* seconds since 1/1/1901 */
139
140 bool IsDST() const;
141 wxTime GetLocalTime() const;
142
143 // static member functions
144 static wxTime GetLocalTime(const wxDate& date, hourTy h=0, minuteTy m=0, secondTy s=0);
145 static wxTime GetBeginDST(unsigned year);
146 static wxTime GetEndDST(unsigned year);
147 #endif // 0
148
149 wxDateTime m_time;
150
151 DECLARE_DYNAMIC_CLASS(wxTime)
152 };
153
154 #endif
155 // wxUSE_TIMEDATE
156 #endif
157 // _WX_TIMEH__
158