Author: axeld Date: 2011-04-01 17:51:08 +0200 (Fri, 01 Apr 2011) New Revision: 41161 Changeset: https://dev.haiku-os.org/changeset/41161 Modified: haiku/trunk/src/apps/deskbar/CalendarMenuWindow.cpp haiku/trunk/src/apps/deskbar/CalendarMenuWindow.h Log: * Followed korli's suggestion and use the existing BDate API instead, thanks! Modified: haiku/trunk/src/apps/deskbar/CalendarMenuWindow.cpp =================================================================== --- haiku/trunk/src/apps/deskbar/CalendarMenuWindow.cpp 2011-04-01 15:07:00 UTC (rev 41160) +++ haiku/trunk/src/apps/deskbar/CalendarMenuWindow.cpp 2011-04-01 15:51:08 UTC (rev 41161) @@ -204,7 +204,7 @@ message->FindInt32("month", &month); message->FindInt32("year", &year); - _UpdateDate(year, month, day); + _UpdateDate(BDate(year, month, day)); break; } @@ -212,8 +212,8 @@ case kMonthUpMessage: { BDate date = fCalendarView->Date(); - _UpdateDate(date.Year(), date.Month() - + (kMonthDownMessage == message->what ? -1 : 1), date.Day()); + date.AddMonths(kMonthDownMessage == message->what ? -1 : 1); + _UpdateDate(date); break; } @@ -221,9 +221,8 @@ case kYearUpMessage: { BDate date = fCalendarView->Date(); - _UpdateDate( - date.Year() + (kYearDownMessage == message->what ? -1 : 1), - date.Month(), date.Day()); + date.AddYears(kYearDownMessage == message->what ? -1 : 1); + _UpdateDate(date); break; } @@ -235,31 +234,6 @@ void -CalendarMenuWindow::_UpdateDate(int32 year, int32 month, int32 day) -{ - if (day < 1) { - month--; - day = 31; - } - if (month < 1) { - year--; - month = 12; - } - if (month > 12) { - year++; - month = 1; - } - - BDate date(year, month, 1); - // Alternatively, we could choose the day at the same position instead - if (day > date.DaysInMonth()) - day = date.DaysInMonth(); - - _UpdateDate(BDate(year, month, day)); -} - - -void CalendarMenuWindow::_UpdateDate(const BDate& date) { if (!date.IsValid()) Modified: haiku/trunk/src/apps/deskbar/CalendarMenuWindow.h =================================================================== --- haiku/trunk/src/apps/deskbar/CalendarMenuWindow.h 2011-04-01 15:07:00 UTC (rev 41160) +++ haiku/trunk/src/apps/deskbar/CalendarMenuWindow.h 2011-04-01 15:51:08 UTC (rev 41161) @@ -31,7 +31,6 @@ virtual void MessageReceived(BMessage* message); private: - void _UpdateDate(int32 year, int32 month, int32 day); void _UpdateDate(const BDate& date); BButton* _SetupButton(const char* label, uint32 what, float height);