X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/1fcca711af0784b266f5387ab0b74a9b9ba97f7f..8cf30134cd3881c0da18ef348206215f5b62bcb7:/src/common/datetime.cpp?ds=sidebyside diff --git a/src/common/datetime.cpp b/src/common/datetime.cpp index 3d131c9503..16ccbc4094 100644 --- a/src/common/datetime.cpp +++ b/src/common/datetime.cpp @@ -376,11 +376,14 @@ wxDateTime::Country wxDateTime::ms_country = wxDateTime::Country_Unknown; // debugger helper: shows what the date really is #ifdef __WXDEBUG__ -extern const wxChar *wxDumpDate(const wxDateTime* dt) +extern const char *wxDumpDate(const wxDateTime* dt) { - static wxChar buf[128]; + static char buf[128]; - wxStrcpy(buf, dt->Format(_T("%Y-%m-%d (%a) %H:%M:%S"))); + wxString fmt(dt->Format("%Y-%m-%d (%a) %H:%M:%S")); + wxStrlcpy(buf, + (fmt + " (" + dt->GetValue().ToString() + " ticks)").ToAscii(), + WXSIZEOF(buf)); return buf; } @@ -485,8 +488,10 @@ static wxString CallStrftime(const wxString& format, const tm* tm) if ( !wxStrftime(buf, WXSIZEOF(buf), format, tm) ) { - // buffer is too small? + // if the format is valid, buffer must be too small? wxFAIL_MSG(_T("strftime() failed")); + + buf[0] = '\0'; } s = buf; @@ -2845,8 +2850,9 @@ wxDateTime::ParseRfc822Date(const wxString& date, wxString::const_iterator *end) min = (wxDateTime_t)(min + *p++ - _T('0')); wxDateTime_t sec = 0; - if ( *p++ == _T(':') ) + if ( *p == _T(':') ) { + p++; if ( !wxIsdigit(*p) ) { return NULL; @@ -3662,6 +3668,11 @@ wxDateTime::ParseFormat(const wxString& date, Tm tm = tmDef; // set the date + if ( haveMon ) + { + tm.mon = mon; + } + if ( haveYear ) { tm.year = year; @@ -3670,16 +3681,15 @@ wxDateTime::ParseFormat(const wxString& date, // TODO we don't check here that the values are consistent, if both year // day and month/day were found, we just ignore the year day and we // also always ignore the week day - if ( haveMon && haveDay ) + if ( haveDay ) { - if ( mday > GetNumOfDaysInMonth(tm.year, mon) ) + if ( mday > GetNumOfDaysInMonth(tm.year, tm.mon) ) { wxLogDebug(_T("bad month day in wxDateTime::ParseFormat")); return NULL; } - tm.mon = mon; tm.mday = mday; } else if ( haveYDay ) @@ -4264,6 +4274,14 @@ enum TimeSpanPart // %l milliseconds (000 - 999) wxString wxTimeSpan::Format(const wxString& format) const { + // we deal with only positive time spans here and just add the sign in + // front for the negative ones + if ( IsNegative() ) + { + wxString str(Negate().Format(format)); + return "-" + str; + } + wxCHECK_MSG( !format.empty(), wxEmptyString, _T("NULL format in wxTimeSpan::Format") ); @@ -4335,13 +4353,6 @@ wxString wxTimeSpan::Format(const wxString& format) const n = GetHours(); if ( partBiggest < Part_Hour ) { - if ( n < 0 ) - { - // the sign has already been taken into account - // when outputting the biggest part - n = -n; - } - n %= HOURS_PER_DAY; } else @@ -4356,9 +4367,6 @@ wxString wxTimeSpan::Format(const wxString& format) const n = GetMilliseconds().ToLong(); if ( partBiggest < Part_MSec ) { - if ( n < 0 ) - n = -n; - n %= 1000; } //else: no need to reset partBiggest to Part_MSec, it is @@ -4371,9 +4379,6 @@ wxString wxTimeSpan::Format(const wxString& format) const n = GetMinutes(); if ( partBiggest < Part_Min ) { - if ( n < 0 ) - n = -n; - n %= MIN_PER_HOUR; } else @@ -4388,9 +4393,6 @@ wxString wxTimeSpan::Format(const wxString& format) const n = GetSeconds().ToLong(); if ( partBiggest < Part_Sec ) { - if ( n < 0 ) - n = -n; - n %= SEC_PER_MIN; } else @@ -4404,10 +4406,6 @@ wxString wxTimeSpan::Format(const wxString& format) const if ( digits ) { - // negative numbers need one extra position for '-' display - if ( n < 0 ) - digits++; - fmtPrefix << _T("0") << digits; } @@ -4588,4 +4586,30 @@ WXDLLIMPEXP_BASE void wxPrevWDay(wxDateTime::WeekDay& wd) : (wxDateTime::WeekDay)(wd - 1); } +#ifdef __WXMSW__ + +wxDateTime& wxDateTime::SetFromMSWSysTime(const SYSTEMTIME& st) +{ + return Set(st.wDay, + static_cast(wxDateTime::Jan + st.wMonth - 1), + st.wYear, + 0, 0, 0); +} + +void wxDateTime::GetAsMSWSysTime(SYSTEMTIME* st) const +{ + const wxDateTime::Tm tm(GetTm()); + + st->wYear = (WXWORD)tm.year; + st->wMonth = (WXWORD)(tm.mon - wxDateTime::Jan + 1); + st->wDay = tm.mday; + + st->wDayOfWeek = + st->wHour = + st->wMinute = + st->wSecond = + st->wMilliseconds = 0; +} +#endif // __WXMSW__ + #endif // wxUSE_DATETIME