]> git.saurik.com Git - wxWidgets.git/blobdiff - src/common/datetime.cpp
modified wxEncodingConverter API to report failures
[wxWidgets.git] / src / common / datetime.cpp
index 1d85ebbbd81c3946803d88f400a6c7d950f6c97e..9a102f00c6542048fba363bc95316d1dd75d71c2 100644 (file)
@@ -500,7 +500,7 @@ static bool GetNumericToken(size_t len, const wxChar*& p, unsigned long *number)
             break;
     }
 
-    return !s.IsEmpty() && s.ToULong(number);
+    return !s.empty() && s.ToULong(number);
 }
 
 // scans all alphabetic characters and returns the resulting string
@@ -542,8 +542,8 @@ wxDateTime::Tm::Tm(const struct tm& tm, const TimeZone& tz)
     mday = (wxDateTime::wxDateTime_t)tm.tm_mday;
     mon = (wxDateTime::Month)tm.tm_mon;
     year = 1900 + tm.tm_year;
-    wday = tm.tm_wday;
-    yday = tm.tm_yday;
+    wday = (wxDateTime::wxDateTime_t)tm.tm_wday;
+    yday = (wxDateTime::wxDateTime_t)tm.tm_yday;
 }
 
 bool wxDateTime::Tm::IsValid() const
@@ -559,7 +559,7 @@ void wxDateTime::Tm::ComputeWeekDay()
     // compute the week day from day/month/year: we use the dumbest algorithm
     // possible: just compute our JDN and then use the (simple to derive)
     // formula: weekday = (JDN + 1.5) % 7
-    wday = (wxDateTime::WeekDay)(GetTruncatedJDN(mday, mon, year) + 2) % 7;
+    wday = (wxDateTime::wxDateTime_t)((wxDateTime::WeekDay)(GetTruncatedJDN(mday, mon, year) + 2) % 7);
 }
 
 void wxDateTime::Tm::AddMonths(int monDiff)
@@ -1168,16 +1168,11 @@ wxDateTime& wxDateTime::Set(const struct tm& tm)
         // less than timezone - try to make it work for this case
         if ( tm2.tm_year == 70 && tm2.tm_mon == 0 && tm2.tm_mday == 1 )
         {
-            // add timezone to make sure that date is in range
-            tm2.tm_sec -= GetTimeZone();
-
-            timet = mktime(&tm2);
-            if ( timet != (time_t)-1 )
-            {
-                timet += GetTimeZone();
-
-                return Set(timet);
-            }
+            return Set((time_t)(
+                       GetTimeZone() +
+                       tm2.tm_hour * MIN_PER_HOUR * SEC_PER_MIN +
+                       tm2.tm_min * SEC_PER_MIN +
+                       tm2.tm_sec));
         }
 
         wxFAIL_MSG( _T("mktime() failed") );
@@ -1262,7 +1257,10 @@ wxDateTime& wxDateTime::Set(wxDateTime_t day,
         (void)Set(tm);
 
         // and finally adjust milliseconds
-        return SetMillisecond(millisec);
+        if (IsValid())
+            SetMillisecond(millisec);
+
+        return *this;
     }
     else
     {
@@ -2394,7 +2392,7 @@ wxString wxDateTime::Format(const wxChar *format, const TimeZone& tz) const
                         fmt += *p;
                     }
 
-                    if ( !fmt.IsEmpty() )
+                    if ( !fmt.empty() )
                     {
                         // we've only got the flags and width so far in fmt
                         fmt.Prepend(_T('%'));
@@ -2966,7 +2964,7 @@ const wxChar *wxDateTime::ParseFormat(const wxChar *date,
                     wxString am, pm, token = GetAlphaToken(input);
 
                     GetAmPmStrings(&am, &pm);
-                    if (am.IsEmpty() && pm.IsEmpty())
+                    if (am.empty() && pm.empty())
                         return (wxChar *)NULL;  // no am/pm strings defined
                     if ( token.CmpNoCase(pm) == 0 )
                     {
@@ -4030,6 +4028,11 @@ void wxDateTimeHolidayAuthority::AddAuthority(wxDateTimeHolidayAuthority *auth)
     ms_authorities.push_back(auth);
 }
 
+wxDateTimeHolidayAuthority::~wxDateTimeHolidayAuthority()
+{
+    // required here for Darwin
+}
+
 // ----------------------------------------------------------------------------
 // wxDateTimeWorkDays
 // ----------------------------------------------------------------------------