]> git.saurik.com Git - wxWidgets.git/blame - include/wx/time.h
Applied patch for wxComboBox and wxListBox to
[wxWidgets.git] / include / wx / time.h
CommitLineData
cd0b1709
VZ
1///////////////////////////////////////////////////////////////////////////////
2// Name: wx/time.h
3// Purpose: wxTime class, from NIHCL: this class is deprecated, use
4// wxDateTime instead
c801d85f 5// Author: Julian Smart, after K. E. Gorlen
cd0b1709 6// Modified by: 18.12.99 by VZ to use the new wxDateTime class
c801d85f
KB
7// Created: 01/02/97
8// RCS-ID: $Id$
9// Copyright: (c) Julian Smart and Markus Holzem
e8b6d59d 10// Licence: wxWindows licence
cd0b1709 11///////////////////////////////////////////////////////////////////////////////
c801d85f 12
34138703
JS
13#ifndef _WX_TIMEH__
14#define _WX_TIMEH__
c801d85f 15
cd0b1709 16#include "wx/defs.h"
c801d85f 17
9838df2c 18#if wxUSE_TIMEDATE
c801d85f 19
cd0b1709
VZ
20#include "wx/object.h"
21#include "wx/datetime.h"
22#include "wx/date.h"
23
c801d85f 24#ifdef __GNUG__
cd0b1709 25 #pragma interface "time.h"
c801d85f
KB
26#endif
27
28class WXDLLEXPORT wxDate;
29
30typedef unsigned short hourTy;
31typedef unsigned short minuteTy;
32typedef unsigned short secondTy;
33typedef unsigned long clockTy;
34
cd0b1709
VZ
35// seconds from 1/1/01 to 1/1/70
36#define wxTIME_EPOCH_DIFF 2177452800UL
37
38class WXDLLEXPORT wxTime : public wxObject
c801d85f 39{
cd0b1709
VZ
40public:
41 // type definitions
e8b6d59d
JS
42 enum tFormat { wx12h, wx24h };
43 enum tPrecision { wxStdMinSec, wxStdMin };
cd0b1709
VZ
44
45public:
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)
479cd5de 75 { return wxTime(t.m_time + wxTimeSpan::Seconds((int)s)); }
cd0b1709 76 friend wxTime WXDLLEXPORT operator+(long s, const wxTime& t)
479cd5de 77 { return wxTime(t.m_time + wxTimeSpan::Seconds((int)s)); }
cd0b1709
VZ
78
79 long operator-(const wxTime& t) const
80 { return (m_time - t.m_time).GetValue().ToLong(); }
81 wxTime operator-(long s) const
479cd5de
VZ
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); }
cd0b1709
VZ
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
03e11df5
GD
126 wxStrncpy(ms_bufTime, m_time.Format(formats[ms_Format][ms_Precision]),
127 WXSIZEOF(ms_bufTime));
cd0b1709 128
03e11df5 129 return ms_bufTime;
cd0b1709
VZ
130 }
131
c801d85f 132private:
cd0b1709
VZ
133 static tFormat ms_Format;
134 static tPrecision ms_Precision;
03e11df5 135 static wxChar ms_bufTime[128];
c801d85f 136
cd0b1709 137#if 0 // old wxTime members unused any more
e8b6d59d 138 clockTy sec; /* seconds since 1/1/1901 */
c801d85f 139
e8b6d59d
JS
140 bool IsDST() const;
141 wxTime GetLocalTime() const;
cd0b1709
VZ
142
143 // static member functions
e8b6d59d
JS
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);
cd0b1709 147#endif // 0
e8b6d59d 148
cd0b1709 149 wxDateTime m_time;
ce3ed50d 150
cd0b1709 151 DECLARE_DYNAMIC_CLASS(wxTime)
c801d85f
KB
152};
153
154#endif
47d67540 155 // wxUSE_TIMEDATE
c801d85f 156#endif
34138703 157 // _WX_TIMEH__
c801d85f 158