calendarsystem Library API Documentation

kcalendarsystem.cpp

00001 // Gregorian calendar system implementation factory for creation of kde calendar
00002 // systems.
00003 // Also default gregorian and factory classes
00004 // Carlos Moro, <cfmoro@correo.uniovi.es>
00005 // GNU-GPL v.2
00006 
00007 #include <qdatetime.h>
00008 #include <qstring.h>
00009 
00010 #include <kglobal.h>
00011 #include <klocale.h>
00012 #include <kdebug.h>
00013 
00014 #include "kcalendarsystemhijri.h"
00015 
00016 #include "kcalendarsystem.h"
00017 
00018 KCalendarSystemGregorian::KCalendarSystemGregorian()
00019 {
00020   kdDebug(5400) << "\nCreated gregorian calendar" << endl;
00021 }
00022 
00023 KCalendarSystemGregorian::~KCalendarSystemGregorian()
00024 {
00025 }
00026 
00027 QString KCalendarSystemGregorian::monthName(const QDate& date, bool shortName)
00028 {
00029   kdDebug(5400) << "Gregorian month..." << endl;
00030   QString q = KGlobal::locale()->monthName(date.month(), shortName) ;
00031 
00032   return q;
00033 }
00034 
00035 QString KCalendarSystemGregorian::formatDate(const QDate& date)
00036 {
00037   kdDebug(5400) << "Gregorian format date..." << endl;
00038   QString q = KGlobal::locale()->formatDate(date,true) ;
00039 
00040   return q;
00041 }
00042 
00043 int KCalendarSystemGregorian::year(const QDate& date)
00044 {
00045   kdDebug(5400) << "Gregorian year..." <<  endl;
00046   return date.year();
00047 }
00048 
00049 void KCalendarSystemGregorian::nextMonthDate(QDate& temp)
00050 {
00051   kdDebug(5400) << "Gregorian next month date..." << endl;
00052   int day = temp.day();
00053   if(temp.month()==12) {
00054     temp.setYMD(temp.year()+1, 1, 1);
00055   } else {
00056     temp.setYMD(temp.year(), temp.month()+1, 1);
00057   }
00058 
00059   if(temp.daysInMonth()<day) {
00060     temp.setYMD(temp.year(), temp.month(), temp.daysInMonth());
00061   } else {
00062     temp.setYMD(temp.year(), temp.month(), day);
00063   }
00064 }
00065 
00066 void KCalendarSystemGregorian::previousMonthDate(QDate& temp)
00067 {
00068   kdDebug(5400) << "Gregorian previous month date..." << endl;
00069   
00070   int day = temp.day();
00071   
00072   if(temp.month()==1) {
00073     temp.setYMD(temp.year()-1, 12, 1);
00074   } else {
00075     temp.setYMD(temp.year(), temp.month()-1, 1);
00076   }
00077   if(temp.daysInMonth()<day) {
00078     temp.setYMD(temp.year(), temp.month(), temp.daysInMonth());
00079   } else {
00080     temp.setYMD(temp.year(), temp.month(), day);
00081   }
00082 }
00083 
00084 
00085 void KCalendarSystemGregorian::nextYearDate(QDate& temp)
00086 {
00087   kdDebug(5400) << "Gregorian next year date..." << endl;
00088   int day = temp.day();
00089   temp.setYMD(temp.year()+1, temp.month(), 1);
00090   if(temp.daysInMonth()<day) {
00091     temp.setYMD(temp.year(), temp.month(), temp.daysInMonth());
00092   } else {
00093     temp.setYMD(temp.year(), temp.month(), day);
00094   }
00095 }
00096 
00097 
00098 void KCalendarSystemGregorian::previousYearDate(QDate& temp)
00099 {
00100   kdDebug(5400) << "Gregorian previous year date..." << endl;
00101   int day = temp.day();
00102   temp.setYMD(temp.year()-1, temp.month(), 1);
00103   if(temp.daysInMonth()<day) {
00104     temp.setYMD(temp.year(), temp.month(), temp.daysInMonth());
00105   } else {
00106     temp.setYMD(temp.year(), temp.month(), day);
00107   }
00108 }
00109 
00110 
00111 int KCalendarSystemGregorian::monthsInYear( int )
00112 {
00113   kdDebug(5400) << "Gregorian monthsInYear" << endl;
00114 
00115   return 12;
00116 }
00117 
00118 QString KCalendarSystemGregorian::monthName(int month)
00119 {
00120   kdDebug(5400) << "Gregorian getMonthName" << endl;
00121 
00122   return KGlobal::locale()->monthName(month, false);
00123 }
00124 
00125 
00126 void KCalendarSystemGregorian::constructDateInMonth(QDate& date, int month)
00127 {
00128   int day;
00129   day = date.day();
00130 
00131   date.setYMD(date.year(), month, 1);
00132   date.setYMD(date.year(), month, QMIN(day, date.daysInMonth()));
00133 
00134   kdDebug(5400) << "Gregorian constructDateInMonth" << endl;
00135 }
00136 
00137 void KCalendarSystemGregorian::constructDateInYear(QDate& date, int year)
00138 {
00139   int day;
00140   day = date.day();
00141 
00142   date.setYMD(year, date.month(), 1);
00143   date.setYMD(year, date.month(), QMIN(day, date.daysInMonth()));
00144 
00145   kdDebug(5400) << "Gregorian constructDateInYear" << endl;
00146 }
00147 
00148 
00149 QDate KCalendarSystemGregorian::parseDate(QString text)
00150 {
00151   kdDebug(5400) << "Gregorian parseDate" << endl;
00152   return KGlobal::locale()->readDate(text);
00153 }
00154 
00155 
00156 QString KCalendarSystemGregorian::weekDayName(int col, bool shortName)
00157 {
00158   //kdDebug(5400) << "Gregorian wDayName" << endl;
00159   return KGlobal::locale()->weekDayName(col, shortName);
00160 }
00161 
00162 
00163 int KCalendarSystemGregorian::dayOfTheWeek(const QDate& date)
00164 {
00165   return date.dayOfWeek();
00166 }
00167 
00168 int KCalendarSystemGregorian::numberOfDaysInMonth(const QDate& date)
00169 {
00170   kdDebug(5400) << "Gregorian daysInMonth" << endl;
00171   return date.daysInMonth();
00172 }
00173 
00174 int KCalendarSystemGregorian::numberOfDaysPrevMonth(const QDate& date)
00175 {
00176   kdDebug(5400) << "Gregorian daysinprevmonth" << endl;
00177   QDate temp;
00178   if(date.month() == 1)
00179   {
00180     temp.setYMD(date.year()-1, 12, 1);
00181   } else {
00182     temp.setYMD(date.year(), date.month()-1, 1);
00183   }
00184   return temp.daysInMonth();
00185 }
00186 
00187 int KCalendarSystemGregorian::maxValidYear()
00188 {
00189   return 8000; // QDate limit
00190 }
00191 
00192 int KCalendarSystemGregorian::day(const QDate& date)
00193 {
00194   return date.day();
00195 }
00196 
00197 int KCalendarSystemGregorian::month(const QDate& date)
00198 {
00199   return date.month();
00200 }
00201 
00202 int KCalendarSystemGregorian::numberOfDayInYear(const QDate& date)
00203 {
00204   return date.dayOfYear();
00205 }
00206 
00207 int KCalendarSystemGregorian::weekDayOfPray() {
00208    return 7; // sunday
00209 }
00210 
00211 void KCalendarSystemGregorian::printType()
00212 {
00213   kdDebug(5400) << "It's Gregorian!" << endl;
00214 }
00215 
00216 
00217 QString KCalendarSystemFactory::calTy[] = { "gregorian", "hijri" };
00218 
00219 KCalendarSystemFactory::KCalendarSystemFactory()
00220 {
00221   kdDebug(5400) << "Created factory calendar" << endl;
00222 }
00223 
00224 KCalendarSystemFactory::~KCalendarSystemFactory()
00225 {
00226 }
00227 
00228 KCalendarSystem *KCalendarSystemFactory::create( const QString &calType )
00229 {
00230   if( calType == calTy[1] )
00231     return  new KCalendarSystemHijri();
00232   else
00233     return  new KCalendarSystemGregorian();
00234 }
KDE Logo
This file is part of the documentation for kdelibs Version 3.1.4.
Documentation copyright © 1996-2002 the KDE developers.
Generated on Sat Oct 18 02:46:51 2003 by doxygen 1.3.4 written by Dimitri van Heesch, © 1997-2001