summaryrefslogtreecommitdiffstats
path: root/calendar/kde
diff options
context:
space:
mode:
authorPraveen Arimbrathodiyil <pravi.a@gmail.com>2009-01-05 01:37:03 -0800
committerPraveen Arimbrathodiyil <pravi.a@gmail.com>2009-01-05 01:37:03 -0800
commitdf2fdef3c511667d0cf9432313ef2be7395f1740 (patch)
tree0694112710fa6064079bf74f32728588b88ce8c6 /calendar/kde
parent1e5de879c832c3fffe9c09513d47a1a0ea562941 (diff)
downloadRachana.git-df2fdef3c511667d0cf9432313ef2be7395f1740.tar.gz
Rachana.git-df2fdef3c511667d0cf9432313ef2be7395f1740.tar.xz
Rachana.git-df2fdef3c511667d0cf9432313ef2be7395f1740.zip
added README, testcases.
Diffstat (limited to 'calendar/kde')
-rw-r--r--calendar/kde/README14
-rw-r--r--calendar/kde/kdelibs/kdecore/date/kcalendarsystemindic.cpp47
-rw-r--r--calendar/kde/kdelibs/kdecore/date/kcalendarsystemindic.h2
-rw-r--r--calendar/kde/kdelibs/kdecore/tests/kcalendartest.cpp85
-rw-r--r--calendar/kde/kdelibs/kdecore/tests/kcalendartest.h54
5 files changed, 183 insertions, 19 deletions
diff --git a/calendar/kde/README b/calendar/kde/README
new file mode 100644
index 0000000..26dc9e5
--- /dev/null
+++ b/calendar/kde/README
@@ -0,0 +1,14 @@
+Follow the steps given below to build the code.
+
+1. Build KDE 4 from source
+ - use kdesvn-build from http://kdesvn-build.kde.org/
+ - build only kdelibs and kdebase
+ - take qt from your distro (if older build qt-copy as well)
+2. Sync files from smc git to kde source tree
+ - rsync -av --progress <path-to-smc-git>/calendar/kde/* <path-to-kdesvn-tree>
+3. Run tests
+ - go to <path-to-kdesvn-tree>/build/kdelibs
+ - make kcalendartest
+ - run kdecore/tests/kcalendartest
+ - kdecore/tests/kcalendartest -functions (for listing available tests)
+ - kdecore/tests/kcalendartest testName -v2 (for running named test with detailed output)
diff --git a/calendar/kde/kdelibs/kdecore/date/kcalendarsystemindic.cpp b/calendar/kde/kdelibs/kdecore/date/kcalendarsystemindic.cpp
index b928d09..fe2addf 100644
--- a/calendar/kde/kdelibs/kdecore/date/kcalendarsystemindic.cpp
+++ b/calendar/kde/kdelibs/kdecore/date/kcalendarsystemindic.cpp
@@ -47,9 +47,7 @@ public:
static double SakaToJD(int year, int month, int date);
};
-int KCalendarSystemSaka::getMonthLength(int greg_year, int greg_month)
-{
-}
+
/*
* This routine converts an Indian date to the corresponding Julian date"
* year The year in Saka Era according to Indian calendar.
@@ -167,6 +165,8 @@ int KCalendarSystemIndic::year( const QDate &date ) const
}
return saka_year;
+
+ return KCalendarSystem::year( date );
}
int KCalendarSystemIndic::month( const QDate &date ) const
@@ -231,15 +231,12 @@ int KCalendarSystemIndic::day( const QDate &date ) const
QDate KCalendarSystemIndic::addYears( const QDate &date, int nyears ) const
{
- QDate result = date;
- int y = year( date ) + nyears;
- setYMD( result, y, month( date ), day( date ) );
- return result;
+ return KCalendarSystem::addYears( date, nyears);
}
QDate KCalendarSystemIndic::addMonths( const QDate &date, int nmonths ) const
{
-QDate result = date;
+/*QDate result = date;
while ( nmonths > 0 ) {
result = addDays( result, daysInMonth( result ) );
@@ -255,6 +252,8 @@ QDate result = date;
}
return result;
+ */
+ return KCalendarSystem::addMonths(date, nmonths);
}
QDate KCalendarSystemIndic::addDays( const QDate &date, int ndays ) const
@@ -270,12 +269,14 @@ int KCalendarSystemIndic::monthsInYear( const QDate &date ) const
int KCalendarSystemIndic::weeksInYear( const QDate &date ) const
{
- return KCalendarSystem::weeksInYear( date );
+ Q_UNUSED( date )
+ return 52;
}
int KCalendarSystemIndic::weeksInYear( int year ) const
{
- return KCalendarSystem::weeksInYear( year );
+ Q_UNUSED( year )
+ return 52;
}
int KCalendarSystemIndic::daysInYear( const QDate &date ) const
@@ -286,8 +287,9 @@ int KCalendarSystemIndic::daysInYear( const QDate &date ) const
int KCalendarSystemIndic::daysInMonth( const QDate &date ) const
{
int month, day;
- month=date.month();
- day=date.day();
+// month=date.month();
+ month=KCalendarSystemIndic::month( date );
+ day=KCalendarSystemIndic::day( date );
if (month > 6)
return 30;
if (month>1)
@@ -305,11 +307,15 @@ int KCalendarSystemIndic::daysInWeek( const QDate &date ) const
int KCalendarSystemIndic::dayOfYear( const QDate &date ) const
{
-QDate first;
- setYMD( first, year( date ), 1, 1 );
-
- return first.daysTo( date ) + 1;
-
+ int days;
+ int month=KCalendarSystemIndic::month( date );
+ if (month < 7 )
+ days=(month-1) * 31 + KCalendarSystemIndic::day( date );
+ else
+ days= 6 * 31 + (month - 7) * 30 + KCalendarSystemIndic::day( date );
+ if ( ! KCalendarSystem::isLeapYear(date.year()) && month !=1 )
+ --days;
+ return days;
}
int KCalendarSystemIndic::dayOfWeek( const QDate &date ) const
@@ -319,7 +325,12 @@ int KCalendarSystemIndic::dayOfWeek( const QDate &date ) const
int KCalendarSystemIndic::weekNumber( const QDate &date, int * yearNum ) const
{
- return KCalendarSystem::weekNumber( date, yearNum );
+ int days, weeks;
+ days=KCalendarSystemIndic::dayOfYear( date );
+ weeks = days/7;
+ if (days%7)
+ ++weeks;
+ return weeks;
}
bool KCalendarSystemIndic::isLeapYear( int year ) const
diff --git a/calendar/kde/kdelibs/kdecore/date/kcalendarsystemindic.h b/calendar/kde/kdelibs/kdecore/date/kcalendarsystemindic.h
index 510d6c5..716313e 100644
--- a/calendar/kde/kdelibs/kdecore/date/kcalendarsystemindic.h
+++ b/calendar/kde/kdelibs/kdecore/date/kcalendarsystemindic.h
@@ -73,7 +73,7 @@ public:
virtual int dayOfYear( const QDate &date ) const;
virtual int dayOfWeek( const QDate &date ) const;
- virtual int weekNumber( const QDate &date, int *yearNum = 0 ) const;
+ virtual int weekNumber( const QDate &date, int * yearNum =0 ) const;
virtual bool isLeapYear( int year ) const;
virtual bool isLeapYear( const QDate &date ) const;
diff --git a/calendar/kde/kdelibs/kdecore/tests/kcalendartest.cpp b/calendar/kde/kdelibs/kdecore/tests/kcalendartest.cpp
index 1f30b5e..fc775b2 100644
--- a/calendar/kde/kdelibs/kdecore/tests/kcalendartest.cpp
+++ b/calendar/kde/kdelibs/kdecore/tests/kcalendartest.cpp
@@ -32,11 +32,13 @@ void KCalendarTest::testTypes()
QVERIFY( lst.contains("hebrew") );
QVERIFY( lst.contains("hijri") );
QVERIFY( lst.contains("jalali") );
+ QVERIFY( lst.contains("indic") );
QCOMPARE( KCalendarSystem::calendarLabel("gregorian"), QString("Gregorian") );
QCOMPARE( KCalendarSystem::calendarLabel("hebrew"), QString("Hebrew") );
QCOMPARE( KCalendarSystem::calendarLabel("hijri"), QString("Hijri") );
QCOMPARE( KCalendarSystem::calendarLabel("jalali"), QString("Jalali") );
+ QCOMPARE( KCalendarSystem::calendarLabel("indic"), QString("Indic") );
}
void KCalendarTest::testLocale()
@@ -53,6 +55,9 @@ void KCalendarTest::testLocale()
KGlobal::locale()->setCalendar("jalali");
calendar = KGlobal::locale()->calendar();
QCOMPARE( calendar->calendarType(), QString("jalali") );
+ KGlobal::locale()->setCalendar("indic");
+ calendar = KGlobal::locale()->calendar();
+ QCOMPARE( calendar->calendarType(), QString("indic") );
}
void KCalendarTest::testGregorian()
@@ -114,6 +119,39 @@ void KCalendarTest::testHijri()
QCOMPARE( newDate.day(), 30 );
}
+void KCalendarTest::testIndic()
+{
+ const KCalendarSystem *calendar = KCalendarSystem::create(QString( "indic" ));
+ QDate testDate( 2005, 9, 10 );
+
+ QCOMPARE( calendar->daysInYear(testDate), 365 );
+ QCOMPARE( calendar->daysInMonth(testDate), 31 );
+ QCOMPARE( calendar->weeksInYear(testDate.year()), 52 );
+ QCOMPARE( calendar->weekNumber(testDate), 25 );
+ QCOMPARE( calendar->dayOfYear(testDate), 173 );
+
+ QVERIFY( calendar->setYMD( testDate, 2000, 3, 1 ) );
+// Not sure if it should return Saka year.
+ QCOMPARE( calendar->year(testDate), 1921 );
+ QCOMPARE( calendar->month(testDate), 12 );
+ QCOMPARE( calendar->day(testDate), 11 );
+
+ QDate newDate = calendar->addYears(testDate, 4);
+// doubt
+ QCOMPARE( newDate.year(), 2004 );
+ QCOMPARE( calendar->daysInYear(newDate), 365 );
+
+ newDate = calendar->addMonths( testDate, -4 );
+ QCOMPARE( newDate.year(), 1999 );
+ QCOMPARE( newDate.month(), 11 );
+ QCOMPARE( newDate.day(), 1 );
+
+ newDate = calendar->addDays( newDate, 20 );
+ QCOMPARE( newDate.year(), 1999 );
+ QCOMPARE( newDate.month(), 11 );
+ QCOMPARE( newDate.day(), 21 );
+}
+
void KCalendarTest::testGregorianBasic()
{
@@ -264,6 +302,53 @@ void KCalendarTest::testJalaliBasic()
QCOMPARE( calendar->isSolar(), true );
}
+
+
+// Indic Calendar System
+
+void KCalendarTest::testIndicBasic()
+{
+ const KCalendarSystem *calendar = KCalendarSystem::create(QString( "jalali" ));
+
+ QCOMPARE( calendar->calendarType(), QString("jalali") );
+ QCOMPARE( KCalendarSystem::calendarLabel( QString("jalali") ), QString("Jalali") );
+
+ QCOMPARE( calendar->epoch(), QDate( 622, 3, 19 ) );
+ QCOMPARE( calendar->earliestValidDate(), QDate( 622, 3, 19 ) );
+ QCOMPARE( calendar->latestValidDate(), QDate( 10621, 3, 17 ) );
+
+ testValid( calendar, 10000, 13, 32, QDate( 1, 1, 1 ) );
+
+ QCOMPARE( calendar->isLeapYear( 1386 ), false );
+ QCOMPARE( calendar->isLeapYear( 1387 ), true );
+ QCOMPARE( calendar->isLeapYear( QDate( 2008, 1, 1 ) ), false );
+ QEXPECT_FAIL("", "Not working right, 2009-01-01 should be 1387, verify", Continue);
+ QCOMPARE( calendar->isLeapYear( QDate( 2009, 1, 1 ) ), true );
+
+ QCOMPARE( calendar->daysInWeek( QDate( 2007, 1, 1 ) ), 7 );
+ QCOMPARE( calendar->monthsInYear( QDate( 2007, 1, 1 ) ), 12 );
+
+ testYear( calendar, QDate( 2005, 8, 31 ), 1384, QString("84"), QString("1384") );
+ testMonth( calendar, QDate( 2005, 8, 31 ), 6, QString("6"), QString("06") );
+ testDay( calendar, QDate( 2005, 8, 31 ), 9, QString("9"), QString("09") );
+
+ testWeekDayName( calendar, 3, QDate( 2005, 8, 31 ),
+ QString("4sh"), QString("Chahar shanbe") );
+ testMonthName( calendar, 6, 1384, QDate( 2005, 8, 31 ),
+ QString("Sha"), QString("Shahrivar"),
+ QString("of Sha"), QString("of Shahrivar") );
+
+ QCOMPARE( calendar->monthsInYear( QDate( 2005, 8, 31 ) ), 12 );
+
+ QCOMPARE( calendar->weekStartDay(), 1 );
+ QCOMPARE( calendar->weekDayOfPray(), 5 );
+
+ QCOMPARE( calendar->isProleptic(), false );
+ QCOMPARE( calendar->isLunar(), false );
+ QCOMPARE( calendar->isLunisolar(), false );
+ QCOMPARE( calendar->isSolar(), true );
+}
+
void KCalendarTest::testJalaliYmd()
{
const KCalendarSystem *calendar = KCalendarSystem::create( QString("jalali") );
diff --git a/calendar/kde/kdelibs/kdecore/tests/kcalendartest.h b/calendar/kde/kdelibs/kdecore/tests/kcalendartest.h
new file mode 100644
index 0000000..6a51dd6
--- /dev/null
+++ b/calendar/kde/kdelibs/kdecore/tests/kcalendartest.h
@@ -0,0 +1,54 @@
+#ifndef KCALENDARTEST_H
+#define KCALENDARTEST_H
+
+#include <QtCore/QObject>
+
+class KCalendarTest : public QObject
+{
+ Q_OBJECT
+
+protected:
+ void testValid( const KCalendarSystem *calendar, int highInvalidYear,
+ int highInvalidMonth, int highInvalidDay, QDate invalidDate );
+ void testYear( const KCalendarSystem *calendar, QDate date,
+ int year, QString shortString, QString longString );
+ void testMonth( const KCalendarSystem *calendar, QDate date,
+ int month, QString shortString, QString longString );
+ void testDay( const KCalendarSystem *calendar, QDate date,
+ int day, QString shortString, QString longString );
+ void testYmd( const KCalendarSystem *calendar, int y, int m, int d, int jd );
+ void testWeekDayName( const KCalendarSystem *calendar, int weekDay, QDate date,
+ QString shortName, QString longName );
+ void testMonthName( const KCalendarSystem *calendar, int month, int year, QDate date,
+ QString shortName, QString longName,
+ QString shortNamePossessive, QString longNamePossessive );
+ void testGregorianCompareQDate( const KCalendarSystem *calendar, int year, int month, int day );
+ void testJalaliCompare();
+ void testCompare( const KCalendarSystem *calendar, int year, int month, int day );
+ void testQDateYMD( const KCalendarSystem *calendar, int y, int m, int d );
+
+private Q_SLOTS:
+ void testTypes();
+ void testLocale();
+ void testGregorian();
+ void testHijri();
+ void testIndic();
+ void testGregorianBasic();
+ void testGregorianYmd();
+ void testHijriBasic();
+ void testHijriYmd();
+ void testJalaliBasic();
+ void testIndicBasic();
+ void testJalaliYmd();
+ void testQDateYearMonthDay();
+ void testQDateAddYears();
+ void testQDateAddMonths();
+ void testQDateAddDays();
+ void testQDateDaysInYear();
+ void testQDateDaysInMonth();
+ void testQDateDayOfYear();
+ void testQDateDayOfWeek();
+ void testQDateIsLeapYear();
+};
+
+#endif