]>
git.saurik.com Git - wxWidgets.git/blob - include/wx/date.h
   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 
  10 // Licence:     wxWindows licence 
  11 /////////////////////////////////////////////////////////////////////////////// 
  17     #pragma interface "date.h" 
  24 #include "wx/object.h" 
  25 #include "wx/string.h" 
  26 #include "wx/datetime.h" 
  28 // ---------------------------------------------------------------------------- 
  30 // ---------------------------------------------------------------------------- 
  32 enum wxdate_format_type
 
  41 enum // wxdate_format_flags 
  47 // ---------------------------------------------------------------------------- 
  49 // ---------------------------------------------------------------------------- 
  51 class WXDLLEXPORT wxDate 
: public wxObject
 
  55     wxDate(long j
) : m_date((double)(j 
+ 0.5)) { Init(); } 
  56     wxDate(int m
, int d
, int y
) : m_date(d
, (wxDateTime::Month
)m
, y
) { Init(); } 
  57     wxDate(const wxString
& dat
) { Init(); (void)m_date
.ParseDate(dat
); } 
  58     wxDate(const wxDate 
&date
) { *this = date
; } 
  60     wxDate(const wxDateTime
& dt
) { Init(); m_date 
= dt
; } 
  63     operator wxString() const { return FormatDate(); } 
  66     void operator=(const wxDate
& date
) 
  69         m_displayFormat 
= date
.m_displayFormat
; 
  70         m_displayOptions 
= date
.m_displayOptions
; 
  73     void operator=(const wxString
& dat
) { (void)m_date
.ParseDate(dat
); } 
  75     wxDate 
operator+(long i
) { return wxDate(GetJulianDate() + i
); } 
  76     wxDate 
operator+(int  i
) { return wxDate(GetJulianDate() + (long)i
); } 
  78     wxDate 
operator-(long i
) { return wxDate(GetJulianDate() - i
); } 
  79     wxDate 
operator-(int  i
) { return wxDate(GetJulianDate() - (long)i
); } 
  81     long operator-(const wxDate 
&dt
) const 
  82         { return GetJulianDate() - dt
.GetJulianDate(); } 
  84     wxDate 
&operator+=(long i
) { m_date 
+= wxTimeSpan::Days((int)i
); return *this; } 
  85     wxDate 
&operator-=(long i
) { m_date 
-= wxTimeSpan::Days((int)i
); return *this; } 
  87     wxDate 
&operator++() { return *this += 1; } 
  88     wxDate 
&operator++(int) { return *this += 1; } 
  89     wxDate 
&operator--() { return *this -= 1; } 
  90     wxDate 
&operator--(int) { return *this -= 1; } 
  92 #if wxUSE_STD_IOSTREAM 
  93     friend ostream WXDLLEXPORT 
& operator <<(ostream 
&os
, const wxDate 
&dt
) 
  94         { return os 
<< dt
.FormatDate().mb_str(); } 
  97     void  SetFormat(int format
) { m_displayFormat 
= format
; } 
  98     int   SetOption(int option
, bool enable 
= TRUE
) 
 101             m_displayOptions 
|= option
; 
 103             m_displayOptions 
&= ~option
; 
 105         return 1; // (VZ: whatever it means) 
 108     // returns julian date (VZ: the integral part of Julian Day Number) 
 109     long GetJulianDate() const 
 110         { return (long)(m_date
.GetJulianDayNumber() - 0.5); } 
 112     // returns relative date since Jan. 1 
 113     int GetDayOfYear() const 
 114         { return m_date
.GetDayOfYear(); } 
 116     // returns TRUE if leap year, FALSE if not 
 117     bool IsLeapYear() const 
 118         { return wxDateTime::IsLeapYear(m_date
.GetYear()); } 
 120     // Sets to current system date 
 122         { m_date 
= wxDateTime::Today(); return (wxDate
&)*this; } 
 123     wxDate 
&Set(long lJulian
) 
 124         { m_date
.Set((double)(lJulian 
+ 0.5)); return (wxDate
&)*this; } 
 125     wxDate 
&Set(int nMonth
, int nDay
, int nYear
) 
 126         { m_date
.Set(nDay
, (wxDateTime::Month
)nMonth
, nYear
); return *this; } 
 128     // May also pass neg# to decrement 
 129     wxDate 
&AddWeeks(int nCount 
= 1) 
 130         { m_date 
+= wxDateSpan::Weeks(nCount
); return *this; } 
 131     wxDate 
&AddMonths(int nCount 
= 1) 
 132         { m_date 
+= wxDateSpan::Months(nCount
); return *this; } 
 133     wxDate 
