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:
Vadim Zeitlin
2001-01-05 21:03:19 +00:00
parent 54b8489125
commit 384223b34b
4 changed files with 49 additions and 29 deletions

View File

@@ -100,7 +100,7 @@ class WXDLLEXPORT wxDateSpan;
// wxInvalidDateTime)
class WXDLLEXPORT wxDateTime;
WXDLLEXPORT_DATA(extern wxDateTime&) wxDefaultDateTime;
WXDLLEXPORT_DATA(extern const wxDateTime&) wxDefaultDateTime;
#define wxInvalidDateTime wxDefaultDateTime
// ----------------------------------------------------------------------------
@@ -760,8 +760,9 @@ public:
// result of timezone shift)
// ------------------------------------------------------------------------
// is the date valid (TRUE even for non initialized objects)?
inline bool IsValid() const { return this != &wxInvalidDateTime; }
// is the date valid? Note that this will return TRUE for non
// 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
//

View File

@@ -65,10 +65,9 @@
#define wxLongLong_t long long
#else // no native long long type
// both warning and pragma warning are not portable, but at least an
// unknown pragma should never be an error.
// Err, actually, Watcom C++ doesn't like it.
// (well, if the compilers are _that_ broken, I'm removing it (VZ))
#if 0 //ndef __WATCOMC__
// unknown pragma should never be an error - unless the compiler is
// seriously broken as Watcom C++ seems to be...
#ifndef __WATCOMC__
#pragma warning "Your compiler does not appear to support 64 bit "\
"integers, using emulation class instead."
#endif
@@ -80,7 +79,7 @@
// both classes) but by default we only use one class
#if (defined(wxUSE_LONGLONG_WX) && wxUSE_LONGLONG_WX) || !defined(wxLongLong_t)
// 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
#define wxUSE_LONGLONG_NATIVE 0
#endif

View File

@@ -37,7 +37,7 @@
//#define TEST_ARRAYS
//#define TEST_CMDLINE
//#define TEST_DATETIME
#define TEST_DATETIME
//#define TEST_DIR
//#define TEST_DLLLOADER
//#define TEST_ENVIRON
@@ -45,7 +45,7 @@
//#define TEST_FILE
//#define TEST_FILECONF
//#define TEST_FILENAME
#define TEST_FTP
//#define TEST_FTP
//#define TEST_HASH
//#define TEST_LIST
//#define TEST_LOG
@@ -4098,7 +4098,7 @@ int main(int argc, char **argv)
#endif // TEST_TIMER
#ifdef TEST_DATETIME
if ( 0 )
if ( 1 )
{
TestTimeSet();
TestTimeStatic();

View File

@@ -106,6 +106,19 @@
#endif
#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
// ----------------------------------------------------------------------------
@@ -173,9 +186,11 @@ static const wxDateTime::wxDateTime_t gs_cumulatedDays[2][MONTHS_IN_YEAR] =
// 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;
@@ -1071,7 +1086,9 @@ wxDateTime& wxDateTime::Set(const struct tm& tm)
wxFAIL_MSG( _T("mktime() failed") );
return wxInvalidDateTime;
*this = wxInvalidDateTime;
return *this;
}
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
// don't use them really
wxCHECK_MSG( hour < 24 && second < 62 && minute < 60 && millisec < 1000,
wxInvalidDateTime,
wxDATETIME_CHECK( hour < 24 &&
second < 62 &&
minute < 60 &&
millisec < 1000,
_T("Invalid time in wxDateTime::Set()") );
// get the current date from system
struct tm *tm = GetTmNow();
wxCHECK_MSG( tm, wxInvalidDateTime, _T("localtime() failed") );
wxDATETIME_CHECK( tm, _T("localtime() failed") );
// adjust the time
tm->tm_hour = hour;
@@ -1118,14 +1137,15 @@ wxDateTime& wxDateTime::Set(wxDateTime_t day,
{
wxASSERT_MSG( IsValid(), _T("invalid wxDateTime") );
wxCHECK_MSG( hour < 24 && second < 62 && minute < 60 && millisec < 1000,
wxInvalidDateTime,
wxDATETIME_CHECK( hour < 24 &&
second < 62 &&
minute < 60 &&
millisec < 1000,
_T("Invalid time in wxDateTime::Set()") );
ReplaceDefaultYearMonthWithCurrent(&year, &month);
wxCHECK_MSG( (0 < day) && (day <= GetNumberOfDays(month, year)),
wxInvalidDateTime,
wxDATETIME_CHECK( (0 < day) && (day <= GetNumberOfDays(month, year)),
_T("Invalid date in wxDateTime::Set()") );
// the range of time_t type (inclusive)
@@ -1479,7 +1499,7 @@ wxDateTime& wxDateTime::SetToLastMonthDay(Month month,
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();
if ( weekday == wdayThis )
@@ -1499,7 +1519,7 @@ wxDateTime& wxDateTime::SetToWeekDayInSameWeek(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;
WeekDay wdayThis = GetWeekDay();
@@ -1523,7 +1543,7 @@ wxDateTime& wxDateTime::SetToNextWeekDay(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;
WeekDay wdayThis = GetWeekDay();
@@ -1671,8 +1691,8 @@ wxDateTime::wxDateTime_t wxDateTime::GetWeekOfMonth(wxDateTime::WeekFlags flags,
wxDateTime& wxDateTime::SetToYearDay(wxDateTime::wxDateTime_t yday)
{
int year = GetYear();
wxCHECK_MSG( (0 < yday) && (yday <= GetNumberOfDays(year)),
wxInvalidDateTime, _T("invalid year day") );
wxDATETIME_CHECK( (0 < yday) && (yday <= GetNumberOfDays(year)),
_T("invalid year day") );
bool isLeap = IsLeapYear(year);
for ( Month mon = Jan; mon < Inv_Month; wxNextMonth(mon) )