• Skip to content
  • Skip to link menu
KDE 4.6 API Reference
  • KDE API Reference
  • kdelibs
  • KDE Home
  • Contact Us
 

KDECore

kcalendarsystemcoptic.cpp

Go to the documentation of this file.
00001 /*
00002     Copyright 2009, 2010 John Layt <john@layt.net>
00003 
00004     This library is free software; you can redistribute it and/or
00005     modify it under the terms of the GNU Library General Public
00006     License as published by the Free Software Foundation; either
00007     version 2 of the License, or (at your option) any later version.
00008 
00009     This library is distributed in the hope that it will be useful,
00010     but WITHOUT ANY WARRANTY; without even the implied warranty of
00011     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012     Library General Public License for more details.
00013 
00014     You should have received a copy of the GNU Library General Public License
00015     along with this library; see the file COPYING.LIB.  If not, write to
00016     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00017     Boston, MA 02110-1301, USA.
00018 */
00019 
00020 #include "kcalendarsystemcoptic_p.h"
00021 #include "kcalendarsystemprivate_p.h"
00022 #include "kcalendarsystemcopticprivate_p.h"
00023 
00024 #include "kdebug.h"
00025 #include "klocale.h"
00026 
00027 #include <QtCore/QDate>
00028 #include <QtCore/QCharRef>
00029 
00030 // Shared d pointer implementations
00031 
00032 KCalendarSystemCopticPrivate::KCalendarSystemCopticPrivate( KCalendarSystemCoptic *q )
00033                              :KCalendarSystemPrivate( q )
00034 {
00035 }
00036 
00037 KCalendarSystemCopticPrivate::~KCalendarSystemCopticPrivate()
00038 {
00039 }
00040 
00041 KLocale::CalendarSystem KCalendarSystemCopticPrivate::calendarSystem() const
00042 {
00043     return KLocale::CopticCalendar;
00044 }
00045 
00046 void KCalendarSystemCopticPrivate::loadDefaultEraList()
00047 {
00048     QString name, shortName, format;
00049     // AM for Anno Martyrum or "Year of the Martyrs"
00050     name = i18nc( "Calendar Era: Coptic Era of Martyrs, years > 0, LongFormat", "Anno Martyrum" );
00051     shortName = i18nc( "Calendar Era: Coptic Era of Martyrs, years > 0, ShortFormat", "AM" );
00052     format = i18nc( "(kdedt-format) Coptic, AM, full era year format used for %EY, e.g. 2000 AM", "%Ey %EC" );
00053     addEra( '+', 1, q->epoch(), 1, q->latestValidDate(), name, shortName, format );
00054 }
00055 
00056 int KCalendarSystemCopticPrivate::monthsInYear( int year ) const
00057 {
00058     Q_UNUSED( year )
00059     return 13;
00060 }
00061 
00062 int KCalendarSystemCopticPrivate::daysInMonth( int year, int month ) const
00063 {
00064     if ( month == 13 ) {
00065         if ( isLeapYear( year ) ) {
00066             return 6;
00067         } else {
00068             return 5;
00069         }
00070     }
00071 
00072     return 30;
00073 }
00074 
00075 int KCalendarSystemCopticPrivate::daysInYear( int year ) const
00076 {
00077     if ( isLeapYear( year ) ) {
00078         return 366;
00079     } else {
00080         return 365;
00081     }
00082 }
00083 
00084 int KCalendarSystemCopticPrivate::daysInWeek() const
00085 {
00086     return 7;
00087 }
00088 
00089 bool KCalendarSystemCopticPrivate::isLeapYear( int year ) const
00090 {
00091     //Uses same rule as Julian but offset by 1 year with year 3 being first leap year
00092     if ( year < 1 ) {
00093         year = year + 2;
00094     } else {
00095         year = year + 1;
00096     }
00097 
00098     if ( year % 4 == 0 ) {
00099         return true;
00100     }
00101     return false;
00102 }
00103 
00104 bool KCalendarSystemCopticPrivate::hasLeapMonths() const
00105 {
00106     return false;
00107 }
00108 
00109 bool KCalendarSystemCopticPrivate::hasYearZero() const
00110 {
00111     return false;
00112 }
00113 
00114 int KCalendarSystemCopticPrivate::maxDaysInWeek() const
00115 {
00116     return 7;
00117 }
00118 
00119 int KCalendarSystemCopticPrivate::maxMonthsInYear() const
00120 {
00121     return 13;
00122 }
00123 
00124 int KCalendarSystemCopticPrivate::earliestValidYear() const
00125 {
00126     return 1;
00127 }
00128 
00129 int KCalendarSystemCopticPrivate::latestValidYear() const
00130 {
00131     return 9999;
00132 }
00133 
00134 KCalendarSystemCoptic::KCalendarSystemCoptic( const KLocale *locale )
00135                      : KCalendarSystem( *new KCalendarSystemCopticPrivate( this ), KSharedConfig::Ptr(), locale ),
00136                        dont_use( 0 )
00137 {
00138     d_ptr->loadConfig( calendarType() );
00139 }
00140 
00141 KCalendarSystemCoptic::KCalendarSystemCoptic( const KSharedConfig::Ptr config, const KLocale *locale )
00142                      : KCalendarSystem( *new KCalendarSystemCopticPrivate( this ), config, locale ),
00143                        dont_use( 0 )
00144 {
00145     d_ptr->loadConfig( calendarType() );
00146 }
00147 
00148 KCalendarSystemCoptic::KCalendarSystemCoptic( KCalendarSystemCopticPrivate &dd,
00149                                               const KSharedConfig::Ptr config, const KLocale *locale )
00150                      : KCalendarSystem( dd, config, locale ),
00151                        dont_use( 0 )
00152 {
00153     d_ptr->loadConfig( calendarType() );
00154 }
00155 
00156 KCalendarSystemCoptic::~KCalendarSystemCoptic()
00157 {
00158     delete dont_use;
00159 }
00160 
00161 QString KCalendarSystemCoptic::calendarType() const
00162 {
00163     return QLatin1String( "coptic" );
00164 }
00165 
00166 QDate KCalendarSystemCoptic::epoch() const
00167 {
00168     //0001-01-01, no Year 0.
00169     //0284-08-29 AD Julian
00170     return QDate::fromJulianDay( 1825030 );
00171 }
00172 
00173 QDate KCalendarSystemCoptic::earliestValidDate() const
00174 {
00175     //0001-01-01, no Year 0.
00176     //0284-08-29 AD Julian
00177     return QDate::fromJulianDay( 1825030 );
00178 }
00179 
00180 QDate KCalendarSystemCoptic::latestValidDate() const
00181 {
00182     // Set to last day of year 9999 until confirm date formats & widgets support > 9999
00183     //9999-12-30
00184     //10283-08-29 AD Julian
00185     return QDate::fromJulianDay( 5477164 );
00186 }
00187 
00188 bool KCalendarSystemCoptic::isValid( int year, int month, int day ) const
00189 {
00190     return KCalendarSystem::isValid( year, month, day );
00191 }
00192 
00193 bool KCalendarSystemCoptic::isValid( const QDate &date ) const
00194 {
00195     return KCalendarSystem::isValid( date );
00196 }
00197 
00198 bool KCalendarSystemCoptic::setDate( QDate &date, int year, int month, int day ) const
00199 {
00200     return KCalendarSystem::setDate( date, year, month, day );
00201 }
00202 
00203 // Deprecated
00204 bool KCalendarSystemCoptic::setYMD( QDate &date, int y, int m, int d ) const
00205 {
00206     return KCalendarSystem::setDate( date, y, m, d );
00207 }
00208 
00209 int KCalendarSystemCoptic::year( const QDate &date ) const
00210 {
00211     return KCalendarSystem::year( date );
00212 }
00213 
00214 int KCalendarSystemCoptic::month( const QDate &date ) const
00215 {
00216     return KCalendarSystem::month( date );
00217 }
00218 
00219 int KCalendarSystemCoptic::day( const QDate &date ) const
00220 {
00221     return KCalendarSystem::day( date );
00222 }
00223 
00224 QDate KCalendarSystemCoptic::addYears( const QDate &date, int nyears ) const
00225 {
00226     return KCalendarSystem::addYears( date, nyears );
00227 }
00228 
00229 QDate KCalendarSystemCoptic::addMonths( const QDate &date, int nmonths ) const
00230 {
00231     return KCalendarSystem::addMonths( date, nmonths );
00232 }
00233 
00234 QDate KCalendarSystemCoptic::addDays( const QDate &date, int ndays ) const
00235 {
00236     return KCalendarSystem::addDays( date, ndays );
00237 }
00238 
00239 int KCalendarSystemCoptic::monthsInYear( const QDate &date ) const
00240 {
00241     return KCalendarSystem::monthsInYear( date );
00242 }
00243 
00244 int KCalendarSystemCoptic::weeksInYear( const QDate &date ) const
00245 {
00246     return KCalendarSystem::weeksInYear( date );
00247 }
00248 
00249 int KCalendarSystemCoptic::weeksInYear( int year ) const
00250 {
00251     return KCalendarSystem::weeksInYear( year );
00252 }
00253 
00254 int KCalendarSystemCoptic::daysInYear( const QDate &date ) const
00255 {
00256     return KCalendarSystem::daysInYear( date );
00257 }
00258 
00259 int KCalendarSystemCoptic::daysInMonth( const QDate &date ) const
00260 {
00261     return KCalendarSystem::daysInMonth( date );
00262 }
00263 
00264 int KCalendarSystemCoptic::daysInWeek( const QDate &date ) const
00265 {
00266     return KCalendarSystem::daysInWeek( date );
00267 }
00268 
00269 int KCalendarSystemCoptic::dayOfYear( const QDate &date ) const
00270 {
00271     return KCalendarSystem::dayOfYear( date );
00272 }
00273 
00274 int KCalendarSystemCoptic::dayOfWeek( const QDate &date ) const
00275 {
00276     return KCalendarSystem::dayOfWeek( date );
00277 }
00278 
00279 int KCalendarSystemCoptic::weekNumber( const QDate &date, int * yearNum ) const
00280 {
00281     return KCalendarSystem::weekNumber( date, yearNum );
00282 }
00283 
00284 bool KCalendarSystemCoptic::isLeapYear( int year ) const
00285 {
00286     return KCalendarSystem::isLeapYear( year );
00287 }
00288 
00289 bool KCalendarSystemCoptic::isLeapYear( const QDate &date ) const
00290 {
00291     return KCalendarSystem::isLeapYear( date );
00292 }
00293 
00294 // Names taken from Bohairic dialect transliterations in http://www.copticheritage.org/parameters/copticheritage/calendar/The_Coptic_Calendar.pdf
00295 // These differ from the transliterations found on Wikipedia http://en.wikipedia.org/wiki/Coptic_calendar
00296 // These differ from the Sahidic dialect transliterations used in Dershowitz & Reingold which went out of use in the 11th centuary
00297 // These differ from the Arabic transliterations found on Wikipedia
00298 // These differ from the transliterations used in Mac OSX 10.6 Snow Leopard
00299 // The Boharic was initially chosen as this is the dialect apparantly in 'common' use in the Coptic Church.
00300 // But it could be argued the Arabic forms should be used as they are in 'common' usage in Eqypt
00301 // And where did the rest come from?
00302 //
00303 //    Boharic         Wikipedia Copt   D&R Sahidic     Wikipedia Arab  Mac OSX
00304 //    --------------  ---------------  --------------  --------------  --------------
00305 //  * Thoout          Thout            Thoout          Tout            Tout
00306 //  * Paope           Paopi            Paope           Baba            Baba
00307 //  * Hathor          Hathor           Athōr           Hatour          Hatour
00308 //  * Kiahk           Koiak            Koiak           Kiahk           Kiahk
00309 //  * Tobe            Tobi             Tōbe            Touba           Toba
00310 //  * Meshir          Meshir           Meshir          Amshir          Amshir
00311 //  * Paremhotep      Paremhat         Paremotep       Baramhat        Baramhat
00312 //  * Parmoute        Paremoude        Paremoute       Baramouda       Baramouda
00313 //  * Pashons         Pashons          Pashons         Bashans         Bashans
00314 //  * Paone           Paoni            Paōne           Ba'ouna         Paona
00315 //  * Epep            Epip             Epēp            Abib            Epep
00316 //  * Mesore          Mesori           Mesorē          Mesra           Mesra
00317 //  * Kouji nabot     Pi Kogi Enavot   Epagomenē                       Nasie
00318 //  *
00319 QString KCalendarSystemCoptic::monthName( int month, int year, MonthNameFormat format ) const
00320 {
00321     Q_UNUSED( year );
00322 
00323     if ( format == ShortNamePossessive ) {
00324         switch ( month ) {
00325         case 1:
00326             return ki18nc( "Coptic month 1 - ShortNamePossessive",  "of Tho" ).toString( locale() );
00327         case 2:
00328             return ki18nc( "Coptic month 2 - ShortNamePossessive",  "of Pao" ).toString( locale() );
00329         case 3:
00330             return ki18nc( "Coptic month 3 - ShortNamePossessive",  "of Hat" ).toString( locale() );
00331         case 4:
00332             return ki18nc( "Coptic month 4 - ShortNamePossessive",  "of Kia" ).toString( locale() );
00333         case 5:
00334             return ki18nc( "Coptic month 5 - ShortNamePossessive",  "of Tob" ).toString( locale() );
00335         case 6:
00336             return ki18nc( "Coptic month 6 - ShortNamePossessive",  "of Mes" ).toString( locale() );
00337         case 7:
00338             return ki18nc( "Coptic month 7 - ShortNamePossessive",  "of Par" ).toString( locale() );
00339         case 8:
00340             return ki18nc( "Coptic month 8 - ShortNamePossessive",  "of Pam" ).toString( locale() );
00341         case 9:
00342             return ki18nc( "Coptic month 9 - ShortNamePossessive",  "of Pas" ).toString( locale() );
00343         case 10:
00344             return ki18nc( "Coptic month 10 - ShortNamePossessive", "of Pan" ).toString( locale() );
00345         case 11:
00346             return ki18nc( "Coptic month 11 - ShortNamePossessive", "of Epe" ).toString( locale() );
00347         case 12:
00348             return ki18nc( "Coptic month 12 - ShortNamePossessive", "of Meo" ).toString( locale() );
00349         case 13:
00350             return ki18nc( "Coptic month 13 - ShortNamePossessive", "of Kou" ).toString( locale() );
00351         default:
00352             return QString();
00353         }
00354     }
00355 
00356     if ( format == LongNamePossessive ) {
00357         switch ( month ) {
00358         case 1:
00359             return ki18nc( "Coptic month 1 - LongNamePossessive",  "of Thoout" ).toString( locale() );
00360         case 2:
00361             return ki18nc( "Coptic month 2 - LongNamePossessive",  "of Paope" ).toString( locale() );
00362         case 3:
00363             return ki18nc( "Coptic month 3 - LongNamePossessive",  "of Hathor" ).toString( locale() );
00364         case 4:
00365             return ki18nc( "Coptic month 4 - LongNamePossessive",  "of Kiahk" ).toString( locale() );
00366         case 5:
00367             return ki18nc( "Coptic month 5 - LongNamePossessive",  "of Tobe" ).toString( locale() );
00368         case 6:
00369             return ki18nc( "Coptic month 6 - LongNamePossessive",  "of Meshir" ).toString( locale() );
00370         case 7:
00371             return ki18nc( "Coptic month 7 - LongNamePossessive",  "of Paremhotep" ).toString( locale() );
00372         case 8:
00373             return ki18nc( "Coptic month 8 - LongNamePossessive",  "of Parmoute" ).toString( locale() );
00374         case 9:
00375             return ki18nc( "Coptic month 9 - LongNamePossessive",  "of Pashons" ).toString( locale() );
00376         case 10:
00377             return ki18nc( "Coptic month 10 - LongNamePossessive", "of Paone" ).toString( locale() );
00378         case 11:
00379             return ki18nc( "Coptic month 11 - LongNamePossessive", "of Epep" ).toString( locale() );
00380         case 12:
00381             return ki18nc( "Coptic month 12 - LongNamePossessive", "of Mesore" ).toString( locale() );
00382         case 13:
00383             return ki18nc( "Coptic month 13 - LongNamePossessive", "of Kouji nabot" ).toString( locale() );
00384         default:
00385             return QString();
00386         }
00387     }
00388 
00389     if ( format == ShortName ) {
00390         switch ( month ) {
00391         case 1:
00392             return ki18nc( "Coptic month 1 - ShortName",  "Tho" ).toString( locale() );
00393         case 2:
00394             return ki18nc( "Coptic month 2 - ShortName",  "Pao" ).toString( locale() );
00395         case 3:
00396             return ki18nc( "Coptic month 3 - ShortName",  "Hat" ).toString( locale() );
00397         case 4:
00398             return ki18nc( "Coptic month 4 - ShortName",  "Kia" ).toString( locale() );
00399         case 5:
00400             return ki18nc( "Coptic month 5 - ShortName",  "Tob" ).toString( locale() );
00401         case 6:
00402             return ki18nc( "Coptic month 6 - ShortName",  "Mes" ).toString( locale() );
00403         case 7:
00404             return ki18nc( "Coptic month 7 - ShortName",  "Par" ).toString( locale() );
00405         case 8:
00406             return ki18nc( "Coptic month 8 - ShortName",  "Pam" ).toString( locale() );
00407         case 9:
00408             return ki18nc( "Coptic month 9 - ShortName",  "Pas" ).toString( locale() );
00409         case 10:
00410             return ki18nc( "Coptic month 10 - ShortName", "Pan" ).toString( locale() );
00411         case 11:
00412             return ki18nc( "Coptic month 11 - ShortName", "Epe" ).toString( locale() );
00413         case 12:
00414             return ki18nc( "Coptic month 12 - ShortName", "Meo" ).toString( locale() );
00415         case 13:
00416             return ki18nc( "Coptic month 13 - ShortName", "Kou" ).toString( locale() );
00417         default:
00418             return QString();
00419         }
00420     }
00421 
00422     // Default to LongName
00423     switch ( month ) {
00424     case 1:
00425         return ki18nc( "Coptic month 1 - LongName",  "Thoout" ).toString( locale() );
00426     case 2:
00427         return ki18nc( "Coptic month 2 - LongName",  "Paope" ).toString( locale() );
00428     case 3:
00429         return ki18nc( "Coptic month 3 - LongName",  "Hathor" ).toString( locale() );
00430     case 4:
00431         return ki18nc( "Coptic month 4 - LongName",  "Kiahk" ).toString( locale() );
00432     case 5:
00433         return ki18nc( "Coptic month 5 - LongName",  "Tobe" ).toString( locale() );
00434     case 6:
00435         return ki18nc( "Coptic month 6 - LongName",  "Meshir" ).toString( locale() );
00436     case 7:
00437         return ki18nc( "Coptic month 7 - LongName",  "Paremhotep" ).toString( locale() );
00438     case 8:
00439         return ki18nc( "Coptic month 8 - LongName",  "Parmoute" ).toString( locale() );
00440     case 9:
00441         return ki18nc( "Coptic month 9 - LongName",  "Pashons" ).toString( locale() );
00442     case 10:
00443         return ki18nc( "Coptic month 10 - LongName", "Paone" ).toString( locale() );
00444     case 11:
00445         return ki18nc( "Coptic month 11 - LongName", "Epep" ).toString( locale() );
00446     case 12:
00447         return ki18nc( "Coptic month 12 - LongName", "Mesore" ).toString( locale() );
00448     case 13:
00449         return ki18nc( "Coptic month 13 - LongName", "Kouji nabot" ).toString( locale() );
00450     default:
00451         return QString();
00452     }
00453 }
00454 
00455 QString KCalendarSystemCoptic::monthName( const QDate &date, MonthNameFormat format ) const
00456 {
00457     return KCalendarSystem::monthName( date, format );
00458 }
00459 
00460 // Names taken from from the Sahidic dialect transliterations used in Dershowitz & Reingold which went out of use in the 11th centuary
00461 // Boharic or Arabic transliterations would be preferred but none could be found
00462 QString KCalendarSystemCoptic::weekDayName( int weekDay, WeekDayNameFormat format ) const
00463 {
00464     if ( format == ShortDayName ) {
00465         switch ( weekDay ) {
00466         case 1:  return ki18nc( "Coptic weekday 1 - ShortDayName", "Pes" ).toString( locale() );
00467         case 2:  return ki18nc( "Coptic weekday 2 - ShortDayName", "Psh" ).toString( locale() );
00468         case 3:  return ki18nc( "Coptic weekday 3 - ShortDayName", "Pef" ).toString( locale() );
00469         case 4:  return ki18nc( "Coptic weekday 4 - ShortDayName", "Pti" ).toString( locale() );
00470         case 5:  return ki18nc( "Coptic weekday 5 - ShortDayName", "Pso" ).toString( locale() );
00471         case 6:  return ki18nc( "Coptic weekday 6 - ShortDayName", "Psa" ).toString( locale() );
00472         case 7:  return ki18nc( "Coptic weekday 7 - ShortDayName", "Tky" ).toString( locale() );
00473         default: return QString();
00474         }
00475     }
00476 
00477     switch ( weekDay ) {
00478     case 1:  return ki18nc( "Coptic weekday 1 - LongDayName", "Pesnau" ).toString( locale() );
00479     case 2:  return ki18nc( "Coptic weekday 2 - LongDayName", "Pshoment" ).toString( locale() );
00480     case 3:  return ki18nc( "Coptic weekday 3 - LongDayName", "Peftoou" ).toString( locale() );
00481     case 4:  return ki18nc( "Coptic weekday 4 - LongDayName", "Ptiou" ).toString( locale() );
00482     case 5:  return ki18nc( "Coptic weekday 5 - LongDayName", "Psoou" ).toString( locale() );
00483     case 6:  return ki18nc( "Coptic weekday 6 - LongDayName", "Psabbaton" ).toString( locale() );
00484     case 7:  return ki18nc( "Coptic weekday 7 - LongDayName", "Tkyriakē" ).toString( locale() );
00485     default: return QString();
00486     }
00487 }
00488 
00489 QString KCalendarSystemCoptic::weekDayName( const QDate &date, WeekDayNameFormat format ) const
00490 {
00491     return KCalendarSystem::weekDayName( date, format );
00492 }
00493 
00494 QString KCalendarSystemCoptic::yearString( const QDate &pDate, StringFormat format ) const
00495 {
00496     return KCalendarSystem::yearString( pDate, format );
00497 }
00498 
00499 QString KCalendarSystemCoptic::monthString( const QDate &pDate, StringFormat format ) const
00500 {
00501     return KCalendarSystem::monthString( pDate, format );
00502 }
00503 
00504 QString KCalendarSystemCoptic::dayString( const QDate &pDate, StringFormat format ) const
00505 {
00506     return KCalendarSystem::dayString( pDate, format );
00507 }
00508 
00509 int KCalendarSystemCoptic::yearStringToInteger( const QString &sNum, int &iLength ) const
00510 {
00511     return KCalendarSystem::yearStringToInteger( sNum, iLength );
00512 }
00513 
00514 int KCalendarSystemCoptic::monthStringToInteger( const QString &sNum, int &iLength ) const
00515 {
00516     return KCalendarSystem::monthStringToInteger( sNum, iLength );
00517 }
00518 
00519 int KCalendarSystemCoptic::dayStringToInteger( const QString &sNum, int &iLength ) const
00520 {
00521     return KCalendarSystem::dayStringToInteger( sNum, iLength );
00522 }
00523 
00524 QString KCalendarSystemCoptic::formatDate( const QDate &date, KLocale::DateFormat format ) const
00525 {
00526     return KCalendarSystem::formatDate( date, format );
00527 }
00528 
00529 QDate KCalendarSystemCoptic::readDate( const QString &str, bool *ok ) const
00530 {
00531     return KCalendarSystem::readDate( str, ok );
00532 }
00533 
00534 QDate KCalendarSystemCoptic::readDate( const QString &intstr, const QString &fmt, bool *ok ) const
00535 {
00536     return KCalendarSystem::readDate( intstr, fmt, ok );
00537 }
00538 
00539 QDate KCalendarSystemCoptic::readDate( const QString &str, KLocale::ReadDateFlags flags, bool *ok ) const
00540 {
00541     return KCalendarSystem::readDate( str, flags, ok );
00542 }
00543 
00544 int KCalendarSystemCoptic::weekStartDay() const
00545 {
00546     return KCalendarSystem::weekStartDay();
00547 }
00548 
00549 int KCalendarSystemCoptic::weekDayOfPray() const
00550 {
00551     return 7;
00552 }
00553 
00554 bool KCalendarSystemCoptic::isLunar() const
00555 {
00556     return false;
00557 }
00558 
00559 bool KCalendarSystemCoptic::isLunisolar() const
00560 {
00561     return false;
00562 }
00563 
00564 bool KCalendarSystemCoptic::isSolar() const
00565 {
00566     return true;
00567 }
00568 
00569 bool KCalendarSystemCoptic::isProleptic() const
00570 {
00571     return false;
00572 }
00573 
00574 bool KCalendarSystemCoptic::julianDayToDate( int jd, int &year, int &month, int &day ) const
00575 {
00576     //The Coptic calendar has 12 months of 30 days, a 13th month of 5 or 6 days,
00577     //and a leap year every 4th year without fail that falls on the last day of
00578     //the year, starting from year 3.
00579 
00580     //Use a fake year 0 for our epoch instead of the real epoch in year 1. This is because year 3
00581     //is the first leap year and a pattern of 365/365/366/365 is hard to calculate, instead a
00582     //pattern of 365/365/365/366 with the leap day the very last day makes the maths easier.
00583 
00584     //Day number in the fake epoch, 0 indexed
00585     int dayInEpoch = jd - ( epoch().toJulianDay() - 365 );
00586     //How many full 4 year leap cycles have been completed, 1461 = (365*3)+366
00587     int leapCyclesCompleted = dayInEpoch / 1461;
00588     //Which year are we in the current 4 year leap cycle, 0 indexed
00589     //Need the qMin as day 366 of 4th year of cycle returns following year (max 3 as 0 index)
00590     int yearInCurrentLeapCycle = qMin( 3, ( dayInEpoch % 1461 ) / 365 );
00591     //Calculate the year
00592     year = ( leapCyclesCompleted * 4 ) + yearInCurrentLeapCycle;
00593     //Days since the fake epoch up to 1st day of this year
00594     int daysBeforeThisYear = ( year * 365 ) + ( year / 4 );
00595     //Gives the day number in this year, 0 indexed
00596     int dayOfThisYear = dayInEpoch -  daysBeforeThisYear;
00597     //Then just calculate month and day from that based on regular 30 day months
00598     month = ( ( dayOfThisYear ) / 30 ) + 1;
00599     day = dayOfThisYear - ( ( month - 1 ) * 30 ) + 1;
00600 
00601     // If year is -ve then is BC.  In Coptic there is no year 0, but the maths
00602     // is easier if we pretend there is, so internally year of 0 = 1BC = -1 outside
00603     if ( year < 1 ) {
00604         year = year - 1;
00605     }
00606 
00607     return true;
00608 }
00609 
00610 bool KCalendarSystemCoptic::dateToJulianDay( int year, int month, int day, int &jd ) const
00611 {
00612     //The Coptic calendar has 12 months of 30 days, a 13th month of 5 or 6 days,
00613     //and a leap year every 4th year without fail that falls on the last day of
00614     //the year, starting from year 3.  This simple repeating pattern makes calculating
00615     // a jd the simple process taking the epoch jd and adding on the years months and
00616     //days required.
00617 
00618     // If year is -ve then is 'BC'.  In Coptic there is no year 0, but the maths
00619     // is easier if we pretend there is, so internally year of -1 = 1BC = 0 internally
00620     int y;
00621     if ( year < 1 ) {
00622         y = year + 1;
00623     } else {
00624         y = year;
00625     }
00626 
00627     jd = epoch().toJulianDay() - 1    // jd of day before Epoch
00628        + ( ( y - 1 ) * 365 )          // Add all normal days in years preceding
00629        + ( y / 4 )                    // Add all leap days in years preceding
00630        + ( ( month - 1 ) * 30 )       // Add days this year in months preceding
00631        + day;                         // Add days in this month
00632 
00633     return true;
00634 }

KDECore

Skip menu "KDECore"
  • Main Page
  • Modules
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

kdelibs

Skip menu "kdelibs"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • Kate
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.7.3
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal