Refactor WeekFlags processing into UseEffectiveWeekDayFlags()
Use the new GetFirstWeekDay() function rather than GetCountry() == USA to determine the first weekday.
This commit is contained in:
@@ -1145,6 +1145,9 @@ private:
|
|||||||
// functions
|
// functions
|
||||||
inline bool IsInStdRange() const;
|
inline bool IsInStdRange() const;
|
||||||
|
|
||||||
|
// assign the preferred first day of a week to flags, if necessary
|
||||||
|
void UseEffectiveWeekDayFlags(WeekFlags &flags) const;
|
||||||
|
|
||||||
// the internal representation of the time is the amount of milliseconds
|
// the internal representation of the time is the amount of milliseconds
|
||||||
// elapsed since the origin which is set by convention to the UNIX/C epoch
|
// elapsed since the origin which is set by convention to the UNIX/C epoch
|
||||||
// value: the midnight of January 1, 1970 (UTC)
|
// value: the midnight of January 1, 1970 (UTC)
|
||||||
|
@@ -1770,10 +1770,7 @@ wxDateTime& wxDateTime::SetToWeekDayInSameWeek(WeekDay weekday, WeekFlags flags)
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( flags == Default_First )
|
UseEffectiveWeekDayFlags(flags);
|
||||||
{
|
|
||||||
flags = GetCountry() == USA ? Sunday_First : Monday_First;
|
|
||||||
}
|
|
||||||
|
|
||||||
// the logic below based on comparing weekday and wdayThis works if Sun (0)
|
// 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
|
// is the first day in the week, but breaks down for Monday_First case so
|
||||||
@@ -1928,10 +1925,7 @@ wxDateTime::wxDateTime_t wxDateTime::GetDayOfYear(const TimeZone& tz) const
|
|||||||
wxDateTime::wxDateTime_t
|
wxDateTime::wxDateTime_t
|
||||||
wxDateTime::GetWeekOfYear(wxDateTime::WeekFlags flags, const TimeZone& tz) const
|
wxDateTime::GetWeekOfYear(wxDateTime::WeekFlags flags, const TimeZone& tz) const
|
||||||
{
|
{
|
||||||
if ( flags == Default_First )
|
UseEffectiveWeekDayFlags(flags);
|
||||||
{
|
|
||||||
flags = GetCountry() == USA ? Sunday_First : Monday_First;
|
|
||||||
}
|
|
||||||
|
|
||||||
Tm tm(GetTm(tz));
|
Tm tm(GetTm(tz));
|
||||||
wxDateTime_t nDayInYear = GetDayOfYearFromTm(tm);
|
wxDateTime_t nDayInYear = GetDayOfYearFromTm(tm);
|
||||||
@@ -2018,10 +2012,7 @@ wxDateTime::wxDateTime_t wxDateTime::GetWeekOfMonth(wxDateTime::WeekFlags flags,
|
|||||||
const wxDateTime dateFirst = wxDateTime(1, tm.mon, tm.year);
|
const wxDateTime dateFirst = wxDateTime(1, tm.mon, tm.year);
|
||||||
const wxDateTime::WeekDay wdFirst = dateFirst.GetWeekDay();
|
const wxDateTime::WeekDay wdFirst = dateFirst.GetWeekDay();
|
||||||
|
|
||||||
if ( flags == Default_First )
|
UseEffectiveWeekDayFlags(flags);
|
||||||
{
|
|
||||||
flags = GetCountry() == USA ? Sunday_First : Monday_First;
|
|
||||||
}
|
|
||||||
|
|
||||||
// compute offset of dateFirst from the beginning of the week
|
// compute offset of dateFirst from the beginning of the week
|
||||||
int firstOffset;
|
int firstOffset;
|
||||||
@@ -2134,6 +2125,16 @@ wxDateTime& wxDateTime::MakeFromTimezone(const TimeZone& tz, bool noDST)
|
|||||||
return Subtract(wxTimeSpan::Seconds(secDiff));
|
return Subtract(wxTimeSpan::Seconds(secDiff));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void wxDateTime::UseEffectiveWeekDayFlags(WeekFlags &flags) const
|
||||||
|
{
|
||||||
|
if ( flags == Default_First )
|
||||||
|
{
|
||||||
|
WeekDay firstDay;
|
||||||
|
GetFirstWeekDay(&firstDay);
|
||||||
|
flags = firstDay == Sun ? Sunday_First : Monday_First;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
// wxDateTimeHolidayAuthority and related classes
|
// wxDateTimeHolidayAuthority and related classes
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
|
Reference in New Issue
Block a user