wxDateTime::IsValid() now returns m_time != (wxLongLong)-1
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@9057 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -100,7 +100,7 @@ class WXDLLEXPORT wxDateSpan;
|
|||||||
// wxInvalidDateTime)
|
// wxInvalidDateTime)
|
||||||
class WXDLLEXPORT wxDateTime;
|
class WXDLLEXPORT wxDateTime;
|
||||||
|
|
||||||
WXDLLEXPORT_DATA(extern wxDateTime&) wxDefaultDateTime;
|
WXDLLEXPORT_DATA(extern const wxDateTime&) wxDefaultDateTime;
|
||||||
#define wxInvalidDateTime wxDefaultDateTime
|
#define wxInvalidDateTime wxDefaultDateTime
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
@@ -760,8 +760,9 @@ public:
|
|||||||
// result of timezone shift)
|
// result of timezone shift)
|
||||||
// ------------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
|
|
||||||
// is the date valid (TRUE even for non initialized objects)?
|
// is the date valid? Note that this will return TRUE for non
|
||||||
inline bool IsValid() const { return this != &wxInvalidDateTime; }
|
// initialized objects but FALSE if *this == wxInvalidDateTime
|
||||||
|
inline bool IsValid() const { return m_time != wxInvalidDateTime.m_time; }
|
||||||
|
|
||||||
// get the broken down date/time representation in the given timezone
|
// get the broken down date/time representation in the given timezone
|
||||||
//
|
//
|
||||||
|
@@ -65,10 +65,9 @@
|
|||||||
#define wxLongLong_t long long
|
#define wxLongLong_t long long
|
||||||
#else // no native long long type
|
#else // no native long long type
|
||||||
// both warning and pragma warning are not portable, but at least an
|
// both warning and pragma warning are not portable, but at least an
|
||||||
// unknown pragma should never be an error.
|
// unknown pragma should never be an error - unless the compiler is
|
||||||
// Err, actually, Watcom C++ doesn't like it.
|
// seriously broken as Watcom C++ seems to be...
|
||||||
// (well, if the compilers are _that_ broken, I'm removing it (VZ))
|
#ifndef __WATCOMC__
|
||||||
#if 0 //ndef __WATCOMC__
|
|
||||||
#pragma warning "Your compiler does not appear to support 64 bit "\
|
#pragma warning "Your compiler does not appear to support 64 bit "\
|
||||||
"integers, using emulation class instead."
|
"integers, using emulation class instead."
|
||||||
#endif
|
#endif
|
||||||
@@ -80,7 +79,7 @@
|
|||||||
// both classes) but by default we only use one class
|
// both classes) but by default we only use one class
|
||||||
#if (defined(wxUSE_LONGLONG_WX) && wxUSE_LONGLONG_WX) || !defined(wxLongLong_t)
|
#if (defined(wxUSE_LONGLONG_WX) && wxUSE_LONGLONG_WX) || !defined(wxLongLong_t)
|
||||||
// don't use both classes unless wxUSE_LONGLONG_NATIVE was explicitly set:
|
// don't use both classes unless wxUSE_LONGLONG_NATIVE was explicitly set:
|
||||||
// this is useful in test programs nad only there
|
// this is useful in test programs and only there
|
||||||
#ifndef wxUSE_LONGLONG_NATIVE
|
#ifndef wxUSE_LONGLONG_NATIVE
|
||||||
#define wxUSE_LONGLONG_NATIVE 0
|
#define wxUSE_LONGLONG_NATIVE 0
|
||||||
#endif
|
#endif
|
||||||
|
@@ -37,7 +37,7 @@
|
|||||||
|
|
||||||
//#define TEST_ARRAYS
|
//#define TEST_ARRAYS
|
||||||
//#define TEST_CMDLINE
|
//#define TEST_CMDLINE
|
||||||
//#define TEST_DATETIME
|
#define TEST_DATETIME
|
||||||
//#define TEST_DIR
|
//#define TEST_DIR
|
||||||
//#define TEST_DLLLOADER
|
//#define TEST_DLLLOADER
|
||||||
//#define TEST_ENVIRON
|
//#define TEST_ENVIRON
|
||||||
@@ -45,7 +45,7 @@
|
|||||||
//#define TEST_FILE
|
//#define TEST_FILE
|
||||||
//#define TEST_FILECONF
|
//#define TEST_FILECONF
|
||||||
//#define TEST_FILENAME
|
//#define TEST_FILENAME
|
||||||
#define TEST_FTP
|
//#define TEST_FTP
|
||||||
//#define TEST_HASH
|
//#define TEST_HASH
|
||||||
//#define TEST_LIST
|
//#define TEST_LIST
|
||||||
//#define TEST_LOG
|
//#define TEST_LOG
|
||||||
@@ -4098,7 +4098,7 @@ int main(int argc, char **argv)
|
|||||||
#endif // TEST_TIMER
|
#endif // TEST_TIMER
|
||||||
|
|
||||||
#ifdef TEST_DATETIME
|
#ifdef TEST_DATETIME
|
||||||
if ( 0 )
|
if ( 1 )
|
||||||
{
|
{
|
||||||
TestTimeSet();
|
TestTimeSet();
|
||||||
TestTimeStatic();
|
TestTimeStatic();
|
||||||
|
@@ -106,6 +106,19 @@
|
|||||||
#endif
|
#endif
|
||||||
#endif // !WX_TIMEZONE
|
#endif // !WX_TIMEZONE
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
// macros
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// debugging helper: just a convenient replacement of wxCHECK()
|
||||||
|
#define wxDATETIME_CHECK(expr, msg) \
|
||||||
|
if ( !(expr) ) \
|
||||||
|
{ \
|
||||||
|
wxFAIL_MSG(msg); \
|
||||||
|
*this = wxInvalidDateTime; \
|
||||||
|
return *this; \
|
||||||
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
// private classes
|
// private classes
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
@@ -173,9 +186,11 @@ static const wxDateTime::wxDateTime_t gs_cumulatedDays[2][MONTHS_IN_YEAR] =
|
|||||||
// global data
|
// global data
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
static wxDateTime gs_dtDefault;
|
// in the fine tradition of ANSI C we use our equivalent of (time_t)-1 to
|
||||||
|
// indicate an invalid wxDateTime object
|
||||||
|
static const wxDateTime gs_dtDefault = wxLongLong((long)ULONG_MAX, ULONG_MAX);
|
||||||
|
|
||||||
wxDateTime& wxDefaultDateTime = gs_dtDefault;
|
const wxDateTime& wxDefaultDateTime = gs_dtDefault;
|
||||||
|
|
||||||
wxDateTime::Country wxDateTime::ms_country = wxDateTime::Country_Unknown;
|
wxDateTime::Country wxDateTime::ms_country = wxDateTime::Country_Unknown;
|
||||||
|
|
||||||
@@ -1071,7 +1086,9 @@ wxDateTime& wxDateTime::Set(const struct tm& tm)
|
|||||||
|
|
||||||
wxFAIL_MSG( _T("mktime() failed") );
|
wxFAIL_MSG( _T("mktime() failed") );
|
||||||
|
|
||||||
return wxInvalidDateTime;
|
*this = wxInvalidDateTime;
|
||||||
|
|
||||||
|
return *this;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -1088,14 +1105,16 @@ wxDateTime& wxDateTime::Set(wxDateTime_t hour,
|
|||||||
|
|
||||||
// we allow seconds to be 61 to account for the leap seconds, even if we
|
// we allow seconds to be 61 to account for the leap seconds, even if we
|
||||||
// don't use them really
|
// don't use them really
|
||||||
wxCHECK_MSG( hour < 24 && second < 62 && minute < 60 && millisec < 1000,
|
wxDATETIME_CHECK( hour < 24 &&
|
||||||
wxInvalidDateTime,
|
second < 62 &&
|
||||||
_T("Invalid time in wxDateTime::Set()") );
|
minute < 60 &&
|
||||||
|
millisec < 1000,
|
||||||
|
_T("Invalid time in wxDateTime::Set()") );
|
||||||
|
|
||||||
// get the current date from system
|
// get the current date from system
|
||||||
struct tm *tm = GetTmNow();
|
struct tm *tm = GetTmNow();
|
||||||
|
|
||||||
wxCHECK_MSG( tm, wxInvalidDateTime, _T("localtime() failed") );
|
wxDATETIME_CHECK( tm, _T("localtime() failed") );
|
||||||
|
|
||||||
// adjust the time
|
// adjust the time
|
||||||
tm->tm_hour = hour;
|
tm->tm_hour = hour;
|
||||||
@@ -1118,15 +1137,16 @@ wxDateTime& wxDateTime::Set(wxDateTime_t day,
|
|||||||
{
|
{
|
||||||
wxASSERT_MSG( IsValid(), _T("invalid wxDateTime") );
|
wxASSERT_MSG( IsValid(), _T("invalid wxDateTime") );
|
||||||
|
|
||||||
wxCHECK_MSG( hour < 24 && second < 62 && minute < 60 && millisec < 1000,
|
wxDATETIME_CHECK( hour < 24 &&
|
||||||
wxInvalidDateTime,
|
second < 62 &&
|
||||||
_T("Invalid time in wxDateTime::Set()") );
|
minute < 60 &&
|
||||||
|
millisec < 1000,
|
||||||
|
_T("Invalid time in wxDateTime::Set()") );
|
||||||
|
|
||||||
ReplaceDefaultYearMonthWithCurrent(&year, &month);
|
ReplaceDefaultYearMonthWithCurrent(&year, &month);
|
||||||
|
|
||||||
wxCHECK_MSG( (0 < day) && (day <= GetNumberOfDays(month, year)),
|
wxDATETIME_CHECK( (0 < day) && (day <= GetNumberOfDays(month, year)),
|
||||||
wxInvalidDateTime,
|
_T("Invalid date in wxDateTime::Set()") );
|
||||||
_T("Invalid date in wxDateTime::Set()") );
|
|
||||||
|
|
||||||
// the range of time_t type (inclusive)
|
// the range of time_t type (inclusive)
|
||||||
static const int yearMinInRange = 1970;
|
static const int yearMinInRange = 1970;
|
||||||
@@ -1479,7 +1499,7 @@ wxDateTime& wxDateTime::SetToLastMonthDay(Month month,
|
|||||||
|
|
||||||
wxDateTime& wxDateTime::SetToWeekDayInSameWeek(WeekDay weekday)
|
wxDateTime& wxDateTime::SetToWeekDayInSameWeek(WeekDay weekday)
|
||||||
{
|
{
|
||||||
wxCHECK_MSG( weekday != Inv_WeekDay, wxInvalidDateTime, _T("invalid weekday") );
|
wxDATETIME_CHECK( weekday != Inv_WeekDay, _T("invalid weekday") );
|
||||||
|
|
||||||
WeekDay wdayThis = GetWeekDay();
|
WeekDay wdayThis = GetWeekDay();
|
||||||
if ( weekday == wdayThis )
|
if ( weekday == wdayThis )
|
||||||
@@ -1499,7 +1519,7 @@ wxDateTime& wxDateTime::SetToWeekDayInSameWeek(WeekDay weekday)
|
|||||||
|
|
||||||
wxDateTime& wxDateTime::SetToNextWeekDay(WeekDay weekday)
|
wxDateTime& wxDateTime::SetToNextWeekDay(WeekDay weekday)
|
||||||
{
|
{
|
||||||
wxCHECK_MSG( weekday != Inv_WeekDay, wxInvalidDateTime, _T("invalid weekday") );
|
wxDATETIME_CHECK( weekday != Inv_WeekDay, _T("invalid weekday") );
|
||||||
|
|
||||||
int diff;
|
int diff;
|
||||||
WeekDay wdayThis = GetWeekDay();
|
WeekDay wdayThis = GetWeekDay();
|
||||||
@@ -1523,7 +1543,7 @@ wxDateTime& wxDateTime::SetToNextWeekDay(WeekDay weekday)
|
|||||||
|
|
||||||
wxDateTime& wxDateTime::SetToPrevWeekDay(WeekDay weekday)
|
wxDateTime& wxDateTime::SetToPrevWeekDay(WeekDay weekday)
|
||||||
{
|
{
|
||||||
wxCHECK_MSG( weekday != Inv_WeekDay, wxInvalidDateTime, _T("invalid weekday") );
|
wxDATETIME_CHECK( weekday != Inv_WeekDay, _T("invalid weekday") );
|
||||||
|
|
||||||
int diff;
|
int diff;
|
||||||
WeekDay wdayThis = GetWeekDay();
|
WeekDay wdayThis = GetWeekDay();
|
||||||
@@ -1671,8 +1691,8 @@ wxDateTime::wxDateTime_t wxDateTime::GetWeekOfMonth(wxDateTime::WeekFlags flags,
|
|||||||
wxDateTime& wxDateTime::SetToYearDay(wxDateTime::wxDateTime_t yday)
|
wxDateTime& wxDateTime::SetToYearDay(wxDateTime::wxDateTime_t yday)
|
||||||
{
|
{
|
||||||
int year = GetYear();
|
int year = GetYear();
|
||||||
wxCHECK_MSG( (0 < yday) && (yday <= GetNumberOfDays(year)),
|
wxDATETIME_CHECK( (0 < yday) && (yday <= GetNumberOfDays(year)),
|
||||||
wxInvalidDateTime, _T("invalid year day") );
|
_T("invalid year day") );
|
||||||
|
|
||||||
bool isLeap = IsLeapYear(year);
|
bool isLeap = IsLeapYear(year);
|
||||||
for ( Month mon = Jan; mon < Inv_Month; wxNextMonth(mon) )
|
for ( Month mon = Jan; mon < Inv_Month; wxNextMonth(mon) )
|
||||||
|
Reference in New Issue
Block a user