]> git.saurik.com Git - wxWidgets.git/commitdiff
wxDateTime::IsValid() now returns m_time != (wxLongLong)-1
authorVadim Zeitlin <vadim@wxwidgets.org>
Fri, 5 Jan 2001 21:03:19 +0000 (21:03 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Fri, 5 Jan 2001 21:03:19 +0000 (21:03 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@9057 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

include/wx/datetime.h
include/wx/longlong.h
samples/console/console.cpp
src/common/datetime.cpp

index 688b2debf4192b90b632494796a0edea13aa11d3..69872ce28a1f1b34b5c1c3d26735829d086466c1 100644 (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
         //
index 113bc1dd330f66d3584011e2253997be2a71c18f..dd35aafdd2d9d619b974a2e2000ca6b945bb65e2 100644 (file)
         #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
index d7088dec55f5f91f6e6a00e6bdfac0592bbd889c..cdd4e8f68fc20f78b8c28382975d9f4f5b8d3f92 100644 (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();
index 5c212e190e7cc8fbd42c23a7ccc8061a0fa990ef..fa2ab9cabb27174a010d913c13f72b8cdaeef700 100644 (file)
     #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,
-                 _T("Invalid time in wxDateTime::Set()") );
+    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,15 +1137,16 @@ wxDateTime& wxDateTime::Set(wxDateTime_t day,
 {
     wxASSERT_MSG( IsValid(), _T("invalid wxDateTime") );
 
-    wxCHECK_MSG( hour < 24 && second < 62 && minute < 60 && millisec < 1000,
-                 wxInvalidDateTime,
-                 _T("Invalid time in wxDateTime::Set()") );
+    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,
-                 _T("Invalid date in wxDateTime::Set()") );
+    wxDATETIME_CHECK( (0 < day) && (day <= GetNumberOfDays(month, year)),
+                      _T("Invalid date in wxDateTime::Set()") );
 
     // the range of time_t type (inclusive)
     static const int yearMinInRange = 1970;
@@ -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) )