KDECore
kcalendarsystemethiopian.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 "kcalendarsystemethiopian_p.h" 00021 #include "kcalendarsystemcopticprivate_p.h" 00022 00023 #include "kdebug.h" 00024 #include "klocale.h" 00025 00026 #include <QtCore/QDate> 00027 #include <QtCore/QCharRef> 00028 00029 //Reuse the Coptic private implementation 00030 class KCalendarSystemEthiopianPrivate : public KCalendarSystemCopticPrivate 00031 { 00032 public: 00033 explicit KCalendarSystemEthiopianPrivate( KCalendarSystemEthiopian *q ) : KCalendarSystemCopticPrivate( q ) 00034 { 00035 } 00036 00037 virtual ~KCalendarSystemEthiopianPrivate() 00038 { 00039 } 00040 00041 virtual KLocale::CalendarSystem calendarSystem() const; 00042 virtual void loadDefaultEraList(); 00043 }; 00044 00045 KLocale::CalendarSystem KCalendarSystemEthiopianPrivate::calendarSystem() const 00046 { 00047 return KLocale::EthiopianCalendar; 00048 } 00049 00050 void KCalendarSystemEthiopianPrivate::loadDefaultEraList() 00051 { 00052 QString name, shortName, format; 00053 // Incarnation Era, Amätä Mehrät, "Year of Mercy". 00054 name = i18nc( "Calendar Era: Ethiopian Incarnation Era, years > 0, LongFormat", "Amata Mehrat" ); 00055 shortName = i18nc( "Calendar Era: Ethiopian Incarnation Era, years > 0, ShortFormat", "AM" ); 00056 format = i18nc( "(kdedt-format) Ethiopian, AM, full era year format used for %EY, e.g. 2000 AM", "%Ey %EC" ); 00057 addEra( '+', 1, q->epoch(), 1, q->latestValidDate(), name, shortName, format ); 00058 } 00059 00060 00061 KCalendarSystemEthiopian::KCalendarSystemEthiopian( const KLocale *locale ) 00062 : KCalendarSystemCoptic( *new KCalendarSystemEthiopianPrivate( this ), KSharedConfig::Ptr(), locale ), 00063 dont_use( 0 ) 00064 { 00065 d_ptr->loadConfig( calendarType() ); 00066 } 00067 00068 KCalendarSystemEthiopian::KCalendarSystemEthiopian( const KSharedConfig::Ptr config, const KLocale *locale ) 00069 : KCalendarSystemCoptic( *new KCalendarSystemEthiopianPrivate( this ), config, locale ), 00070 dont_use( 0 ) 00071 { 00072 d_ptr->loadConfig( calendarType() ); 00073 } 00074 00075 KCalendarSystemEthiopian::KCalendarSystemEthiopian( KCalendarSystemEthiopianPrivate &dd, 00076 const KSharedConfig::Ptr config, const KLocale *locale ) 00077 : KCalendarSystemCoptic( dd, config, locale ), 00078 dont_use( 0 ) 00079 { 00080 d_ptr->loadConfig( calendarType() ); 00081 } 00082 00083 KCalendarSystemEthiopian::~KCalendarSystemEthiopian() 00084 { 00085 delete dont_use; 00086 } 00087 00088 QString KCalendarSystemEthiopian::calendarType() const 00089 { 00090 return QLatin1String( "ethiopian" ); 00091 } 00092 00093 QDate KCalendarSystemEthiopian::epoch() const 00094 { 00095 //0001-01-01, no Year 0. 00096 //0008-08-29 AD Julian 00097 return QDate::fromJulianDay( 1724221 ); 00098 } 00099 00100 QDate KCalendarSystemEthiopian::earliestValidDate() const 00101 { 00102 //0001-01-01, no Year 0. 00103 //0008-08-29 AD Julian 00104 return QDate::fromJulianDay( 1724221 ); 00105 } 00106 00107 QDate KCalendarSystemEthiopian::latestValidDate() const 00108 { 00109 // Set to last day of year 9999 until confirm date formats & widgets support > 9999 00110 //9999-12-30 00111 //100008-08-29 AD Julian 00112 return QDate::fromJulianDay( 5376721 ); 00113 } 00114 00115 bool KCalendarSystemEthiopian::isValid( int year, int month, int day ) const 00116 { 00117 return KCalendarSystemCoptic::isValid( year, month, day ); 00118 } 00119 00120 bool KCalendarSystemEthiopian::isValid( const QDate &date ) const 00121 { 00122 return KCalendarSystemCoptic::isValid( date ); 00123 } 00124 00125 bool KCalendarSystemEthiopian::setDate( QDate &date, int year, int month, int day ) const 00126 { 00127 return KCalendarSystemCoptic::setDate( date, year, month, day ); 00128 } 00129 00130 // Deprecated 00131 bool KCalendarSystemEthiopian::setYMD( QDate &date, int y, int m, int d ) const 00132 { 00133 return KCalendarSystemCoptic::setDate( date, y, m, d ); 00134 } 00135 00136 int KCalendarSystemEthiopian::year( const QDate &date ) const 00137 { 00138 return KCalendarSystemCoptic::year( date ); 00139 } 00140 00141 int KCalendarSystemEthiopian::month( const QDate &date ) const 00142 { 00143 return KCalendarSystemCoptic::month( date ); 00144 } 00145 00146 int KCalendarSystemEthiopian::day( const QDate &date ) const 00147 { 00148 return KCalendarSystemCoptic::day( date ); 00149 } 00150 00151 QDate KCalendarSystemEthiopian::addYears( const QDate &date, int nyears ) const 00152 { 00153 return KCalendarSystemCoptic::addYears( date, nyears ); 00154 } 00155 00156 QDate KCalendarSystemEthiopian::addMonths( const QDate &date, int nmonths ) const 00157 { 00158 return KCalendarSystemCoptic::addMonths( date, nmonths ); 00159 } 00160 00161 QDate KCalendarSystemEthiopian::addDays( const QDate &date, int ndays ) const 00162 { 00163 return KCalendarSystemCoptic::addDays( date, ndays ); 00164 } 00165 00166 int KCalendarSystemEthiopian::monthsInYear( const QDate &date ) const 00167 { 00168 return KCalendarSystemCoptic::monthsInYear( date ); 00169 } 00170 00171 int KCalendarSystemEthiopian::weeksInYear( const QDate &date ) const 00172 { 00173 return KCalendarSystemCoptic::weeksInYear( date ); 00174 } 00175 00176 int KCalendarSystemEthiopian::weeksInYear( int year ) const 00177 { 00178 return KCalendarSystemCoptic::weeksInYear( year ); 00179 } 00180 00181 int KCalendarSystemEthiopian::daysInYear( const QDate &date ) const 00182 { 00183 return KCalendarSystemCoptic::daysInYear( date ); 00184 } 00185 00186 int KCalendarSystemEthiopian::daysInMonth( const QDate &date ) const 00187 { 00188 return KCalendarSystemCoptic::daysInMonth( date ); 00189 } 00190 00191 int KCalendarSystemEthiopian::daysInWeek( const QDate &date ) const 00192 { 00193 return KCalendarSystemCoptic::daysInWeek( date ); 00194 } 00195 00196 int KCalendarSystemEthiopian::dayOfYear( const QDate &date ) const 00197 { 00198 return KCalendarSystemCoptic::dayOfYear( date ); 00199 } 00200 00201 int KCalendarSystemEthiopian::dayOfWeek( const QDate &date ) const 00202 { 00203 return KCalendarSystemCoptic::dayOfWeek( date ); 00204 } 00205 00206 int KCalendarSystemEthiopian::weekNumber( const QDate &date, int * yearNum ) const 00207 { 00208 return KCalendarSystemCoptic::weekNumber( date, yearNum ); 00209 } 00210 00211 bool KCalendarSystemEthiopian::isLeapYear( int year ) const 00212 { 00213 return KCalendarSystemCoptic::isLeapYear( year ); 00214 } 00215 00216 bool KCalendarSystemEthiopian::isLeapYear( const QDate &date ) const 00217 { 00218 return KCalendarSystemCoptic::isLeapYear( date ); 00219 } 00220 00221 // Names taken from http://www.ethiopianembassy.at/dates_cycles.htm, alternative transliterations exist 00222 QString KCalendarSystemEthiopian::monthName( int month, int year, MonthNameFormat format ) const 00223 { 00224 Q_UNUSED( year ); 00225 00226 if ( format == ShortNamePossessive ) { 00227 switch ( month ) { 00228 case 1: 00229 return ki18nc( "Ethiopian month 1 - ShortNamePossessive", "of Mes" ).toString( locale() ); 00230 case 2: 00231 return ki18nc( "Ethiopian month 2 - ShortNamePossessive", "of Teq" ).toString( locale() ); 00232 case 3: 00233 return ki18nc( "Ethiopian month 3 - ShortNamePossessive", "of Hed" ).toString( locale() ); 00234 case 4: 00235 return ki18nc( "Ethiopian month 4 - ShortNamePossessive", "of Tah" ).toString( locale() ); 00236 case 5: 00237 return ki18nc( "Ethiopian month 5 - ShortNamePossessive", "of Ter" ).toString( locale() ); 00238 case 6: 00239 return ki18nc( "Ethiopian month 6 - ShortNamePossessive", "of Yak" ).toString( locale() ); 00240 case 7: 00241 return ki18nc( "Ethiopian month 7 - ShortNamePossessive", "of Mag" ).toString( locale() ); 00242 case 8: 00243 return ki18nc( "Ethiopian month 8 - ShortNamePossessive", "of Miy" ).toString( locale() ); 00244 case 9: 00245 return ki18nc( "Ethiopian month 9 - ShortNamePossessive", "of Gen" ).toString( locale() ); 00246 case 10: 00247 return ki18nc( "Ethiopian month 10 - ShortNamePossessive", "of Sen" ).toString( locale() ); 00248 case 11: 00249 return ki18nc( "Ethiopian month 11 - ShortNamePossessive", "of Ham" ).toString( locale() ); 00250 case 12: 00251 return ki18nc( "Ethiopian month 12 - ShortNamePossessive", "of Neh" ).toString( locale() ); 00252 case 13: 00253 return ki18nc( "Ethiopian month 13 - ShortNamePossessive", "of Pag" ).toString( locale() ); 00254 default: 00255 return QString(); 00256 } 00257 } 00258 00259 if ( format == LongNamePossessive ) { 00260 switch ( month ) { 00261 case 1: 00262 return ki18nc( "Ethiopian month 1 - LongNamePossessive", "of Meskerem" ).toString( locale() ); 00263 case 2: 00264 return ki18nc( "Ethiopian month 2 - LongNamePossessive", "of Tequemt" ).toString( locale() ); 00265 case 3: 00266 return ki18nc( "Ethiopian month 3 - LongNamePossessive", "of Hedar" ).toString( locale() ); 00267 case 4: 00268 return ki18nc( "Ethiopian month 4 - LongNamePossessive", "of Tahsas" ).toString( locale() ); 00269 case 5: 00270 return ki18nc( "Ethiopian month 5 - LongNamePossessive", "of Ter" ).toString( locale() ); 00271 case 6: 00272 return ki18nc( "Ethiopian month 6 - LongNamePossessive", "of Yakatit" ).toString( locale() ); 00273 case 7: 00274 return ki18nc( "Ethiopian month 7 - LongNamePossessive", "of Magabit" ).toString( locale() ); 00275 case 8: 00276 return ki18nc( "Ethiopian month 8 - LongNamePossessive", "of Miyazya" ).toString( locale() ); 00277 case 9: 00278 return ki18nc( "Ethiopian month 9 - LongNamePossessive", "of Genbot" ).toString( locale() ); 00279 case 10: 00280 return ki18nc( "Ethiopian month 10 - LongNamePossessive", "of Sene" ).toString( locale() ); 00281 case 11: 00282 return ki18nc( "Ethiopian month 11 - LongNamePossessive", "of Hamle" ).toString( locale() ); 00283 case 12: 00284 return ki18nc( "Ethiopian month 12 - LongNamePossessive", "of Nehase" ).toString( locale() ); 00285 case 13: 00286 return ki18nc( "Ethiopian month 13 - LongNamePossessive", "of Pagumen" ).toString( locale() ); 00287 default: 00288 return QString(); 00289 } 00290 } 00291 00292 if ( format == ShortName ) { 00293 switch ( month ) { 00294 case 1: 00295 return ki18nc( "Ethiopian month 1 - ShortName", "Mes" ).toString( locale() ); 00296 case 2: 00297 return ki18nc( "Ethiopian month 2 - ShortName", "Teq" ).toString( locale() ); 00298 case 3: 00299 return ki18nc( "Ethiopian month 3 - ShortName", "Hed" ).toString( locale() ); 00300 case 4: 00301 return ki18nc( "Ethiopian month 4 - ShortName", "Tah" ).toString( locale() ); 00302 case 5: 00303 return ki18nc( "Ethiopian month 5 - ShortName", "Ter" ).toString( locale() ); 00304 case 6: 00305 return ki18nc( "Ethiopian month 6 - ShortName", "Yak" ).toString( locale() ); 00306 case 7: 00307 return ki18nc( "Ethiopian month 7 - ShortName", "Mag" ).toString( locale() ); 00308 case 8: 00309 return ki18nc( "Ethiopian month 8 - ShortName", "Miy" ).toString( locale() ); 00310 case 9: 00311 return ki18nc( "Ethiopian month 9 - ShortName", "Gen" ).toString( locale() ); 00312 case 10: 00313 return ki18nc( "Ethiopian month 10 - ShortName", "Sen" ).toString( locale() ); 00314 case 11: 00315 return ki18nc( "Ethiopian month 11 - ShortName", "Ham" ).toString( locale() ); 00316 case 12: 00317 return ki18nc( "Ethiopian month 12 - ShortName", "Neh" ).toString( locale() ); 00318 case 13: 00319 return ki18nc( "Ethiopian month 13 - ShortName", "Pag" ).toString( locale() ); 00320 default: 00321 return QString(); 00322 } 00323 } 00324 00325 // Default to LongName 00326 switch ( month ) { 00327 case 1: 00328 return ki18nc( "Ethiopian month 1 - LongName", "Meskerem" ).toString( locale() ); 00329 case 2: 00330 return ki18nc( "Ethiopian month 2 - LongName", "Tequemt" ).toString( locale() ); 00331 case 3: 00332 return ki18nc( "Ethiopian month 3 - LongName", "Hedar" ).toString( locale() ); 00333 case 4: 00334 return ki18nc( "Ethiopian month 4 - LongName", "Tahsas" ).toString( locale() ); 00335 case 5: 00336 return ki18nc( "Ethiopian month 5 - LongName", "Ter" ).toString( locale() ); 00337 case 6: 00338 return ki18nc( "Ethiopian month 6 - LongName", "Yakatit" ).toString( locale() ); 00339 case 7: 00340 return ki18nc( "Ethiopian month 7 - LongName", "Magabit" ).toString( locale() ); 00341 case 8: 00342 return ki18nc( "Ethiopian month 8 - LongName", "Miyazya" ).toString( locale() ); 00343 case 9: 00344 return ki18nc( "Ethiopian month 9 - LongName", "Genbot" ).toString( locale() ); 00345 case 10: 00346 return ki18nc( "Ethiopian month 10 - LongName", "Sene" ).toString( locale() ); 00347 case 11: 00348 return ki18nc( "Ethiopian month 11 - LongName", "Hamle" ).toString( locale() ); 00349 case 12: 00350 return ki18nc( "Ethiopian month 12 - LongName", "Nehase" ).toString( locale() ); 00351 case 13: 00352 return ki18nc( "Ethiopian month 13 - LongName", "Pagumen" ).toString( locale() ); 00353 default: 00354 return QString(); 00355 } 00356 } 00357 00358 QString KCalendarSystemEthiopian::monthName( const QDate &date, MonthNameFormat format ) const 00359 { 00360 return KCalendarSystemCoptic::monthName( date, format ); 00361 } 00362 00363 // Names taken from http://www.ethiopianembassy.at/dates_cycles.htm, alternative transliterations exist 00364 QString KCalendarSystemEthiopian::weekDayName( int weekDay, WeekDayNameFormat format ) const 00365 { 00366 if ( format == ShortDayName ) { 00367 switch ( weekDay ) { 00368 case 1: return ki18nc( "Ethiopian weekday 1 - ShortDayName", "Seg" ).toString( locale() ); 00369 case 2: return ki18nc( "Ethiopian weekday 2 - ShortDayName", "Mak" ).toString( locale() ); 00370 case 3: return ki18nc( "Ethiopian weekday 3 - ShortDayName", "Rob" ).toString( locale() ); 00371 case 4: return ki18nc( "Ethiopian weekday 4 - ShortDayName", "Ham" ).toString( locale() ); 00372 case 5: return ki18nc( "Ethiopian weekday 5 - ShortDayName", "Arb" ).toString( locale() ); 00373 case 6: return ki18nc( "Ethiopian weekday 6 - ShortDayName", "Qed" ).toString( locale() ); 00374 case 7: return ki18nc( "Ethiopian weekday 7 - ShortDayName", "Ehu" ).toString( locale() ); 00375 default: return QString(); 00376 } 00377 } 00378 00379 switch ( weekDay ) { 00380 case 1: return ki18nc( "Ethiopian weekday 1 - LongDayName", "Segno" ).toString( locale() ); 00381 case 2: return ki18nc( "Ethiopian weekday 2 - LongDayName", "Maksegno" ).toString( locale() ); 00382 case 3: return ki18nc( "Ethiopian weekday 3 - LongDayName", "Rob" ).toString( locale() ); 00383 case 4: return ki18nc( "Ethiopian weekday 4 - LongDayName", "Hamus" ).toString( locale() ); 00384 case 5: return ki18nc( "Ethiopian weekday 5 - LongDayName", "Arb" ).toString( locale() ); 00385 case 6: return ki18nc( "Ethiopian weekday 6 - LongDayName", "Qedame" ).toString( locale() ); 00386 case 7: return ki18nc( "Ethiopian weekday 7 - LongDayName", "Ehud" ).toString( locale() ); 00387 default: return QString(); 00388 } 00389 } 00390 00391 QString KCalendarSystemEthiopian::weekDayName( const QDate &date, WeekDayNameFormat format ) const 00392 { 00393 return KCalendarSystemCoptic::weekDayName( date, format ); 00394 } 00395 00396 QString KCalendarSystemEthiopian::yearString( const QDate &pDate, StringFormat format ) const 00397 { 00398 return KCalendarSystemCoptic::yearString( pDate, format ); 00399 } 00400 00401 QString KCalendarSystemEthiopian::monthString( const QDate &pDate, StringFormat format ) const 00402 { 00403 return KCalendarSystemCoptic::monthString( pDate, format ); 00404 } 00405 00406 QString KCalendarSystemEthiopian::dayString( const QDate &pDate, StringFormat format ) const 00407 { 00408 return KCalendarSystemCoptic::dayString( pDate, format ); 00409 } 00410 00411 int KCalendarSystemEthiopian::yearStringToInteger( const QString &sNum, int &iLength ) const 00412 { 00413 return KCalendarSystemCoptic::yearStringToInteger( sNum, iLength ); 00414 } 00415 00416 int KCalendarSystemEthiopian::monthStringToInteger( const QString &sNum, int &iLength ) const 00417 { 00418 return KCalendarSystemCoptic::monthStringToInteger( sNum, iLength ); 00419 } 00420 00421 int KCalendarSystemEthiopian::dayStringToInteger( const QString &sNum, int &iLength ) const 00422 { 00423 return KCalendarSystemCoptic::dayStringToInteger( sNum, iLength ); 00424 } 00425 00426 QString KCalendarSystemEthiopian::formatDate( const QDate &date, KLocale::DateFormat format ) const 00427 { 00428 return KCalendarSystemCoptic::formatDate( date, format ); 00429 } 00430 00431 QDate KCalendarSystemEthiopian::readDate( const QString &str, bool *ok ) const 00432 { 00433 return KCalendarSystemCoptic::readDate( str, ok ); 00434 } 00435 00436 QDate KCalendarSystemEthiopian::readDate( const QString &intstr, const QString &fmt, bool *ok ) const 00437 { 00438 return KCalendarSystemCoptic::readDate( intstr, fmt, ok ); 00439 } 00440 00441 QDate KCalendarSystemEthiopian::readDate( const QString &str, KLocale::ReadDateFlags flags, bool *ok ) const 00442 { 00443 return KCalendarSystemCoptic::readDate( str, flags, ok ); 00444 } 00445 00446 int KCalendarSystemEthiopian::weekStartDay() const 00447 { 00448 return KCalendarSystemCoptic::weekStartDay(); 00449 } 00450 00451 int KCalendarSystemEthiopian::weekDayOfPray() const 00452 { 00453 return 7; 00454 } 00455 00456 bool KCalendarSystemEthiopian::isLunar() const 00457 { 00458 return KCalendarSystemCoptic::isLunar(); 00459 } 00460 00461 bool KCalendarSystemEthiopian::isLunisolar() const 00462 { 00463 return KCalendarSystemCoptic::isLunisolar(); 00464 } 00465 00466 bool KCalendarSystemEthiopian::isSolar() const 00467 { 00468 return KCalendarSystemCoptic::isSolar(); 00469 } 00470 00471 bool KCalendarSystemEthiopian::isProleptic() const 00472 { 00473 return false; 00474 } 00475 00476 bool KCalendarSystemEthiopian::julianDayToDate( int jd, int &year, int &month, int &day ) const 00477 { 00478 return KCalendarSystemCoptic::julianDayToDate( jd, year, month, day ); 00479 } 00480 00481 bool KCalendarSystemEthiopian::dateToJulianDay( int year, int month, int day, int &jd ) const 00482 { 00483 return KCalendarSystemCoptic::dateToJulianDay( year, month, day, jd ); 00484 }
KDE 4.6 API Reference