From: Vadim Zeitlin Date: Thu, 17 Mar 2005 23:11:00 +0000 (+0000) Subject: fixed wxDateTime::SetToWeekDayInSameWeek(Sun, Monday_First) X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/af80bc9294f7a1137acb41faab78dbd77cbc8416 fixed wxDateTime::SetToWeekDayInSameWeek(Sun, Monday_First) git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@32875 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/docs/changes.txt b/docs/changes.txt index 80a5f3d2e0..1aaab5e802 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -9,8 +9,9 @@ All: - wxURI::GetUser() only returns the user name now, use GetUserInfo() to get user and password as in 2.5.4; wxURI::GetPassword() added. -- Added wxDebugReport class. +- added wxDebugReport class. - added wxTempFileOutputStream by Stas Sergeev +- fixed wxDateTime::SetToWeekDayInSameWeek(Sun, Monday_First) All (GUI): diff --git a/src/common/datetime.cpp b/src/common/datetime.cpp index 2a4491edaf..99a0e3cbec 100644 --- a/src/common/datetime.cpp +++ b/src/common/datetime.cpp @@ -1822,8 +1822,9 @@ wxDateTime& wxDateTime::SetToWeekDayInSameWeek(WeekDay weekday, WeekFlags flags) { wxDATETIME_CHECK( weekday != Inv_WeekDay, _T("invalid weekday") ); - int wdayThis = GetWeekDay(); - if ( weekday == wdayThis ) + int wdayDst = weekday, + wdayThis = GetWeekDay(); + if ( wdayDst == wdayThis ) { // nothing to do return *this; @@ -1837,21 +1838,23 @@ wxDateTime& wxDateTime::SetToWeekDayInSameWeek(WeekDay weekday, WeekFlags flags) // the logic below based on comparing weekday and wdayThis works if Sun (0) // is the first day in the week, but breaks down for Monday_First case so // we adjust the week days in this case - if( flags == Monday_First ) + if ( flags == Monday_First ) { if ( wdayThis == Sun ) wdayThis += 7; + if ( wdayDst == Sun ) + wdayDst += 7; } //else: Sunday_First, nothing to do // go forward or back in time to the day we want - if ( weekday < wdayThis ) + if ( wdayDst < wdayThis ) { - return Subtract(wxDateSpan::Days(wdayThis - weekday)); + return Subtract(wxDateSpan::Days(wdayThis - wdayDst)); } else // weekday > wdayThis { - return Add(wxDateSpan::Days(weekday - wdayThis)); + return Add(wxDateSpan::Days(wdayDst - wdayThis)); } }