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 virtual ~KCalendarSystemEthiopianPrivate() { 00037 } 00038 00039 virtual KLocale::CalendarSystem calendarSystem() const; 00040 virtual void loadDefaultEraList(); 00041 virtual QString monthName(int month, int year, KLocale::DateTimeComponentFormat format, bool possessive) const; 00042 virtual QString weekDayName(int weekDay, KLocale::DateTimeComponentFormat format) const; 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 // Names taken from http://www.ethiopianembassy.at/dates_cycles.htm, alternative transliterations exist 00061 QString KCalendarSystemEthiopianPrivate::monthName(int month, int year, KLocale::DateTimeComponentFormat format, bool possessive) const 00062 { 00063 Q_UNUSED(year); 00064 00065 if (format == KLocale::NarrowName) { 00066 switch (month) { 00067 case 1: 00068 return ki18nc("Ethiopian month 1 - KLocale::NarrowName", "M").toString(locale()); 00069 case 2: 00070 return ki18nc("Ethiopian month 2 - KLocale::NarrowName", "T").toString(locale()); 00071 case 3: 00072 return ki18nc("Ethiopian month 3 - KLocale::NarrowName", "H").toString(locale()); 00073 case 4: 00074 return ki18nc("Ethiopian month 4 - KLocale::NarrowName", "T").toString(locale()); 00075 case 5: 00076 return ki18nc("Ethiopian month 5 - KLocale::NarrowName", "T").toString(locale()); 00077 case 6: 00078 return ki18nc("Ethiopian month 6 - KLocale::NarrowName", "Y").toString(locale()); 00079 case 7: 00080 return ki18nc("Ethiopian month 7 - KLocale::NarrowName", "M").toString(locale()); 00081 case 8: 00082 return ki18nc("Ethiopian month 8 - KLocale::NarrowName", "M").toString(locale()); 00083 case 9: 00084 return ki18nc("Ethiopian month 9 - KLocale::NarrowName", "G").toString(locale()); 00085 case 10: 00086 return ki18nc("Ethiopian month 10 - KLocale::NarrowName", "S").toString(locale()); 00087 case 11: 00088 return ki18nc("Ethiopian month 11 - KLocale::NarrowName", "H").toString(locale()); 00089 case 12: 00090 return ki18nc("Ethiopian month 12 - KLocale::NarrowName", "N").toString(locale()); 00091 case 13: 00092 return ki18nc("Ethiopian month 13 - KLocale::NarrowName", "P").toString(locale()); 00093 default: 00094 return QString(); 00095 } 00096 } 00097 00098 if (format == KLocale::ShortName && possessive) { 00099 switch (month) { 00100 case 1: 00101 return ki18nc("Ethiopian month 1 - KLocale::ShortName Possessive", "of Mes").toString(locale()); 00102 case 2: 00103 return ki18nc("Ethiopian month 2 - KLocale::ShortName Possessive", "of Teq").toString(locale()); 00104 case 3: 00105 return ki18nc("Ethiopian month 3 - KLocale::ShortName Possessive", "of Hed").toString(locale()); 00106 case 4: 00107 return ki18nc("Ethiopian month 4 - KLocale::ShortName Possessive", "of Tah").toString(locale()); 00108 case 5: 00109 return ki18nc("Ethiopian month 5 - KLocale::ShortName Possessive", "of Ter").toString(locale()); 00110 case 6: 00111 return ki18nc("Ethiopian month 6 - KLocale::ShortName Possessive", "of Yak").toString(locale()); 00112 case 7: 00113 return ki18nc("Ethiopian month 7 - KLocale::ShortName Possessive", "of Mag").toString(locale()); 00114 case 8: 00115 return ki18nc("Ethiopian month 8 - KLocale::ShortName Possessive", "of Miy").toString(locale()); 00116 case 9: 00117 return ki18nc("Ethiopian month 9 - KLocale::ShortName Possessive", "of Gen").toString(locale()); 00118 case 10: 00119 return ki18nc("Ethiopian month 10 - KLocale::ShortName Possessive", "of Sen").toString(locale()); 00120 case 11: 00121 return ki18nc("Ethiopian month 11 - KLocale::ShortName Possessive", "of Ham").toString(locale()); 00122 case 12: 00123 return ki18nc("Ethiopian month 12 - KLocale::ShortName Possessive", "of Neh").toString(locale()); 00124 case 13: 00125 return ki18nc("Ethiopian month 13 - KLocale::ShortName Possessive", "of Pag").toString(locale()); 00126 default: 00127 return QString(); 00128 } 00129 } 00130 00131 if (format == KLocale::ShortName && !possessive) { 00132 switch (month) { 00133 case 1: 00134 return ki18nc("Ethiopian month 1 - KLocale::ShortName", "Mes").toString(locale()); 00135 case 2: 00136 return ki18nc("Ethiopian month 2 - KLocale::ShortName", "Teq").toString(locale()); 00137 case 3: 00138 return ki18nc("Ethiopian month 3 - KLocale::ShortName", "Hed").toString(locale()); 00139 case 4: 00140 return ki18nc("Ethiopian month 4 - KLocale::ShortName", "Tah").toString(locale()); 00141 case 5: 00142 return ki18nc("Ethiopian month 5 - KLocale::ShortName", "Ter").toString(locale()); 00143 case 6: 00144 return ki18nc("Ethiopian month 6 - KLocale::ShortName", "Yak").toString(locale()); 00145 case 7: 00146 return ki18nc("Ethiopian month 7 - KLocale::ShortName", "Mag").toString(locale()); 00147 case 8: 00148 return ki18nc("Ethiopian month 8 - KLocale::ShortName", "Miy").toString(locale()); 00149 case 9: 00150 return ki18nc("Ethiopian month 9 - KLocale::ShortName", "Gen").toString(locale()); 00151 case 10: 00152 return ki18nc("Ethiopian month 10 - KLocale::ShortName", "Sen").toString(locale()); 00153 case 11: 00154 return ki18nc("Ethiopian month 11 - KLocale::ShortName", "Ham").toString(locale()); 00155 case 12: 00156 return ki18nc("Ethiopian month 12 - KLocale::ShortName", "Neh").toString(locale()); 00157 case 13: 00158 return ki18nc("Ethiopian month 13 - KLocale::ShortName", "Pag").toString(locale()); 00159 default: 00160 return QString(); 00161 } 00162 } 00163 00164 if (format == KLocale::LongName && possessive) { 00165 switch (month) { 00166 case 1: 00167 return ki18nc("Ethiopian month 1 - KLocale::LongName Possessive", "of Meskerem").toString(locale()); 00168 case 2: 00169 return ki18nc("Ethiopian month 2 - KLocale::LongName Possessive", "of Tequemt").toString(locale()); 00170 case 3: 00171 return ki18nc("Ethiopian month 3 - KLocale::LongName Possessive", "of Hedar").toString(locale()); 00172 case 4: 00173 return ki18nc("Ethiopian month 4 - KLocale::LongName Possessive", "of Tahsas").toString(locale()); 00174 case 5: 00175 return ki18nc("Ethiopian month 5 - KLocale::LongName Possessive", "of Ter").toString(locale()); 00176 case 6: 00177 return ki18nc("Ethiopian month 6 - KLocale::LongName Possessive", "of Yakatit").toString(locale()); 00178 case 7: 00179 return ki18nc("Ethiopian month 7 - KLocale::LongName Possessive", "of Magabit").toString(locale()); 00180 case 8: 00181 return ki18nc("Ethiopian month 8 - KLocale::LongName Possessive", "of Miyazya").toString(locale()); 00182 case 9: 00183 return ki18nc("Ethiopian month 9 - KLocale::LongName Possessive", "of Genbot").toString(locale()); 00184 case 10: 00185 return ki18nc("Ethiopian month 10 - KLocale::LongName Possessive", "of Sene").toString(locale()); 00186 case 11: 00187 return ki18nc("Ethiopian month 11 - KLocale::LongName Possessive", "of Hamle").toString(locale()); 00188 case 12: 00189 return ki18nc("Ethiopian month 12 - KLocale::LongName Possessive", "of Nehase").toString(locale()); 00190 case 13: 00191 return ki18nc("Ethiopian month 13 - KLocale::LongName Possessive", "of Pagumen").toString(locale()); 00192 default: 00193 return QString(); 00194 } 00195 } 00196 00197 // Default to LongName 00198 switch (month) { 00199 case 1: 00200 return ki18nc("Ethiopian month 1 - KLocale::LongName", "Meskerem").toString(locale()); 00201 case 2: 00202 return ki18nc("Ethiopian month 2 - KLocale::LongName", "Tequemt").toString(locale()); 00203 case 3: 00204 return ki18nc("Ethiopian month 3 - KLocale::LongName", "Hedar").toString(locale()); 00205 case 4: 00206 return ki18nc("Ethiopian month 4 - KLocale::LongName", "Tahsas").toString(locale()); 00207 case 5: 00208 return ki18nc("Ethiopian month 5 - KLocale::LongName", "Ter").toString(locale()); 00209 case 6: 00210 return ki18nc("Ethiopian month 6 - KLocale::LongName", "Yakatit").toString(locale()); 00211 case 7: 00212 return ki18nc("Ethiopian month 7 - KLocale::LongName", "Magabit").toString(locale()); 00213 case 8: 00214 return ki18nc("Ethiopian month 8 - KLocale::LongName", "Miyazya").toString(locale()); 00215 case 9: 00216 return ki18nc("Ethiopian month 9 - KLocale::LongName", "Genbot").toString(locale()); 00217 case 10: 00218 return ki18nc("Ethiopian month 10 - KLocale::LongName", "Sene").toString(locale()); 00219 case 11: 00220 return ki18nc("Ethiopian month 11 - KLocale::LongName", "Hamle").toString(locale()); 00221 case 12: 00222 return ki18nc("Ethiopian month 12 - KLocale::LongName", "Nehase").toString(locale()); 00223 case 13: 00224 return ki18nc("Ethiopian month 13 - KLocale::LongName", "Pagumen").toString(locale()); 00225 default: 00226 return QString(); 00227 } 00228 } 00229 00230 // Names taken from http://www.ethiopianembassy.at/dates_cycles.htm, alternative transliterations exist 00231 QString KCalendarSystemEthiopianPrivate::weekDayName(int weekDay, KLocale::DateTimeComponentFormat format) const 00232 { 00233 if (format == KLocale::NarrowName) { 00234 switch (weekDay) { 00235 case 1: 00236 return ki18nc("Ethiopian weekday 1 - KLocale::NarrowName ", "S").toString(locale()); 00237 case 2: 00238 return ki18nc("Ethiopian weekday 2 - KLocale::NarrowName ", "M").toString(locale()); 00239 case 3: 00240 return ki18nc("Ethiopian weekday 3 - KLocale::NarrowName ", "R").toString(locale()); 00241 case 4: 00242 return ki18nc("Ethiopian weekday 4 - KLocale::NarrowName ", "H").toString(locale()); 00243 case 5: 00244 return ki18nc("Ethiopian weekday 5 - KLocale::NarrowName ", "A").toString(locale()); 00245 case 6: 00246 return ki18nc("Ethiopian weekday 6 - KLocale::NarrowName ", "Q").toString(locale()); 00247 case 7: 00248 return ki18nc("Ethiopian weekday 7 - KLocale::NarrowName ", "E").toString(locale()); 00249 default: 00250 return QString(); 00251 } 00252 } 00253 00254 if (format == KLocale::ShortName || format == KLocale:: ShortNumber) { 00255 switch (weekDay) { 00256 case 1: 00257 return ki18nc("Ethiopian weekday 1 - KLocale::ShortName", "Seg").toString(locale()); 00258 case 2: 00259 return ki18nc("Ethiopian weekday 2 - KLocale::ShortName", "Mak").toString(locale()); 00260 case 3: 00261 return ki18nc("Ethiopian weekday 3 - KLocale::ShortName", "Rob").toString(locale()); 00262 case 4: 00263 return ki18nc("Ethiopian weekday 4 - KLocale::ShortName", "Ham").toString(locale()); 00264 case 5: 00265 return ki18nc("Ethiopian weekday 5 - KLocale::ShortName", "Arb").toString(locale()); 00266 case 6: 00267 return ki18nc("Ethiopian weekday 6 - KLocale::ShortName", "Qed").toString(locale()); 00268 case 7: 00269 return ki18nc("Ethiopian weekday 7 - KLocale::ShortName", "Ehu").toString(locale()); 00270 default: return QString(); 00271 } 00272 } 00273 00274 switch (weekDay) { 00275 case 1: 00276 return ki18nc("Ethiopian weekday 1 - KLocale::LongName", "Segno").toString(locale()); 00277 case 2: 00278 return ki18nc("Ethiopian weekday 2 - KLocale::LongName", "Maksegno").toString(locale()); 00279 case 3: 00280 return ki18nc("Ethiopian weekday 3 - KLocale::LongName", "Rob").toString(locale()); 00281 case 4: 00282 return ki18nc("Ethiopian weekday 4 - KLocale::LongName", "Hamus").toString(locale()); 00283 case 5: 00284 return ki18nc("Ethiopian weekday 5 - KLocale::LongName", "Arb").toString(locale()); 00285 case 6: 00286 return ki18nc("Ethiopian weekday 6 - KLocale::LongName", "Qedame").toString(locale()); 00287 case 7: 00288 return ki18nc("Ethiopian weekday 7 - KLocale::LongName", "Ehud").toString(locale()); 00289 default: 00290 return QString(); 00291 } 00292 } 00293 00294 00295 KCalendarSystemEthiopian::KCalendarSystemEthiopian(const KLocale *locale) 00296 : KCalendarSystemCoptic(*new KCalendarSystemEthiopianPrivate(this), KSharedConfig::Ptr(), locale) 00297 { 00298 d_ptr->loadConfig(calendarType()); 00299 } 00300 00301 KCalendarSystemEthiopian::KCalendarSystemEthiopian(const KSharedConfig::Ptr config, const KLocale *locale) 00302 : KCalendarSystemCoptic(*new KCalendarSystemEthiopianPrivate(this), config, locale) 00303 { 00304 d_ptr->loadConfig(calendarType()); 00305 } 00306 00307 KCalendarSystemEthiopian::KCalendarSystemEthiopian(KCalendarSystemEthiopianPrivate &dd, 00308 const KSharedConfig::Ptr config, const KLocale *locale) 00309 : KCalendarSystemCoptic(dd, config, locale) 00310 { 00311 d_ptr->loadConfig(calendarType()); 00312 } 00313 00314 KCalendarSystemEthiopian::~KCalendarSystemEthiopian() 00315 { 00316 } 00317 00318 QString KCalendarSystemEthiopian::calendarType() const 00319 { 00320 return QLatin1String("ethiopian"); 00321 } 00322 00323 QDate KCalendarSystemEthiopian::epoch() const 00324 { 00325 //0001-01-01, no Year 0. 00326 //0008-08-29 AD Julian 00327 return QDate::fromJulianDay(1724221); 00328 } 00329 00330 QDate KCalendarSystemEthiopian::earliestValidDate() const 00331 { 00332 //0001-01-01, no Year 0. 00333 //0008-08-29 AD Julian 00334 return QDate::fromJulianDay(1724221); 00335 } 00336 00337 QDate KCalendarSystemEthiopian::latestValidDate() const 00338 { 00339 // Set to last day of year 9999 until confirm date formats & widgets support > 9999 00340 //9999-12-30 00341 //100008-08-29 AD Julian 00342 return QDate::fromJulianDay(5376721); 00343 } 00344 00345 bool KCalendarSystemEthiopian::isValid(int year, int month, int day) const 00346 { 00347 return KCalendarSystemCoptic::isValid(year, month, day); 00348 } 00349 00350 bool KCalendarSystemEthiopian::isValid(const QDate &date) const 00351 { 00352 return KCalendarSystemCoptic::isValid(date); 00353 } 00354 00355 bool KCalendarSystemEthiopian::isLeapYear(int year) const 00356 { 00357 return KCalendarSystemCoptic::isLeapYear(year); 00358 } 00359 00360 bool KCalendarSystemEthiopian::isLeapYear(const QDate &date) const 00361 { 00362 return KCalendarSystemCoptic::isLeapYear(date); 00363 } 00364 00365 QString KCalendarSystemEthiopian::monthName(int month, int year, MonthNameFormat format) const 00366 { 00367 return KCalendarSystemCoptic::monthName(month, year, format); 00368 } 00369 00370 QString KCalendarSystemEthiopian::monthName(const QDate &date, MonthNameFormat format) const 00371 { 00372 return KCalendarSystemCoptic::monthName(date, format); 00373 } 00374 00375 QString KCalendarSystemEthiopian::weekDayName(int weekDay, WeekDayNameFormat format) const 00376 { 00377 return KCalendarSystemCoptic::weekDayName(weekDay, format); 00378 } 00379 00380 QString KCalendarSystemEthiopian::weekDayName(const QDate &date, WeekDayNameFormat format) const 00381 { 00382 return KCalendarSystemCoptic::weekDayName(date, format); 00383 } 00384 00385 int KCalendarSystemEthiopian::weekDayOfPray() const 00386 { 00387 return 7; 00388 } 00389 00390 bool KCalendarSystemEthiopian::isLunar() const 00391 { 00392 return KCalendarSystemCoptic::isLunar(); 00393 } 00394 00395 bool KCalendarSystemEthiopian::isLunisolar() const 00396 { 00397 return KCalendarSystemCoptic::isLunisolar(); 00398 } 00399 00400 bool KCalendarSystemEthiopian::isSolar() const 00401 { 00402 return KCalendarSystemCoptic::isSolar(); 00403 } 00404 00405 bool KCalendarSystemEthiopian::isProleptic() const 00406 { 00407 return false; 00408 } 00409 00410 bool KCalendarSystemEthiopian::julianDayToDate(int jd, int &year, int &month, int &day) const 00411 { 00412 return KCalendarSystemCoptic::julianDayToDate(jd, year, month, day); 00413 } 00414 00415 bool KCalendarSystemEthiopian::dateToJulianDay(int year, int month, int day, int &jd) const 00416 { 00417 return KCalendarSystemCoptic::dateToJulianDay(year, month, day, jd); 00418 }
KDE 4.7 API Reference