X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/fb96cf856e152671099f464f5d1defa429bfc4ef..27ee942feb598fc96f790d62bb8aac6d8c97cce5:/src/common/datetime.cpp diff --git a/src/common/datetime.cpp b/src/common/datetime.cpp index c40dedee2b..765e316419 100644 --- a/src/common/datetime.cpp +++ b/src/common/datetime.cpp @@ -210,7 +210,18 @@ struct tm *wxLocaltime_r(const time_t* ticks, struct tm* temp) // thread local storage for localtime anyway. wxMutexLocker locker(timeLock); #endif - memcpy(temp, localtime(ticks), sizeof(struct tm)); + + // Borland CRT crashes when passed 0 ticks for some reason, see SF bug 1704438 +#ifdef __BORLANDC__ + if ( !*ticks ) + return NULL; +#endif + + const tm * const t = localtime(ticks); + if ( !t ) + return NULL; + + memcpy(temp, t, sizeof(struct tm)); return temp; } #endif // !HAVE_LOCALTIME_R @@ -223,6 +234,16 @@ struct tm *wxGmtime_r(const time_t* ticks, struct tm* temp) // using thread local storage for gmtime anyway. wxMutexLocker locker(timeLock); #endif + +#ifdef __BORLANDC__ + if ( !*ticks ) + return NULL; +#endif + + const tm * const t = gmtime(ticks); + if ( !t ) + return NULL; + memcpy(temp, gmtime(ticks), sizeof(struct tm)); return temp; } @@ -660,7 +681,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::wxDateTime_t)((wxDateTime::WeekDay)(GetTruncatedJDN(mday, mon, year) + 2) % 7); + wday = (wxDateTime::wxDateTime_t)((GetTruncatedJDN(mday, mon, year) + 2) % 7); } void wxDateTime::Tm::AddMonths(int monDiff) @@ -2261,11 +2282,11 @@ wxString wxDateTime::Format(const wxChar *format, const TimeZone& tz) const { wxCHECK_MSG( format, wxEmptyString, _T("NULL format in wxDateTime::Format") ); - time_t time = GetTicks(); - // we have to use our own implementation if the date is out of range of // strftime() or if we use non standard specificators #ifdef HAVE_STRFTIME + time_t time = GetTicks(); + if ( (time != (time_t)-1) && !wxStrstr(format, _T("%l")) ) { // use strftime()