fixed several bugs in wxDateTime week number calculations which required passing WeekFlags argument to more functions
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_2_4_BRANCH@17621 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -1127,7 +1127,7 @@ This function returns the time representation in the ISO 8601 format
|
|||||||
|
|
||||||
\membersection{wxDateTime::SetToWeekDayInSameWeek}\label{wxdatetimesettoweekdayinsameweek}
|
\membersection{wxDateTime::SetToWeekDayInSameWeek}\label{wxdatetimesettoweekdayinsameweek}
|
||||||
|
|
||||||
\func{wxDateTime\&}{SetToWeekDayInSameWeek}{\param{WeekDay }{weekday}}
|
\func{wxDateTime\&}{SetToWeekDayInSameWeek}{\param{WeekDay }{weekday}, \param{WeekFlags}{flags = {\tt Monday\_First}}}
|
||||||
|
|
||||||
Adjusts the date so that it will still lie in the same week as before, but its
|
Adjusts the date so that it will still lie in the same week as before, but its
|
||||||
week day will be the given one.
|
week day will be the given one.
|
||||||
@@ -1136,9 +1136,9 @@ Returns the reference to the modified object itself.
|
|||||||
|
|
||||||
\membersection{wxDateTime::GetWeekDayInSameWeek}\label{wxdatetimegetweekdayinsameweek}
|
\membersection{wxDateTime::GetWeekDayInSameWeek}\label{wxdatetimegetweekdayinsameweek}
|
||||||
|
|
||||||
\constfunc{wxDateTime}{GetWeekDayInSameWeek}{\param{WeekDay }{weekday}}
|
\constfunc{wxDateTime}{GetWeekDayInSameWeek}{\param{WeekDay }{weekday}, \param{WeekFlags}{flags = {\tt Monday\_First}}}
|
||||||
|
|
||||||
Returns the copy of this object to which
|
Returns the copy of this object to which
|
||||||
\helpref{SetToWeekDayInSameWeek}{wxdatetimesettoweekdayinsameweek} was
|
\helpref{SetToWeekDayInSameWeek}{wxdatetimesettoweekdayinsameweek} was
|
||||||
applied.
|
applied.
|
||||||
|
|
||||||
@@ -1216,7 +1216,7 @@ Returns the copy of this object to which
|
|||||||
|
|
||||||
\membersection{wxDateTime::SetToTheWeek}\label{wxdatetimesettotheweek}
|
\membersection{wxDateTime::SetToTheWeek}\label{wxdatetimesettotheweek}
|
||||||
|
|
||||||
\func{bool}{SetToTheWeek}{\param{wxDateTime\_t }{numWeek}, \param{WeekDay }{weekday = Mon}}
|
\func{bool}{SetToTheWeek}{\param{wxDateTime\_t }{numWeek}, \param{WeekDay }{weekday = Mon}, \param{WeekFlags}{flags = {\tt Monday\_First}}}
|
||||||
|
|
||||||
Set the date to the given {\it weekday} in the week with given number
|
Set the date to the given {\it weekday} in the week with given number
|
||||||
{\it numWeek}. The number should be in range $1\ldots53$ and {\tt FALSE} will
|
{\it numWeek}. The number should be in range $1\ldots53$ and {\tt FALSE} will
|
||||||
@@ -1225,7 +1225,7 @@ date was changed successfully.
|
|||||||
|
|
||||||
\membersection{wxDateTime::GetWeek}\label{wxdatetimegetweek}
|
\membersection{wxDateTime::GetWeek}\label{wxdatetimegetweek}
|
||||||
|
|
||||||
\constfunc{wxDateTime}{GetWeek}{\param{wxDateTime\_t }{numWeek}, \param{WeekDay }{weekday = Mon}}
|
\constfunc{wxDateTime}{GetWeek}{\param{wxDateTime\_t }{numWeek}, \param{WeekDay }{weekday = Mon}, \param{WeekFlags}{flags = {\tt Monday\_First}}}
|
||||||
|
|
||||||
Returns the copy of this object to which
|
Returns the copy of this object to which
|
||||||
\helpref{SetToTheWeek}{wxdatetimesettotheweek} was applied.
|
\helpref{SetToTheWeek}{wxdatetimesettotheweek} was applied.
|
||||||
|
@@ -659,8 +659,10 @@ public:
|
|||||||
// ------------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
|
|
||||||
// set to the given week day in the same week as this one
|
// set to the given week day in the same week as this one
|
||||||
wxDateTime& SetToWeekDayInSameWeek(WeekDay weekday);
|
wxDateTime& SetToWeekDayInSameWeek(WeekDay weekday,
|
||||||
inline wxDateTime GetWeekDayInSameWeek(WeekDay weekday) const;
|
WeekFlags flags = Monday_First);
|
||||||
|
inline wxDateTime GetWeekDayInSameWeek(WeekDay weekday,
|
||||||
|
WeekFlags flags = Monday_First) const;
|
||||||
|
|
||||||
// set to the next week day following this one
|
// set to the next week day following this one
|
||||||
wxDateTime& SetToNextWeekDay(WeekDay weekday);
|
wxDateTime& SetToNextWeekDay(WeekDay weekday);
|
||||||
@@ -694,8 +696,12 @@ public:
|
|||||||
// sets the date to the given day of the given week in the year,
|
// sets the date to the given day of the given week in the year,
|
||||||
// returns TRUE on success and FALSE if given date doesn't exist (e.g.
|
// returns TRUE on success and FALSE if given date doesn't exist (e.g.
|
||||||
// numWeek is > 53)
|
// numWeek is > 53)
|
||||||
bool SetToTheWeek(wxDateTime_t numWeek, WeekDay weekday = Mon);
|
bool SetToTheWeek(wxDateTime_t numWeek,
|
||||||
inline wxDateTime GetWeek(wxDateTime_t numWeek, WeekDay weekday = Mon) const;
|
WeekDay weekday = Mon,
|
||||||
|
WeekFlags flags = Monday_First);
|
||||||
|
inline wxDateTime GetWeek(wxDateTime_t numWeek,
|
||||||
|
WeekDay weekday = Mon,
|
||||||
|
WeekFlags flags = Monday_First) const;
|
||||||
|
|
||||||
// sets the date to the last day of the given (or current) month or the
|
// sets the date to the last day of the given (or current) month or the
|
||||||
// given (or current) year
|
// given (or current) year
|
||||||
|
@@ -156,7 +156,8 @@ inline bool wxDateTime::SetToLastWeekDay(WeekDay weekday,
|
|||||||
return SetToWeekDay(weekday, -1, month, year);
|
return SetToWeekDay(weekday, -1, month, year);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline wxDateTime wxDateTime::GetWeekDayInSameWeek(WeekDay weekday) const
|
inline wxDateTime wxDateTime::GetWeekDayInSameWeek(WeekDay weekday,
|
||||||
|
WeekFlags flags) const
|
||||||
{
|
{
|
||||||
MODIFY_AND_RETURN( SetToWeekDayInSameWeek(weekday) );
|
MODIFY_AND_RETURN( SetToWeekDayInSameWeek(weekday) );
|
||||||
}
|
}
|
||||||
@@ -191,11 +192,12 @@ inline wxDateTime wxDateTime::GetLastWeekDay(WeekDay weekday,
|
|||||||
}
|
}
|
||||||
|
|
||||||
inline wxDateTime wxDateTime::GetWeek(wxDateTime_t numWeek,
|
inline wxDateTime wxDateTime::GetWeek(wxDateTime_t numWeek,
|
||||||
WeekDay weekday) const
|
WeekDay weekday,
|
||||||
|
WeekFlags flags) const
|
||||||
{
|
{
|
||||||
wxDateTime dt(*this);
|
wxDateTime dt(*this);
|
||||||
|
|
||||||
return dt.SetToTheWeek(numWeek, weekday) ? dt : wxInvalidDateTime;
|
return dt.SetToTheWeek(numWeek, weekday, flags) ? dt : wxInvalidDateTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline wxDateTime wxDateTime::GetLastMonthDay(Month month, int year) const
|
inline wxDateTime wxDateTime::GetLastMonthDay(Month month, int year) const
|
||||||
|
@@ -1494,13 +1494,18 @@ wxDateTime& wxDateTime::Add(const wxDateSpan& diff)
|
|||||||
// Weekday and monthday stuff
|
// Weekday and monthday stuff
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
bool wxDateTime::SetToTheWeek(wxDateTime_t numWeek, WeekDay weekday)
|
bool wxDateTime::SetToTheWeek(wxDateTime_t numWeek,
|
||||||
|
WeekDay weekday,
|
||||||
|
WeekFlags flags)
|
||||||
{
|
{
|
||||||
|
wxASSERT_MSG( numWeek > 0,
|
||||||
|
_T("invalid week number: weeks are counted from 1") );
|
||||||
|
|
||||||
int year = GetYear();
|
int year = GetYear();
|
||||||
|
|
||||||
// Jan 4 always lies in the 1st week of the year
|
// Jan 4 always lies in the 1st week of the year
|
||||||
Set(4, Jan, year);
|
Set(4, Jan, year);
|
||||||
SetToWeekDayInSameWeek(weekday) += wxDateSpan::Weeks(numWeek);
|
SetToWeekDayInSameWeek(weekday, flags) += wxDateSpan::Weeks(numWeek - 1);
|
||||||
|
|
||||||
if ( GetYear() != year )
|
if ( GetYear() != year )
|
||||||
{
|
{
|
||||||
@@ -1523,17 +1528,34 @@ wxDateTime& wxDateTime::SetToLastMonthDay(Month month,
|
|||||||
return Set(GetNumOfDaysInMonth(year, month), month, year);
|
return Set(GetNumOfDaysInMonth(year, month), month, year);
|
||||||
}
|
}
|
||||||
|
|
||||||
wxDateTime& wxDateTime::SetToWeekDayInSameWeek(WeekDay weekday)
|
wxDateTime& wxDateTime::SetToWeekDayInSameWeek(WeekDay weekday, WeekFlags flags)
|
||||||
{
|
{
|
||||||
wxDATETIME_CHECK( weekday != Inv_WeekDay, _T("invalid weekday") );
|
wxDATETIME_CHECK( weekday != Inv_WeekDay, _T("invalid weekday") );
|
||||||
|
|
||||||
WeekDay wdayThis = GetWeekDay();
|
int wdayThis = GetWeekDay();
|
||||||
if ( weekday == wdayThis )
|
if ( weekday == wdayThis )
|
||||||
{
|
{
|
||||||
// nothing to do
|
// nothing to do
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
else if ( weekday < wdayThis )
|
|
||||||
|
if ( flags == Default_First )
|
||||||
|
{
|
||||||
|
flags = GetCountry() == USA ? Sunday_First : Monday_First;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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 ( wdayThis == Sun )
|
||||||
|
wdayThis += 7;
|
||||||
|
}
|
||||||
|
//else: Sunday_First, nothing to do
|
||||||
|
|
||||||
|
// go forward or back in time to the day we want
|
||||||
|
if ( weekday < wdayThis )
|
||||||
{
|
{
|
||||||
return Subtract(wxDateSpan::Days(wdayThis - weekday));
|
return Subtract(wxDateSpan::Days(wdayThis - weekday));
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user