# kdecore Library API Documentation

Overview | Class Hierarchy | Classes | Classes (annotated) | Members | Namespaces | Source Files

# kcalendarsystemgregorian.cpp

    00001 /*
    00002    Copyright (c) 2002 Carlos Moro <cfmoro@correo.uniovi.es>
    00003    Copyright (c) 2002-2003 Hans Petter Bieker <bieker@kde.org>
    00004
    00005    This library is free software; you can redistribute it and/or
    00006    modify it under the terms of the GNU Library General Public
    00007    License as published by the Free Software Foundation; either
    00008    version 2 of the License, or (at your option) any later version.
    00009
    00010    This library is distributed in the hope that it will be useful,
    00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
    00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    00013    Library General Public License for more details.
    00014
    00015    You should have received a copy of the GNU Library General Public License
    00016    along with this library; see the file COPYING.LIB.  If not, write to
    00017    the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
    00018    Boston, MA 02111-1307, USA.
    00019 */
    00020
    00021 // Derived gregorian kde calendar class
    00022 // Just a schema.
    00023
    00024 #include <qdatetime.h>
    00025 #include <qstring.h>
    00026
    00027 #include <klocale.h>
    00028 #include <kdebug.h>
    00029
    00030 #include "kcalendarsystemgregorian.h"
    00031
    00032 KCalendarSystemGregorian::KCalendarSystemGregorian(const KLocale * locale)
    00033   : KCalendarSystem(locale)
    00034 {
    00035 }
    00036
    00037 KCalendarSystemGregorian::~KCalendarSystemGregorian()
    00038 {
    00039 }
    00040
    00041 int KCalendarSystemGregorian::year(const QDate& date) const
    00042 {
    00043   return date.year();
    00044 }
    00045
    00046 int KCalendarSystemGregorian::monthsInYear( const QDate & date ) const
    00047 {
    00048   Q_UNUSED( date )
    00049
    00050   return 12;
    00051 }
    00052
    00053 int KCalendarSystemGregorian::weeksInYear(int year) const
    00054 {
    00055   QDate temp;
    00056   temp.setYMD(year, 12, 31);
    00057
    00058   // If the last day of the year is in the first week, we have to check the
    00059   // week before
    00060   if ( temp.weekNumber() == 1 )
    00061     temp = temp.addDays(-7);
    00062
    00063   return temp.weekNumber();
    00064 }
    00065
    00066 int KCalendarSystemGregorian::weekNumber(const QDate& date,
    00067                                          int * yearNum) const
    00068 {
    00069   return date.weekNumber(yearNum);
    00070 }
    00071
    00072 QString KCalendarSystemGregorian::monthName(const QDate& date,
    00073                                             bool shortName) const
    00074 {
    00075   return monthName(month(date), year(date), shortName);
    00076 }
    00077
    00078 QString KCalendarSystemGregorian::monthNamePossessive(const QDate& date, bool shortName) const
    00079 {
    00080   return monthNamePossessive(month(date), year(date), shortName);
    00081 }
    00082
    00083 QString KCalendarSystemGregorian::monthName(int month, int year, bool shortName) const
    00084 {
    00085   Q_UNUSED(year);
    00086
    00087   if ( shortName )
    00088     switch ( month )
    00089       {
    00090       case 1:
    00091         return locale()->translate("January", "Jan");
    00092       case 2:
    00093         return locale()->translate("February", "Feb");
    00094       case 3:
    00095         return locale()->translate("March", "Mar");
    00096       case 4:
    00097         return locale()->translate("April", "Apr");
    00098       case 5:
    00099         return locale()->translate("May short", "May");
    00100       case 6:
    00101         return locale()->translate("June", "Jun");
    00102       case 7:
    00103         return locale()->translate("July", "Jul");
    00104       case 8:
    00105         return locale()->translate("August", "Aug");
    00106       case 9:
    00107         return locale()->translate("September", "Sep");
    00108       case 10:
    00109         return locale()->translate("October", "Oct");
    00110       case 11:
    00111         return locale()->translate("November", "Nov");
    00112       case 12:
    00113         return locale()->translate("December", "Dec");
    00114       }
    00115   else
    00116     switch ( month )
    00117       {
    00118       case 1:
    00119         return locale()->translate("January");
    00120       case 2:
    00121         return locale()->translate("February");
    00122       case 3:
    00123         return locale()->translate("March");
    00124       case 4:
    00125         return locale()->translate("April");
    00126       case 5:
    00127         return locale()->translate("May long", "May");
    00128       case 6:
    00129         return locale()->translate("June");
    00130       case 7:
    00131         return locale()->translate("July");
    00132       case 8:
    00133         return locale()->translate("August");
    00134       case 9:
    00135         return locale()->translate("September");
    00136       case 10:
    00137         return locale()->translate("October");
    00138       case 11:
    00139         return locale()->translate("November");
    00140       case 12:
    00141         return locale()->translate("December");
    00142       }
    00143
    00144   return QString::null;
    00145 }
    00146
    00147 QString KCalendarSystemGregorian::monthNamePossessive(int month, int year,
    00148                                                       bool shortName) const
    00149 {
    00150   Q_UNUSED(year);
    00151
    00152   if ( shortName )
    00153     switch ( month )
    00154       {
    00155       case 1:
    00156         return locale()->translate("of January", "of Jan");
    00157       case 2:
    00158         return locale()->translate("of February", "of Feb");
    00159       case 3:
    00160         return locale()->translate("of March", "of Mar");
    00161       case 4:
    00162         return locale()->translate("of April", "of Apr");
    00163       case 5:
    00164         return locale()->translate("of May short", "of May");
    00165       case 6:
    00166         return locale()->translate("of June", "of Jun");
    00167       case 7:
    00168         return locale()->translate("of July", "of Jul");
    00169       case 8:
    00170         return locale()->translate("of August", "of Aug");
    00171       case 9:
    00172         return locale()->translate("of September", "of Sep");
    00173       case 10:
    00174         return locale()->translate("of October", "of Oct");
    00175       case 11:
    00176        return locale()->translate("of November", "of Nov");
    00177       case 12:
    00178         return locale()->translate("of December", "of Dec");
    00179       }
    00180   else
    00181     switch ( month )
    00182       {
    00183       case 1:
    00184         return locale()->translate("of January");
    00185       case 2:
    00186         return locale()->translate("of February");
    00187       case 3:
    00188         return locale()->translate("of March");
    00189       case 4:
    00190         return locale()->translate("of April");
    00191       case 5:
    00192         return locale()->translate("of May long", "of May");
    00193       case 6:
    00194         return locale()->translate("of June");
    00195       case 7:
    00196         return locale()->translate("of July");
    00197       case 8:
    00198         return locale()->translate("of August");
    00199       case 9:
    00200         return locale()->translate("of September");
    00201       case 10:
    00202         return locale()->translate("of October");
    00203       case 11:
    00204         return locale()->translate("of November");
    00205       case 12:
    00206         return locale()->translate("of December");
    00207       }
    00208
    00209   return QString::null;
    00210 }
    00211
    00212 bool KCalendarSystemGregorian::setYMD(QDate & date, int y, int m, int d) const
    00213 {
    00214   // We don't want Qt to add 1900 to them
    00215   if ( y >= 0 && y <= 99 )
    00216     return false;
    00217
    00218   // QDate supports gregorian internally
    00219   return date.setYMD(y, m, d);
    00220 }
    00221
    00222 QDate KCalendarSystemGregorian::addYears(const QDate & date, int nyears) const
    00223 {
    00224   return date.addYears(nyears);
    00225 }
    00226
    00227 QDate KCalendarSystemGregorian::addMonths(const QDate & date, int nmonths) const
    00228 {
    00229   return date.addMonths(nmonths);
    00230 }
    00231
    00232 QDate KCalendarSystemGregorian::addDays(const QDate & date, int ndays) const
    00233 {
    00234   return date.addDays(ndays);
    00235 }
    00236
    00237 QString KCalendarSystemGregorian::weekDayName(int col, bool shortName) const
    00238 {
    00239   // ### Should this really be different to each calendar system? Or are we
    00240   //     only going to support weeks with 7 days?
    00241
    00242   return KCalendarSystem::weekDayName(col, shortName);
    00243 }
    00244
    00245 QString KCalendarSystemGregorian::weekDayName(const QDate& date, bool shortName) const
    00246 {
    00247   return weekDayName(dayOfWeek(date), shortName);
    00248 }
    00249
    00250
    00251 int KCalendarSystemGregorian::dayOfWeek(const QDate& date) const
    00252 {
    00253   return date.dayOfWeek();
    00254 }
    00255
    00256 int KCalendarSystemGregorian::dayOfYear(const QDate & date) const
    00257 {
    00258   return date.dayOfYear();
    00259 }
    00260
    00261 int KCalendarSystemGregorian::daysInMonth(const QDate& date) const
    00262 {
    00263   return date.daysInMonth();
    00264 }
    00265
    00266 int KCalendarSystemGregorian::minValidYear() const
    00267 {
    00268   return 1753; // QDate limit
    00269 }
    00270
    00271 int KCalendarSystemGregorian::maxValidYear() const
    00272 {
    00273   return 8000; // QDate limit
    00274 }
    00275
    00276 int KCalendarSystemGregorian::day(const QDate& date) const
    00277 {
    00278   return date.day();
    00279 }
    00280
    00281 int KCalendarSystemGregorian::month(const QDate& date) const
    00282 {
    00283   return date.month();
    00284 }
    00285
    00286 int KCalendarSystemGregorian::daysInYear(const QDate& date) const
    00287 {
    00288   return date.daysInYear();
    00289 }
    00290
    00291 int KCalendarSystemGregorian::weekDayOfPray() const
    00292 {
    00293   return 7; // sunday
    00294 }
    00295
    00296 QString KCalendarSystemGregorian::calendarName() const
    00297 {
    00298   return QString::fromLatin1("gregorian");
    00299 }
    00300
    00301 bool KCalendarSystemGregorian::isLunar() const
    00302 {
    00303   return false;
    00304 }
    00305
    00306 bool KCalendarSystemGregorian::isLunisolar() const
    00307 {
    00308   return false;
    00309 }
    00310
    00311 bool KCalendarSystemGregorian::isSolar() const
    00312 {
    00313   return true;
    00314 }
    00315
    00316 int KCalendarSystemGregorian::yearStringToInteger(const QString & sNum, int & iLength) const
    00317 {
    00318   int iYear;
    00319   iYear = KCalendarSystem::yearStringToInteger(sNum, iLength);
    00320
    00321   // Qt treats a year in the range 0-100 as 1900-1999.
    00322   // It is nicer for the user if we treat 0-68 as 2000-2068
    00323   if (iYear < 69)
    00324     iYear += 2000;
    00325   else if (iYear < 100)
    00326     iYear += 1900;
    00327
    00328   return iYear;
    00329 }

This file is part of the documentation for kdecore Library Version 3.4.1.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Sat Jun 11 20:18:01 2005 by doxygen 1.4.1 written by Dimitri van Heesch, © 1997-2003