summaryrefslogtreecommitdiffstats
path: root/calendar
diff options
context:
space:
mode:
authorPraveen Arimbrathodiyil <pravi.a@gmail.com>2009-01-11 18:08:06 -0800
committerPraveen Arimbrathodiyil <pravi.a@gmail.com>2009-01-11 18:08:06 -0800
commitc1eec24329f710edba91c13d6f041065727742d9 (patch)
tree9b7f85b1ecbf83ffcb498d717c42e7465a7bfaf4 /calendar
parent06f3f2ec5d5c01e2a457f36bae9f188cda7f2b1b (diff)
downloadRachana.git-c1eec24329f710edba91c13d6f041065727742d9.tar.gz
Rachana.git-c1eec24329f710edba91c13d6f041065727742d9.tar.xz
Rachana.git-c1eec24329f710edba91c13d6f041065727742d9.zip
addMonths reimplemented.
Diffstat (limited to 'calendar')
-rw-r--r--calendar/kde/kdelibs/kdecore/date/kcalendarsystemindic.cpp35
1 files changed, 16 insertions, 19 deletions
diff --git a/calendar/kde/kdelibs/kdecore/date/kcalendarsystemindic.cpp b/calendar/kde/kdelibs/kdecore/date/kcalendarsystemindic.cpp
index c1201db..a47a85d 100644
--- a/calendar/kde/kdelibs/kdecore/date/kcalendarsystemindic.cpp
+++ b/calendar/kde/kdelibs/kdecore/date/kcalendarsystemindic.cpp
@@ -238,7 +238,6 @@ int KCalendarSystemIndic::day( const QDate &date ) const
QDate KCalendarSystemIndic::addYears( const QDate &date, int nyears ) const
{
int saka_year, saka_month, saka_day;
- kDebug() << "year, month, day" << date.year() << date.month() << date.day();
saka_year = KCalendarSystemIndic::year( date );
saka_month = KCalendarSystemIndic::month( date );
saka_day = KCalendarSystemIndic::day( date );
@@ -247,24 +246,22 @@ QDate KCalendarSystemIndic::addYears( const QDate &date, int nyears ) const
QDate KCalendarSystemIndic::addMonths( const QDate &date, int nmonths ) const
{
-/*QDate result = date;
-
- while ( nmonths > 0 ) {
- result = addDays( result, daysInMonth( result ) );
- --nmonths;
- }
-
- while ( nmonths < 0 ) {
- // get the number of days in the previous month to be consistent with
- // addMonths where nmonths > 0
- int nDaysInMonth = daysInMonth( addDays( result, -day( result ) ) );
- result = addDays( result, -nDaysInMonth );
- ++nmonths;
- }
-
- return result;
- */
- return KCalendarSystem::addMonths(date, nmonths);
+ int saka_year, saka_month, saka_day, change;
+ saka_year = KCalendarSystemIndic::year( date );
+ saka_month = KCalendarSystemIndic::month( date );
+ saka_day = KCalendarSystemIndic::day( date );
+ change = saka_month + nmonths;
+ if (change < 0 ) {
+ saka_year -= ( abs(change)/12 + 1 );
+ saka_month = 12 + change%12;
+ }
+ else if (change >= 12) {
+ saka_year += (change/12)+1;
+ saka_month = change%12;
+ } else {
+ saka_month += nmonths;
+ }
+ return QDate::fromJulianDay( KCalendarSystemSaka::SakaToJD(saka_year, saka_month, saka_day) );
}
QDate KCalendarSystemIndic::addDays( const QDate &date, int ndays ) const