Simplified initialization of week days for a month.

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@27243 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Michael Pfeiffer 2008-08-30 16:13:05 +00:00
parent c984125a2d
commit f0932941dd
3 changed files with 34 additions and 15 deletions

View File

@ -50,6 +50,8 @@ class BDate {
static BDate CurrentDate(time_type type);
bool SetDate(int32 year, int32 month, int32 day);
void AddDays(int32 days);
int32 Day() const;
int32 Year() const;

View File

@ -909,7 +909,6 @@ BCalendarView::_SetupDayNumbers()
}
}
void
BCalendarView::_SetupWeekNumbers()
{
@ -917,22 +916,13 @@ BCalendarView::_SetupWeekNumbers()
if (!date.IsValid())
return;
int32 weekNumber = date.WeekNumber();
// date on Thursday determines week number (ISO 8601)
date.AddDays(4 - date.DayOfWeek());
for (int32 row = 0; row < 6; ++row) {
fWeekNumbers[row].SetTo("");
fWeekNumbers[row] << weekNumber++;
}
if (fMonth == 12) {
date.SetDate(fYear, fMonth, 29);
weekNumber = date.WeekNumber();
fWeekNumbers[4].SetTo("");
fWeekNumbers[5].SetTo("");
fWeekNumbers[4] << weekNumber;
fWeekNumbers[5] << ((weekNumber != 1) ? 1L : 2L);
fWeekNumbers[row] << date.WeekNumber();
date.AddDays(7);
}
}

View File

@ -175,6 +175,33 @@ BDate::SetDate(int32 year, int32 month, int32 day)
}
void
BDate::AddDays(int32 days)
{
days += Day();
if (days > 0) {
while (days > DaysInMonth()) {
days -= DaysInMonth();
fMonth ++;
if (fMonth == 13) {
fMonth = 1;
fYear ++;
}
}
} else {
while (days <= 0) {
fMonth --;
if (fMonth == 0) {
fMonth = 12;
fYear --;
}
days += DaysInMonth();
}
}
fDay = days;
}
int32
BDate::Day() const
{