&AddYears(int nCount 
= 1) 
 134         { m_date 
+= wxDateSpan::Years(nCount
); return *this; } 
 136     // Numeric Day of date object 
 137     int GetDay() const { return m_date
.GetDay(); } 
 138     // Number of days in month(1..31) 
 139     int GetDaysInMonth() const 
 141         return wxDateTime::GetNumberOfDays((wxDateTime::Month
)m_date
.GetMonth(), 
 145     // First Day Of Month(1..7) 
 146     int GetFirstDayOfMonth() const 
 147         { return wxDate(GetMonth(), 1, GetYear()).GetDayOfWeek(); } 
 149     // Character Day Of Week('Sunday'..'Saturday') 
 150     wxString 
GetDayOfWeekName() const { return FormatDate(wxDAY
); } 
 151     int GetDayOfWeek() const { return (int)m_date
.GetWeekDay() + 1; } 
 153     // Numeric Week Of Month(1..6) (VZ: I'd love to see a month with 6 weeks) 
 154     int GetWeekOfMonth() const { return m_date
.GetWeekOfMonth(); } 
 155     // Numeric Week Of Year(1..52) (VZ: but there are years with 53 weeks) 
 156     int GetWeekOfYear() const { return m_date
.GetWeekOfYear(); } 
 158     // Character Month name 
 159     wxString 
GetMonthName() { return FormatDate(wxMONTH
); } 
 160     // Month Number(1..12) 
 161     int GetMonth() const { return m_date
.GetMonth() + 1; } 
 163     // First Date Of Month 
 164     wxDate 
GetMonthStart() const { return(wxDate(GetMonth()-1, 1, GetYear())); } 
 165     // Last Date Of Month 
 166     wxDate 
GetMonthEnd() const { return wxDate(GetMonth(), 1, GetYear())-1; } 
 169     int GetYear() const { return m_date
.GetYear(); } 
 170     // First Date Of Year 
 171     wxDate 
GetYearStart() const { return wxDate(0, 1, GetYear()); } 
 173     wxDate 
GetYearEnd() const { return wxDate(0, 1, GetYear()+1) - 1; } 
 175     bool IsBetween(const wxDate
& first
, const wxDate
& second
) const 
 177         return m_date
.IsBetween(first
.m_date
, second
.m_date
); 
 180     wxDate 
Previous(int dayOfWeek
) const 
 183         int dow 
= GetDayOfWeek(); 
 184         prev 
-= dayOfWeek 
> dow 
? 7 - (dayOfWeek 
- dow
) : dow 
- dayOfWeek
; 
 189     wxString 
FormatDate(int type 
= -1) const 
 191         static const wxChar 
*formats
[] = 
 193             // MDY          (week)DAY   MONTH   FULL                 EUROPEAN 
 194             _T("%m/%d/%Y"), _T("%A"), _T("%B"), _T("%A, %B %d, %Y"), _T("%d %B %Y") 
 197         wxString fmt 
= formats
[type 
== -1 ? m_displayFormat 
: type
]; 
 199         if ( m_displayOptions 
& wxDATE_ABBR 
) 
 201             fmt
.Replace(_T("A"), _T("a")); 
 202             fmt
.Replace(_T("B"), _T("b")); 
 204         if ( m_displayOptions 
& wxNO_CENTURY 
) 
 206             fmt
.Replace(_T("Y"), _T("y")); 
 209         return m_date
.Format(fmt
); 
 213     void Init() { m_displayFormat 
= wxMDY
; m_displayOptions 
= 0; } 
 215 #if 0 // the old wxDate members - unused any more 
 216     unsigned long julian
; // see julDate();  days since 1/1/4713 B.C. 
 217     int month
;            // see NMonth() 
 218     int day
;              // see Day() 
 219     int year
;             // see NYear4() 
 220     int day_of_week
;      // see NDOW();  1 = Sunday, ... 7 = Saturday 
 222     void julian_to_mdy();         // convert julian day to mdy 
 223     void julian_to_wday();        // convert julian day to day_of_week 
 224     void mdy_to_julian();         // convert mdy to julian day 
 231     int m_displayOptions
; 
 234     DECLARE_DYNAMIC_CLASS(wxDate
) 
 237 // ---------------------------------------------------------------------------- 
 239 // ---------------------------------------------------------------------------- 
 241 inline bool WXDLLEXPORT 
operator <(const wxDate 
&dt1
, const wxDate 
&dt2
) 
 242     { return dt1
.GetJulianDate() < dt2
.GetJulianDate(); } 
 243 inline bool WXDLLEXPORT 
operator <=(const wxDate 
&dt1
, const wxDate 
&dt2
) 
 244     { return dt1
.GetJulianDate() <= dt2
.GetJulianDate(); } 
 245 inline bool WXDLLEXPORT 
operator >(const wxDate 
&dt1
, const wxDate 
&dt2
) 
 246     { return dt1
.GetJulianDate() > dt2
.GetJulianDate(); } 
 247 inline bool WXDLLEXPORT 
operator >=(const wxDate 
&dt1
, const wxDate 
&dt2
) 
 248     { return dt1
.GetJulianDate() >= dt2
.GetJulianDate(); } 
 249 inline bool WXDLLEXPORT 
operator ==(const wxDate 
&dt1
, const wxDate 
&dt2
) 
 250     { return dt1
.GetJulianDate() == dt2
.GetJulianDate(); } 
 251 inline bool WXDLLEXPORT 
operator !=(const wxDate 
&dt1
, const wxDate 
&dt2
) 
 252     { return dt1
.GetJulianDate() != dt2
.GetJulianDate(); } 
 254 #endif // wxUSE_TIMEDATE