]>
git.saurik.com Git - wxWidgets.git/blob - include/wx/time.h
1 ///////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxTime class, from NIHCL: this class is deprecated, use
5 // Author: Julian Smart, after K. E. Gorlen
6 // Modified by: 18.12.99 by VZ to use the new wxDateTime class
9 // Copyright: (c) Julian Smart
10 // Licence: wxWindows licence
11 ///////////////////////////////////////////////////////////////////////////////
20 #include "wx/object.h"
21 #include "wx/datetime.h"
24 #if defined(__GNUG__) && !defined(__APPLE__)
25 #pragma interface "time.h"
28 class WXDLLEXPORT wxDate
;
30 typedef unsigned short hourTy
;
31 typedef unsigned short minuteTy
;
32 typedef unsigned short secondTy
;
33 typedef unsigned long clockTy
;
35 // seconds from 1/1/01 to 1/1/70
36 #define wxTIME_EPOCH_DIFF 2177452800UL
38 class WXDLLEXPORT wxTime
: public wxObject
42 enum tFormat
{ wx12h
, wx24h
};
43 enum tPrecision
{ wxStdMinSec
, wxStdMin
};
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
) : wxObject() { *this = t
; }
51 wxTime(hourTy h
, minuteTy m
, secondTy s
= 0, bool WXUNUSED(dst
) = FALSE
)
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(),
59 wxTime(const wxDateTime
& time
) : m_time(time
) { }
63 operator wxChar
*() const { return FormatTime(); }
64 operator wxDate() const { return wxDate(m_time
); }
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
; }
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
)); }
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
; }
89 int GetDay() const { return m_time
.GetDay(); }
91 int GetMonth() const { return m_time
.GetMonth(); }
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(); }
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
); }
104 clockTy
GetSeconds() const { return (clockTy
)m_time
.GetValue().ToLong(); }
106 wxTime
Max(const wxTime
& t
) const { return (t
< *this) ? *this : t
; }
107 wxTime
Min(const wxTime
& t
) const { return (t
> *this) ? *this : t
; }
109 static void SetFormat(const tFormat lFormat
= wx12h
,
110 const tPrecision lPrecision
= wxStdMinSec
)
113 ms_Precision
= lPrecision
;
116 // (VZ: DANGER: returns pointer to static buffer)
117 wxChar
*FormatTime() const
119 static const wxChar
*formats
[2][2] =
121 // wxStdMinSec wxStdMin
122 { _T("%I:%M:%S %p"), _T("%I:%M %p") }, // wx12h
123 { _T("%H:%M:%S"), _T("%H:%M") } // wx24h
126 wxStrncpy(ms_bufTime
, m_time
.Format(formats
[ms_Format
][ms_Precision
]),
127 WXSIZEOF(ms_bufTime
));
133 static tFormat ms_Format
;
134 static tPrecision ms_Precision
;
135 static wxChar ms_bufTime
[128];
137 #if 0 // old wxTime members unused any more
138 clockTy sec
; /* seconds since 1/1/1901 */
141 wxTime
GetLocalTime() const;
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
);
151 DECLARE_DYNAMIC_CLASS(wxTime
)