1 ///////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxDate class: this class is deprecated, use wxDateTime instead!
4 // Author: Julian Smart, Steve Marcus, Eric Simon, Chris Hill,
6 // Modified by: 18.12.99 by VZ to use the new wxDateTime class
9 // Copyright: Julian Smart, Steve Marcus, Eric Simon, Chris Hill,
11 // Licence: wxWindows licence
12 ///////////////////////////////////////////////////////////////////////////////
17 #if defined(__GNUG__) && !defined(__APPLE__)
18 #pragma interface "date.h"
25 #include "wx/object.h"
26 #include "wx/string.h"
27 #include "wx/datetime.h"
29 // ----------------------------------------------------------------------------
31 // ----------------------------------------------------------------------------
33 enum wxdate_format_type
42 enum // wxdate_format_flags
48 // ----------------------------------------------------------------------------
50 // ----------------------------------------------------------------------------
52 class WXDLLEXPORT wxDate
: public wxObject
56 wxDate(long j
) : m_date((double)(j
+ 0.5)) { Init(); }
57 wxDate(int m
, int d
, int y
) : m_date(d
, (wxDateTime::Month
)m
, y
) { Init(); }
58 wxDate(const wxString
& dat
) { Init(); (void)m_date
.ParseDate(dat
); }
59 wxDate(const wxDate
&date
) : wxObject() { *this = date
; }
61 wxDate(const wxDateTime
& dt
) { Init(); m_date
= dt
; }
64 operator wxString() const { return FormatDate(); }
67 void operator=(const wxDate
& date
)
70 m_displayFormat
= date
.m_displayFormat
;
71 m_displayOptions
= date
.m_displayOptions
;
74 void operator=(const wxString
& dat
) { (void)m_date
.ParseDate(dat
); }
76 wxDate
operator+(long i
) { return wxDate(GetJulianDate() + i
); }
77 wxDate
operator+(int i
) { return wxDate(GetJulianDate() + (long)i
); }
79 wxDate
operator-(long i
) { return wxDate(GetJulianDate() - i
); }
80 wxDate
operator-(int i
) { return wxDate(GetJulianDate() - (long)i
); }
82 long operator-(const wxDate
&dt
) const
83 { return GetJulianDate() - dt
.GetJulianDate(); }
85 wxDate
&operator+=(long i
) { m_date
+= wxTimeSpan::Days((int)i
); return *this; }
86 wxDate
&operator-=(long i
) { m_date
-= wxTimeSpan::Days((int)i
); return *this; }
88 wxDate
&operator++() { return *this += 1; }
89 wxDate
&operator++(int) { return *this += 1; }
90 wxDate
&operator--() { return *this -= 1; }
91 wxDate
&operator--(int) { return *this -= 1; }
93 #if wxUSE_STD_IOSTREAM
94 friend wxSTD ostream WXDLLEXPORT
& operator <<(wxSTD ostream
&os
, const wxDate
&dt
)
95 { return os
<< dt
.FormatDate().mb_str(); }
98 void SetFormat(int format
) { m_displayFormat
= format
; }
99 int SetOption(int option
, bool enable
= TRUE
)
102 m_displayOptions
|= option
;
104 m_displayOptions
&= ~option
;
106 return 1; // (VZ: whatever it means)
109 // returns julian date (VZ: the integral part of Julian Day Number)
110 long GetJulianDate() const
111 { return (long)(m_date
.GetJulianDayNumber() - 0.5); }
113 // returns relative date since Jan. 1
114 int GetDayOfYear() const
115 { return m_date
.GetDayOfYear(); }
117 // returns TRUE if leap year, FALSE if not
118 bool IsLeapYear() const
119 { return wxDateTime::IsLeapYear(m_date
.GetYear()); }
121 // Sets to current system date
123 { m_date
= wxDateTime::Today(); return (wxDate
&)*this; }
124 wxDate
&Set(long lJulian
)
125 { m_date
.Set((double)(lJulian
+ 0.5)); return (wxDate
&)*this; }
126 wxDate
&Set(int nMonth
, int nDay
, int nYear
)
127 { m_date
.Set(nDay
, (wxDateTime::Month
)nMonth
, nYear
); return *this; }
129 // May also pass neg# to decrement
130 wxDate
&AddWeeks(int nCount
= 1)
131 { m_date
+= wxDateSpan::Weeks(nCount
); return *this; }
132 wxDate
&AddMonths(int nCount
= 1)
133 { m_date
+= wxDateSpan::Months(nCount
); return *this; }
134 wxDate
&AddYears(int nCount
= 1)
135 { m_date
+= wxDateSpan::Years(nCount
); return *this; }
137 // Numeric Day of date object
138 int GetDay() const { return m_date
.GetDay(); }
139 // Number of days in month(1..31)
140 int GetDaysInMonth() const
142 return wxDateTime::GetNumberOfDays((wxDateTime::Month
)m_date
.GetMonth(),
146 // First Day Of Month(1..7)
147 int GetFirstDayOfMonth() const
148 { return wxDate(GetMonth(), 1, GetYear()).GetDayOfWeek(); }
150 // Character Day Of Week('Sunday'..'Saturday')
151 wxString
GetDayOfWeekName() const { return FormatDate(wxDAY
); }
152 int GetDayOfWeek() const { return (int)m_date
.GetWeekDay() + 1; }
154 // Numeric Week Of Month(1..6) (VZ: I'd love to see a month with 6 weeks)
155 int GetWeekOfMonth() const { return m_date
.GetWeekOfMonth(); }
156 // Numeric Week Of Year(1..52) (VZ: but there are years with 53 weeks)
157 int GetWeekOfYear() const { return m_date
.GetWeekOfYear(); }
159 // Character Month name
160 wxString
GetMonthName() { return FormatDate(wxMONTH
); }
161 // Month Number(1..12)
162 int GetMonth() const { return m_date
.GetMonth() + 1; }
164 // First Date Of Month
165 wxDate
GetMonthStart() const { return(wxDate(GetMonth()-1, 1, GetYear())); }
166 // Last Date Of Month
167 wxDate
GetMonthEnd() const { return wxDate(GetMonth(), 1, GetYear())-1; }
170 int GetYear() const { return m_date
.GetYear(); }
171 // First Date Of Year
172 wxDate
GetYearStart() const { return wxDate(0, 1, GetYear()); }
174 wxDate
GetYearEnd() const { return wxDate(0, 1, GetYear()+1) - 1; }
176 bool IsBetween(const wxDate
& first
, const wxDate
& second
) const
178 return m_date
.IsBetween(first
.m_date
, second
.m_date
);
181 wxDate
Previous(int dayOfWeek
) const
184 int dow
= GetDayOfWeek();
185 prev
-= dayOfWeek
> dow
? 7 - (dayOfWeek
- dow
) : dow
- dayOfWeek
;
190 wxString
FormatDate(int type
= -1) const
192 static const wxChar
*formats
[] =
194 // MDY (week)DAY MONTH FULL EUROPEAN
195 _T("%m/%d/%Y"), _T("%A"), _T("%B"), _T("%A, %B %d, %Y"), _T("%d %B %Y")
198 wxString fmt
= formats
[type
== -1 ? m_displayFormat
: type
];
200 if ( m_displayOptions
& wxDATE_ABBR
)
202 fmt
.Replace(_T("A"), _T("a"));
203 fmt
.Replace(_T("B"), _T("b"));
205 if ( m_displayOptions
& wxNO_CENTURY
)
207 fmt
.Replace(_T("Y"), _T("y"));
210 return m_date
.Format(fmt
);
214 void Init() { m_displayFormat
= wxMDY
; m_displayOptions
= 0; }
216 #if 0 // the old wxDate members - unused any more
217 unsigned long julian
; // see julDate(); days since 1/1/4713 B.C.
218 int month
; // see NMonth()
219 int day
; // see Day()
220 int year
; // see NYear4()
221 int day_of_week
; // see NDOW(); 1 = Sunday, ... 7 = Saturday
223 void julian_to_mdy(); // convert julian day to mdy
224 void julian_to_wday(); // convert julian day to day_of_week
225 void mdy_to_julian(); // convert mdy to julian day
232 int m_displayOptions
;
235 DECLARE_DYNAMIC_CLASS(wxDate
)
238 // ----------------------------------------------------------------------------
240 // ----------------------------------------------------------------------------
242 inline bool WXDLLEXPORT
operator <(const wxDate
&dt1
, const wxDate
&dt2
)
243 { return dt1
.GetJulianDate() < dt2
.GetJulianDate(); }
244 inline bool WXDLLEXPORT
operator <=(const wxDate
&dt1
, const wxDate
&dt2
)
245 { return dt1
.GetJulianDate() <= dt2
.GetJulianDate(); }
246 inline bool WXDLLEXPORT
operator >(const wxDate
&dt1
, const wxDate
&dt2
)
247 { return dt1
.GetJulianDate() > dt2
.GetJulianDate(); }
248 inline bool WXDLLEXPORT
operator >=(const wxDate
&dt1
, const wxDate
&dt2
)
249 { return dt1
.GetJulianDate() >= dt2
.GetJulianDate(); }
250 inline bool WXDLLEXPORT
operator ==(const wxDate
&dt1
, const wxDate
&dt2
)
251 { return dt1
.GetJulianDate() == dt2
.GetJulianDate(); }
252 inline bool WXDLLEXPORT
operator !=(const wxDate
&dt1
, const wxDate
&dt2
)
253 { return dt1
.GetJulianDate() != dt2
.GetJulianDate(); }
255 #endif // wxUSE_TIMEDATE