[calendar] Always start counting weeks from Monday
Sometimes the first day in the grid can be Sunday, but the week number must always be counted from Monday in that week BUG: 349044 Change-Id: I903650fcaadb4fd78764ad6a8bb1e219261c791b FIXED-IN: 5.11
This commit is contained in:
parent
c60ca1b6a0
commit
bc0280ddb0
@ -261,8 +261,20 @@ void Calendar::updateData()
|
|||||||
}
|
}
|
||||||
const int numOfDaysInCalendar = m_dayList.count();
|
const int numOfDaysInCalendar = m_dayList.count();
|
||||||
|
|
||||||
|
// Week numbers are always counted from Mondays
|
||||||
|
// so find which index is Monday
|
||||||
|
int mondayOffset = 0;
|
||||||
|
if (!m_dayList.isEmpty()) {
|
||||||
|
const DayData &data = m_dayList.at(0);
|
||||||
|
QDate firstDay(data.yearNumber, data.monthNumber, data.dayNumber);
|
||||||
|
// If the first day is not already Monday, get offset for Monday
|
||||||
|
if (firstDay.dayOfWeek() != 1) {
|
||||||
|
mondayOffset = 8 - firstDay.dayOfWeek();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Fill weeksModel with the week numbers
|
// Fill weeksModel with the week numbers
|
||||||
for (int i = 0; i < numOfDaysInCalendar; i += 7) {
|
for (int i = mondayOffset; i < numOfDaysInCalendar; i += 7) {
|
||||||
const DayData &data = m_dayList.at(i);
|
const DayData &data = m_dayList.at(i);
|
||||||
m_weekList.append(QDate(data.yearNumber, data.monthNumber, data.dayNumber).weekNumber());
|
m_weekList.append(QDate(data.yearNumber, data.monthNumber, data.dayNumber).weekNumber());
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user