1999-12-21 01:44:45 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Name: wx/date.h
|
|
|
|
// Purpose: wxDate class: this class is deprecated, use wxDateTime instead!
|
1998-05-20 14:01:55 +00:00
|
|
|
// Author: Julian Smart, Steve Marcus, Eric Simon, Chris Hill,
|
|
|
|
// Charles D. Price
|
1999-12-21 01:44:45 +00:00
|
|
|
// Modified by: 18.12.99 by VZ to use the new wxDateTime class
|
1998-05-20 14:01:55 +00:00
|
|
|
// Created: 01/02/97
|
|
|
|
// RCS-ID: $Id$
|
1999-12-21 01:44:45 +00:00
|
|
|
// Copyright:(c)
|
1999-03-29 21:18:49 +00:00
|
|
|
// Licence: wxWindows licence
|
1999-12-21 01:44:45 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
1998-05-20 14:01:55 +00:00
|
|
|
|
1998-08-15 00:23:28 +00:00
|
|
|
#ifndef _WX_DATE_H_
|
|
|
|
#define _WX_DATE_H_
|
1998-05-20 14:01:55 +00:00
|
|
|
|
|
|
|
#ifdef __GNUG__
|
1999-12-21 01:44:45 +00:00
|
|
|
#pragma interface "date.h"
|
1998-05-20 14:01:55 +00:00
|
|
|
#endif
|
|
|
|
|
1999-12-21 01:44:45 +00:00
|
|
|
#include "wx/defs.h"
|
1998-05-20 14:01:55 +00:00
|
|
|
|
1999-01-24 14:57:09 +00:00
|
|
|
#if wxUSE_TIMEDATE
|
1998-05-20 14:01:55 +00:00
|
|
|
|
1999-12-21 01:44:45 +00:00
|
|
|
#include "wx/object.h"
|
|
|
|
#include "wx/string.h"
|
|
|
|
#include "wx/datetime.h"
|
1998-05-20 14:01:55 +00:00
|
|
|
|
1999-12-21 01:44:45 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// constants
|
|
|
|
// ----------------------------------------------------------------------------
|
1998-05-20 14:01:55 +00:00
|
|
|
|
1999-12-21 01:44:45 +00:00
|
|
|
enum wxdate_format_type
|
1998-05-20 14:01:55 +00:00
|
|
|
{
|
1999-12-21 01:44:45 +00:00
|
|
|
wxMDY,
|
|
|
|
wxDAY,
|
|
|
|
wxMONTH,
|
|
|
|
wxFULL,
|
|
|
|
wxEUROPEAN
|
|
|
|
};
|
1999-03-29 21:18:49 +00:00
|
|
|
|
1999-12-21 01:44:45 +00:00
|
|
|
enum // wxdate_format_flags
|
|
|
|
{
|
|
|
|
wxNO_CENTURY = 0x02,
|
|
|
|
wxDATE_ABBR = 0x04
|
|
|
|
};
|
1999-03-29 21:18:49 +00:00
|
|
|
|
1999-12-21 01:44:45 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// wxDate
|
|
|
|
// ----------------------------------------------------------------------------
|
1999-03-29 21:18:49 +00:00
|
|
|
|
1999-12-21 01:44:45 +00:00
|
|
|
class WXDLLEXPORT wxDate : public wxObject
|
|
|
|
{
|
1999-03-29 21:18:49 +00:00
|
|
|
public:
|
1999-12-21 01:44:45 +00:00
|
|
|
wxDate() { Init(); }
|
|
|
|
wxDate(long j) : m_date((double)(j + 0.5)) { Init(); }
|
|
|
|
wxDate(int m, int d, int y) : m_date(d, (wxDateTime::Month)m, y) { Init(); }
|
|
|
|
wxDate(const wxString& dat) { Init(); (void)m_date.ParseDate(dat); }
|
|
|
|
wxDate(const wxDate &date) { *this = date; }
|
|
|
|
|
|
|
|
wxDate(const wxDateTime& dt) { Init(); m_date = dt; }
|
1998-05-20 14:01:55 +00:00
|
|
|
|
1999-01-19 11:00:22 +00:00
|
|
|
#ifndef __SALFORDC__
|
1999-12-21 01:44:45 +00:00
|
|
|
operator wxString() const { return FormatDate(); }
|
1999-01-19 11:00:22 +00:00
|
|
|
#endif
|
|
|
|
|
1999-12-21 01:44:45 +00:00
|
|
|
void operator=(const wxDate& date)
|
|
|
|
{
|
|
|
|
m_date = date.m_date;
|
|
|
|
m_displayFormat = date.m_displayFormat;
|
|
|
|
m_displayOptions = date.m_displayOptions;
|
|
|
|
}
|
1998-05-20 14:01:55 +00:00
|
|
|
|
1999-12-21 01:44:45 +00:00
|
|
|
void operator=(const wxString& dat) { (void)m_date.ParseDate(dat); }
|
1998-05-20 14:01:55 +00:00
|
|
|
|
1999-12-21 01:44:45 +00:00
|
|
|
wxDate operator+(long i) { return wxDate(GetJulianDate() + i); }
|
|
|
|
wxDate operator+(int i) { return wxDate(GetJulianDate() + (long)i); }
|
1998-05-20 14:01:55 +00:00
|
|
|
|
1999-12-21 01:44:45 +00:00
|
|
|
wxDate operator-(long i) { return wxDate(GetJulianDate() - i); }
|
|
|
|
wxDate operator-(int i) { return wxDate(GetJulianDate() - (long)i); }
|
1998-05-20 14:01:55 +00:00
|
|
|
|
1999-12-21 01:44:45 +00:00
|
|
|
long operator-(const wxDate &dt) const
|
|
|
|
{ return GetJulianDate() - dt.GetJulianDate(); }
|
1998-05-20 14:01:55 +00:00
|
|
|
|
2000-01-05 15:35:04 +00:00
|
|
|
wxDate &operator+=(long i) { m_date += wxTimeSpan::Days((int)i); return *this; }
|
|
|
|
wxDate &operator-=(long i) { m_date -= wxTimeSpan::Days((int)i); return *this; }
|
1998-05-20 14:01:55 +00:00
|
|
|
|
1999-12-21 01:44:45 +00:00
|
|
|
wxDate &operator++() { return *this += 1; }
|
|
|
|
wxDate &operator++(int) { return *this += 1; }
|
|
|
|
wxDate &operator--() { return *this -= 1; }
|
|
|
|
wxDate &operator--(int) { return *this -= 1; }
|
1999-01-08 16:46:20 +00:00
|
|
|
|
1999-06-27 10:39:38 +00:00
|
|
|
#if wxUSE_STD_IOSTREAM
|
1999-12-21 01:44:45 +00:00
|
|
|
friend ostream WXDLLEXPORT & operator <<(ostream &os, const wxDate &dt)
|
|
|
|
{ return os << dt.FormatDate().mb_str(); }
|
1999-06-27 10:39:38 +00:00
|
|
|
#endif
|
1998-05-20 14:01:55 +00:00
|
|
|
|
1999-12-21 01:44:45 +00:00
|
|
|
void SetFormat(int format) { m_displayFormat = format; }
|
|
|
|
int SetOption(int option, bool enable = TRUE)
|
|
|
|
{
|
|
|
|
if ( enable )
|
|
|
|
m_displayOptions |= option;
|
|
|
|
else
|
|
|
|
m_displayOptions &= ~option;
|
|
|
|
|
|
|
|
return 1; // (VZ: whatever it means)
|
|
|
|
}
|
|
|
|
|
|
|
|
// returns julian date (VZ: the integral part of Julian Day Number)
|
|
|
|
long GetJulianDate() const
|
|
|
|
{ return (long)(m_date.GetJulianDayNumber() - 0.5); }
|
|
|
|
|
|
|
|
// returns relative date since Jan. 1
|
|
|
|
int GetDayOfYear() const
|
|
|
|
{ return m_date.GetDayOfYear(); }
|
|
|
|
|
|
|
|
// returns TRUE if leap year, FALSE if not
|
|
|
|
bool IsLeapYear() const
|
|
|
|
{ return wxDateTime::IsLeapYear(m_date.GetYear()); }
|
|
|
|
|
|
|
|
// Sets to current system date
|
|
|
|
wxDate &Set()
|
1999-12-21 15:14:14 +00:00
|
|
|
{ m_date = wxDateTime::Today(); return (wxDate&)*this; }
|
1999-12-21 01:44:45 +00:00
|
|
|
wxDate &Set(long lJulian)
|
1999-12-21 15:14:14 +00:00
|
|
|
{ m_date.Set((double)(lJulian + 0.5)); return (wxDate&)*this; }
|
1999-12-21 01:44:45 +00:00
|
|
|
wxDate &Set(int nMonth, int nDay, int nYear)
|
1999-12-21 15:40:13 +00:00
|
|
|
{ m_date.Set(nDay, (wxDateTime::Month)nMonth, nYear); return *this; }
|
1999-12-21 01:44:45 +00:00
|
|
|
|
|
|
|
// May also pass neg# to decrement
|
|
|
|
wxDate &AddWeeks(int nCount = 1)
|
|
|
|
{ m_date += wxDateSpan::Weeks(nCount); return *this; }
|
|
|
|
wxDate &AddMonths(int nCount = 1)
|
|
|
|
{ m_date += wxDateSpan::Months(nCount); return *this; }
|
|
|
|
wxDate &AddYears(int nCount = 1)
|
|
|
|
{ m_date += wxDateSpan::Years(nCount); return *this; }
|
|
|
|
|
|
|
|
// Numeric Day of date object
|
|
|
|
int GetDay() const { return m_date.GetDay(); }
|
|
|
|
// Number of days in month(1..31)
|
|
|
|
int GetDaysInMonth() const
|
|
|
|
{
|
|
|
|
return wxDateTime::GetNumberOfDays((wxDateTime::Month)m_date.GetMonth(),
|
|
|
|
m_date.GetYear());
|
|
|
|
}
|
|
|
|
|
|
|
|
// First Day Of Month(1..7)
|
|
|
|
int GetFirstDayOfMonth() const
|
|
|
|
{ return wxDate(GetMonth(), 1, GetYear()).GetDayOfWeek(); }
|
|
|
|
|
|
|
|
// Character Day Of Week('Sunday'..'Saturday')
|
|
|
|
wxString GetDayOfWeekName() const { return FormatDate(wxDAY); }
|
|
|
|
int GetDayOfWeek() const { return (int)m_date.GetWeekDay() + 1; }
|
|
|
|
|
|
|
|
// Numeric Week Of Month(1..6) (VZ: I'd love to see a month with 6 weeks)
|
|
|
|
int GetWeekOfMonth() const { return m_date.GetWeekOfMonth(); }
|
|
|
|
// Numeric Week Of Year(1..52) (VZ: but there are years with 53 weeks)
|
|
|
|
int GetWeekOfYear() const { return m_date.GetWeekOfYear(); }
|
|
|
|
|
|
|
|
// Character Month name
|
|
|
|
wxString GetMonthName() { return FormatDate(wxMONTH); }
|
|
|
|
// Month Number(1..12)
|
|
|
|
int GetMonth() const { return m_date.GetMonth() + 1; }
|
|
|
|
|
|
|
|
// First Date Of Month
|
2000-07-15 19:51:35 +00:00
|
|
|
wxDate GetMonthStart() const { return(wxDate(GetMonth()-1, 1, GetYear())); }
|
1999-12-21 01:44:45 +00:00
|
|
|
// Last Date Of Month
|
2000-07-15 19:51:35 +00:00
|
|
|
wxDate GetMonthEnd() const { return wxDate(GetMonth(), 1, GetYear())-1; }
|
1999-12-21 01:44:45 +00:00
|
|
|
|
|
|
|
// eg. 1992
|
|
|
|
int GetYear() const { return m_date.GetYear(); }
|
|
|
|
// First Date Of Year
|
2000-07-15 19:51:35 +00:00
|
|
|
wxDate GetYearStart() const { return wxDate(0, 1, GetYear()); }
|
1999-12-21 01:44:45 +00:00
|
|
|
// Last Date Of Year
|
2000-07-15 19:51:35 +00:00
|
|
|
wxDate GetYearEnd() const { return wxDate(0, 1, GetYear()+1) - 1; }
|
1999-12-21 01:44:45 +00:00
|
|
|
|
|
|
|
bool IsBetween(const wxDate& first, const wxDate& second) const
|
|
|
|
{
|
|
|
|
return m_date.IsBetween(first.m_date, second.m_date);
|
|
|
|
}
|
|
|
|
|
|
|
|
wxDate Previous(int dayOfWeek) const
|
|
|
|
{
|
1999-12-26 21:52:50 +00:00
|
|
|
wxDate prev = *this;
|
1999-12-21 01:44:45 +00:00
|
|
|
int dow = GetDayOfWeek();
|
1999-12-26 21:52:50 +00:00
|
|
|
prev -= dayOfWeek > dow ? 7 - (dayOfWeek - dow) : dow - dayOfWeek;
|
|
|
|
|
|
|
|
return prev;
|
1999-12-21 01:44:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
wxString FormatDate(int type = -1) const
|
|
|
|
{
|
|
|
|
static const wxChar *formats[] =
|
|
|
|
{
|
|
|
|
// MDY (week)DAY MONTH FULL EUROPEAN
|
|
|
|
_T("%m/%d/%Y"), _T("%A"), _T("%B"), _T("%A, %B %d, %Y"), _T("%d %B %Y")
|
|
|
|
};
|
|
|
|
|
|
|
|
wxString fmt = formats[type == -1 ? m_displayFormat : type];
|
|
|
|
|
|
|
|
if ( m_displayOptions & wxDATE_ABBR )
|
|
|
|
{
|
|
|
|
fmt.Replace(_T("A"), _T("a"));
|
|
|
|
fmt.Replace(_T("B"), _T("b"));
|
|
|
|
}
|
|
|
|
if ( m_displayOptions & wxNO_CENTURY )
|
|
|
|
{
|
|
|
|
fmt.Replace(_T("Y"), _T("y"));
|
|
|
|
}
|
|
|
|
|
|
|
|
return m_date.Format(fmt);
|
|
|
|
}
|
1998-05-20 14:01:55 +00:00
|
|
|
|
1999-12-21 01:44:45 +00:00
|
|
|
protected:
|
|
|
|
void Init() { m_displayFormat = wxMDY; m_displayOptions = 0; }
|
1998-05-20 14:01:55 +00:00
|
|
|
|
1999-12-21 01:44:45 +00:00
|
|
|
#if 0 // the old wxDate members - unused any more
|
|
|
|
unsigned long julian; // see julDate(); days since 1/1/4713 B.C.
|
|
|
|
int month; // see NMonth()
|
|
|
|
int day; // see Day()
|
|
|
|
int year; // see NYear4()
|
|
|
|
int day_of_week; // see NDOW(); 1 = Sunday, ... 7 = Saturday
|
1998-05-20 14:01:55 +00:00
|
|
|
|
1999-12-21 01:44:45 +00:00
|
|
|
void julian_to_mdy(); // convert julian day to mdy
|
|
|
|
void julian_to_wday(); // convert julian day to day_of_week
|
|
|
|
void mdy_to_julian(); // convert mdy to julian day
|
|
|
|
#endif // 0
|
1998-05-20 14:01:55 +00:00
|
|
|
|
1999-12-21 01:44:45 +00:00
|
|
|
private:
|
|
|
|
wxDateTime m_date;
|
1998-05-20 14:01:55 +00:00
|
|
|
|
1999-12-21 01:44:45 +00:00
|
|
|
int m_displayFormat;
|
|
|
|
int m_displayOptions;
|
1999-03-29 21:18:49 +00:00
|
|
|
|
1999-12-21 01:44:45 +00:00
|
|
|
private:
|
|
|
|
DECLARE_DYNAMIC_CLASS(wxDate)
|
1998-05-20 14:01:55 +00:00
|
|
|
};
|
|
|
|
|
1999-12-21 01:44:45 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// global functions
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
inline bool WXDLLEXPORT operator <(const wxDate &dt1, const wxDate &dt2)
|
|
|
|
{ return dt1.GetJulianDate() < dt2.GetJulianDate(); }
|
|
|
|
inline bool WXDLLEXPORT operator <=(const wxDate &dt1, const wxDate &dt2)
|
|
|
|
{ return dt1.GetJulianDate() <= dt2.GetJulianDate(); }
|
|
|
|
inline bool WXDLLEXPORT operator >(const wxDate &dt1, const wxDate &dt2)
|
|
|
|
{ return dt1.GetJulianDate() > dt2.GetJulianDate(); }
|
|
|
|
inline bool WXDLLEXPORT operator >=(const wxDate &dt1, const wxDate &dt2)
|
|
|
|
{ return dt1.GetJulianDate() >= dt2.GetJulianDate(); }
|
|
|
|
inline bool WXDLLEXPORT operator ==(const wxDate &dt1, const wxDate &dt2)
|
|
|
|
{ return dt1.GetJulianDate() == dt2.GetJulianDate(); }
|
|
|
|
inline bool WXDLLEXPORT operator !=(const wxDate &dt1, const wxDate &dt2)
|
|
|
|
{ return dt1.GetJulianDate() != dt2.GetJulianDate(); }
|
|
|
|
|
1999-03-29 21:18:49 +00:00
|
|
|
#endif // wxUSE_TIMEDATE
|
1998-05-20 14:01:55 +00:00
|
|
|
#endif
|
1998-08-15 00:23:28 +00:00
|
|
|
// _WX_DATE_H_
|