Warning, file /frameworks/kdelibs4support/src/kdecore/kcalendarsystemethiopian.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001 /* 0002 Copyright 2009, 2010 John Layt <john@layt.net> 0003 0004 This library is free software; you can redistribute it and/or 0005 modify it under the terms of the GNU Library General Public 0006 License as published by the Free Software Foundation; either 0007 version 2 of the License, or (at your option) any later version. 0008 0009 This library is distributed in the hope that it will be useful, 0010 but WITHOUT ANY WARRANTY; without even the implied warranty of 0011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0012 Library General Public License for more details. 0013 0014 You should have received a copy of the GNU Library General Public License 0015 along with this library; see the file COPYING.LIB. If not, write to 0016 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0017 Boston, MA 02110-1301, USA. 0018 */ 0019 0020 #include "kcalendarsystemethiopian_p.h" 0021 #include "kcalendarsystemcopticprivate_p.h" 0022 0023 #include "klocale.h" 0024 #include "klocalizedstring.h" 0025 0026 #include <QDate> 0027 #include <QCharRef> 0028 0029 //Reuse the Coptic private implementation 0030 class KCalendarSystemEthiopianPrivate : public KCalendarSystemCopticPrivate 0031 { 0032 public: 0033 KDELIBS4SUPPORT_DEPRECATED explicit KCalendarSystemEthiopianPrivate(KCalendarSystemEthiopian *q) : KCalendarSystemCopticPrivate(q) 0034 { 0035 } 0036 0037 ~KCalendarSystemEthiopianPrivate() override 0038 { 0039 } 0040 0041 void loadDefaultEraList() override; 0042 QString monthName(int month, int year, KLocale::DateTimeComponentFormat format, bool possessive) const override; 0043 QString weekDayName(int weekDay, KLocale::DateTimeComponentFormat format) const override; 0044 }; 0045 0046 void KCalendarSystemEthiopianPrivate::loadDefaultEraList() 0047 { 0048 QString name, shortName, format; 0049 // Incarnation Era, Amätä Mehrät, "Year of Mercy". 0050 name = i18nc("Calendar Era: Ethiopian Incarnation Era, years > 0, LongFormat", "Amata Mehrat"); 0051 shortName = i18nc("Calendar Era: Ethiopian Incarnation Era, years > 0, ShortFormat", "AM"); 0052 format = i18nc("(kdedt-format) Ethiopian, AM, full era year format used for %EY, e.g. 2000 AM", "%Ey %EC"); 0053 addEra('+', 1, q->epoch(), 1, q->latestValidDate(), name, shortName, format); 0054 } 0055 0056 // Names taken from http://www.ethiopianembassy.at/dates_cycles.htm, alternative transliterations exist 0057 QString KCalendarSystemEthiopianPrivate::monthName(int month, int year, KLocale::DateTimeComponentFormat format, bool possessive) const 0058 { 0059 Q_UNUSED(year); 0060 0061 QStringList languages = locale()->languageList(); 0062 0063 if (format == KLocale::NarrowName) { 0064 switch (month) { 0065 case 1: 0066 return ki18nc("Ethiopian month 1 - KLocale::NarrowName", "M").toString(languages); 0067 case 2: 0068 return ki18nc("Ethiopian month 2 - KLocale::NarrowName", "T").toString(languages); 0069 case 3: 0070 return ki18nc("Ethiopian month 3 - KLocale::NarrowName", "H").toString(languages); 0071 case 4: 0072 return ki18nc("Ethiopian month 4 - KLocale::NarrowName", "T").toString(languages); 0073 case 5: 0074 return ki18nc("Ethiopian month 5 - KLocale::NarrowName", "T").toString(languages); 0075 case 6: 0076 return ki18nc("Ethiopian month 6 - KLocale::NarrowName", "Y").toString(languages); 0077 case 7: 0078 return ki18nc("Ethiopian month 7 - KLocale::NarrowName", "M").toString(languages); 0079 case 8: 0080 return ki18nc("Ethiopian month 8 - KLocale::NarrowName", "M").toString(languages); 0081 case 9: 0082 return ki18nc("Ethiopian month 9 - KLocale::NarrowName", "G").toString(languages); 0083 case 10: 0084 return ki18nc("Ethiopian month 10 - KLocale::NarrowName", "S").toString(languages); 0085 case 11: 0086 return ki18nc("Ethiopian month 11 - KLocale::NarrowName", "H").toString(languages); 0087 case 12: 0088 return ki18nc("Ethiopian month 12 - KLocale::NarrowName", "N").toString(languages); 0089 case 13: 0090 return ki18nc("Ethiopian month 13 - KLocale::NarrowName", "P").toString(languages); 0091 default: 0092 return QString(); 0093 } 0094 } 0095 0096 if (format == KLocale::ShortName && possessive) { 0097 switch (month) { 0098 case 1: 0099 return ki18nc("Ethiopian month 1 - KLocale::ShortName Possessive", "of Mes").toString(languages); 0100 case 2: 0101 return ki18nc("Ethiopian month 2 - KLocale::ShortName Possessive", "of Teq").toString(languages); 0102 case 3: 0103 return ki18nc("Ethiopian month 3 - KLocale::ShortName Possessive", "of Hed").toString(languages); 0104 case 4: 0105 return ki18nc("Ethiopian month 4 - KLocale::ShortName Possessive", "of Tah").toString(languages); 0106 case 5: 0107 return ki18nc("Ethiopian month 5 - KLocale::ShortName Possessive", "of Ter").toString(languages); 0108 case 6: 0109 return ki18nc("Ethiopian month 6 - KLocale::ShortName Possessive", "of Yak").toString(languages); 0110 case 7: 0111 return ki18nc("Ethiopian month 7 - KLocale::ShortName Possessive", "of Mag").toString(languages); 0112 case 8: 0113 return ki18nc("Ethiopian month 8 - KLocale::ShortName Possessive", "of Miy").toString(languages); 0114 case 9: 0115 return ki18nc("Ethiopian month 9 - KLocale::ShortName Possessive", "of Gen").toString(languages); 0116 case 10: 0117 return ki18nc("Ethiopian month 10 - KLocale::ShortName Possessive", "of Sen").toString(languages); 0118 case 11: 0119 return ki18nc("Ethiopian month 11 - KLocale::ShortName Possessive", "of Ham").toString(languages); 0120 case 12: 0121 return ki18nc("Ethiopian month 12 - KLocale::ShortName Possessive", "of Neh").toString(languages); 0122 case 13: 0123 return ki18nc("Ethiopian month 13 - KLocale::ShortName Possessive", "of Pag").toString(languages); 0124 default: 0125 return QString(); 0126 } 0127 } 0128 0129 if (format == KLocale::ShortName && !possessive) { 0130 switch (month) { 0131 case 1: 0132 return ki18nc("Ethiopian month 1 - KLocale::ShortName", "Mes").toString(languages); 0133 case 2: 0134 return ki18nc("Ethiopian month 2 - KLocale::ShortName", "Teq").toString(languages); 0135 case 3: 0136 return ki18nc("Ethiopian month 3 - KLocale::ShortName", "Hed").toString(languages); 0137 case 4: 0138 return ki18nc("Ethiopian month 4 - KLocale::ShortName", "Tah").toString(languages); 0139 case 5: 0140 return ki18nc("Ethiopian month 5 - KLocale::ShortName", "Ter").toString(languages); 0141 case 6: 0142 return ki18nc("Ethiopian month 6 - KLocale::ShortName", "Yak").toString(languages); 0143 case 7: 0144 return ki18nc("Ethiopian month 7 - KLocale::ShortName", "Mag").toString(languages); 0145 case 8: 0146 return ki18nc("Ethiopian month 8 - KLocale::ShortName", "Miy").toString(languages); 0147 case 9: 0148 return ki18nc("Ethiopian month 9 - KLocale::ShortName", "Gen").toString(languages); 0149 case 10: 0150 return ki18nc("Ethiopian month 10 - KLocale::ShortName", "Sen").toString(languages); 0151 case 11: 0152 return ki18nc("Ethiopian month 11 - KLocale::ShortName", "Ham").toString(languages); 0153 case 12: 0154 return ki18nc("Ethiopian month 12 - KLocale::ShortName", "Neh").toString(languages); 0155 case 13: 0156 return ki18nc("Ethiopian month 13 - KLocale::ShortName", "Pag").toString(languages); 0157 default: 0158 return QString(); 0159 } 0160 } 0161 0162 if (format == KLocale::LongName && possessive) { 0163 switch (month) { 0164 case 1: 0165 return ki18nc("Ethiopian month 1 - KLocale::LongName Possessive", "of Meskerem").toString(languages); 0166 case 2: 0167 return ki18nc("Ethiopian month 2 - KLocale::LongName Possessive", "of Tequemt").toString(languages); 0168 case 3: 0169 return ki18nc("Ethiopian month 3 - KLocale::LongName Possessive", "of Hedar").toString(languages); 0170 case 4: 0171 return ki18nc("Ethiopian month 4 - KLocale::LongName Possessive", "of Tahsas").toString(languages); 0172 case 5: 0173 return ki18nc("Ethiopian month 5 - KLocale::LongName Possessive", "of Ter").toString(languages); 0174 case 6: 0175 return ki18nc("Ethiopian month 6 - KLocale::LongName Possessive", "of Yakatit").toString(languages); 0176 case 7: 0177 return ki18nc("Ethiopian month 7 - KLocale::LongName Possessive", "of Magabit").toString(languages); 0178 case 8: 0179 return ki18nc("Ethiopian month 8 - KLocale::LongName Possessive", "of Miyazya").toString(languages); 0180 case 9: 0181 return ki18nc("Ethiopian month 9 - KLocale::LongName Possessive", "of Genbot").toString(languages); 0182 case 10: 0183 return ki18nc("Ethiopian month 10 - KLocale::LongName Possessive", "of Sene").toString(languages); 0184 case 11: 0185 return ki18nc("Ethiopian month 11 - KLocale::LongName Possessive", "of Hamle").toString(languages); 0186 case 12: 0187 return ki18nc("Ethiopian month 12 - KLocale::LongName Possessive", "of Nehase").toString(languages); 0188 case 13: 0189 return ki18nc("Ethiopian month 13 - KLocale::LongName Possessive", "of Pagumen").toString(languages); 0190 default: 0191 return QString(); 0192 } 0193 } 0194 0195 // Default to LongName 0196 switch (month) { 0197 case 1: 0198 return ki18nc("Ethiopian month 1 - KLocale::LongName", "Meskerem").toString(languages); 0199 case 2: 0200 return ki18nc("Ethiopian month 2 - KLocale::LongName", "Tequemt").toString(languages); 0201 case 3: 0202 return ki18nc("Ethiopian month 3 - KLocale::LongName", "Hedar").toString(languages); 0203 case 4: 0204 return ki18nc("Ethiopian month 4 - KLocale::LongName", "Tahsas").toString(languages); 0205 case 5: 0206 return ki18nc("Ethiopian month 5 - KLocale::LongName", "Ter").toString(languages); 0207 case 6: 0208 return ki18nc("Ethiopian month 6 - KLocale::LongName", "Yakatit").toString(languages); 0209 case 7: 0210 return ki18nc("Ethiopian month 7 - KLocale::LongName", "Magabit").toString(languages); 0211 case 8: 0212 return ki18nc("Ethiopian month 8 - KLocale::LongName", "Miyazya").toString(languages); 0213 case 9: 0214 return ki18nc("Ethiopian month 9 - KLocale::LongName", "Genbot").toString(languages); 0215 case 10: 0216 return ki18nc("Ethiopian month 10 - KLocale::LongName", "Sene").toString(languages); 0217 case 11: 0218 return ki18nc("Ethiopian month 11 - KLocale::LongName", "Hamle").toString(languages); 0219 case 12: 0220 return ki18nc("Ethiopian month 12 - KLocale::LongName", "Nehase").toString(languages); 0221 case 13: 0222 return ki18nc("Ethiopian month 13 - KLocale::LongName", "Pagumen").toString(languages); 0223 default: 0224 return QString(); 0225 } 0226 } 0227 0228 // Names taken from http://www.ethiopianembassy.at/dates_cycles.htm, alternative transliterations exist 0229 QString KCalendarSystemEthiopianPrivate::weekDayName(int weekDay, KLocale::DateTimeComponentFormat format) const 0230 { 0231 QStringList languages = locale()->languageList(); 0232 0233 if (format == KLocale::NarrowName) { 0234 switch (weekDay) { 0235 case 1: 0236 return ki18nc("Ethiopian weekday 1 - KLocale::NarrowName ", "S").toString(languages); 0237 case 2: 0238 return ki18nc("Ethiopian weekday 2 - KLocale::NarrowName ", "M").toString(languages); 0239 case 3: 0240 return ki18nc("Ethiopian weekday 3 - KLocale::NarrowName ", "R").toString(languages); 0241 case 4: 0242 return ki18nc("Ethiopian weekday 4 - KLocale::NarrowName ", "H").toString(languages); 0243 case 5: 0244 return ki18nc("Ethiopian weekday 5 - KLocale::NarrowName ", "A").toString(languages); 0245 case 6: 0246 return ki18nc("Ethiopian weekday 6 - KLocale::NarrowName ", "Q").toString(languages); 0247 case 7: 0248 return ki18nc("Ethiopian weekday 7 - KLocale::NarrowName ", "E").toString(languages); 0249 default: 0250 return QString(); 0251 } 0252 } 0253 0254 if (format == KLocale::ShortName || format == KLocale:: ShortNumber) { 0255 switch (weekDay) { 0256 case 1: 0257 return ki18nc("Ethiopian weekday 1 - KLocale::ShortName", "Seg").toString(languages); 0258 case 2: 0259 return ki18nc("Ethiopian weekday 2 - KLocale::ShortName", "Mak").toString(languages); 0260 case 3: 0261 return ki18nc("Ethiopian weekday 3 - KLocale::ShortName", "Rob").toString(languages); 0262 case 4: 0263 return ki18nc("Ethiopian weekday 4 - KLocale::ShortName", "Ham").toString(languages); 0264 case 5: 0265 return ki18nc("Ethiopian weekday 5 - KLocale::ShortName", "Arb").toString(languages); 0266 case 6: 0267 return ki18nc("Ethiopian weekday 6 - KLocale::ShortName", "Qed").toString(languages); 0268 case 7: 0269 return ki18nc("Ethiopian weekday 7 - KLocale::ShortName", "Ehu").toString(languages); 0270 default: return QString(); 0271 } 0272 } 0273 0274 switch (weekDay) { 0275 case 1: 0276 return ki18nc("Ethiopian weekday 1 - KLocale::LongName", "Segno").toString(languages); 0277 case 2: 0278 return ki18nc("Ethiopian weekday 2 - KLocale::LongName", "Maksegno").toString(languages); 0279 case 3: 0280 return ki18nc("Ethiopian weekday 3 - KLocale::LongName", "Rob").toString(languages); 0281 case 4: 0282 return ki18nc("Ethiopian weekday 4 - KLocale::LongName", "Hamus").toString(languages); 0283 case 5: 0284 return ki18nc("Ethiopian weekday 5 - KLocale::LongName", "Arb").toString(languages); 0285 case 6: 0286 return ki18nc("Ethiopian weekday 6 - KLocale::LongName", "Qedame").toString(languages); 0287 case 7: 0288 return ki18nc("Ethiopian weekday 7 - KLocale::LongName", "Ehud").toString(languages); 0289 default: 0290 return QString(); 0291 } 0292 } 0293 0294 KCalendarSystemEthiopian::KCalendarSystemEthiopian(const KSharedConfig::Ptr config, const KLocale *locale) 0295 : KCalendarSystemCoptic(*new KCalendarSystemEthiopianPrivate(this), config, locale) 0296 { 0297 d_ptr->loadConfig(calendarType()); 0298 } 0299 0300 KCalendarSystemEthiopian::KCalendarSystemEthiopian(KCalendarSystemEthiopianPrivate &dd, 0301 const KSharedConfig::Ptr config, const KLocale *locale) 0302 : KCalendarSystemCoptic(dd, config, locale) 0303 { 0304 d_ptr->loadConfig(calendarType()); 0305 } 0306 0307 KCalendarSystemEthiopian::~KCalendarSystemEthiopian() 0308 { 0309 } 0310 0311 QString KCalendarSystemEthiopian::calendarType() const 0312 { 0313 return QLatin1String("ethiopian"); 0314 } 0315 0316 KLocale::CalendarSystem KCalendarSystemEthiopian::calendarSystem() const 0317 { 0318 return KLocale::EthiopianCalendar; 0319 } 0320 0321 QDate KCalendarSystemEthiopian::epoch() const 0322 { 0323 //0001-01-01, no Year 0. 0324 //0008-08-29 AD Julian 0325 return QDate::fromJulianDay(1724221); 0326 } 0327 0328 QDate KCalendarSystemEthiopian::earliestValidDate() const 0329 { 0330 //0001-01-01, no Year 0. 0331 //0008-08-29 AD Julian 0332 return QDate::fromJulianDay(1724221); 0333 } 0334 0335 QDate KCalendarSystemEthiopian::latestValidDate() const 0336 { 0337 // Set to last day of year 9999 until confirm date formats & widgets support > 9999 0338 //9999-12-30 0339 //100008-08-29 AD Julian 0340 return QDate::fromJulianDay(5376721); 0341 } 0342 0343 QString KCalendarSystemEthiopian::monthName(int month, int year, MonthNameFormat format) const 0344 { 0345 return KCalendarSystemCoptic::monthName(month, year, format); 0346 } 0347 0348 QString KCalendarSystemEthiopian::monthName(const QDate &date, MonthNameFormat format) const 0349 { 0350 return KCalendarSystemCoptic::monthName(date, format); 0351 } 0352 0353 QString KCalendarSystemEthiopian::weekDayName(int weekDay, WeekDayNameFormat format) const 0354 { 0355 return KCalendarSystemCoptic::weekDayName(weekDay, format); 0356 } 0357 0358 QString KCalendarSystemEthiopian::weekDayName(const QDate &date, WeekDayNameFormat format) const 0359 { 0360 return KCalendarSystemCoptic::weekDayName(date, format); 0361 } 0362 0363 bool KCalendarSystemEthiopian::isLunar() const 0364 { 0365 return KCalendarSystemCoptic::isLunar(); 0366 } 0367 0368 bool KCalendarSystemEthiopian::isLunisolar() const 0369 { 0370 return KCalendarSystemCoptic::isLunisolar(); 0371 } 0372 0373 bool KCalendarSystemEthiopian::isSolar() const 0374 { 0375 return KCalendarSystemCoptic::isSolar(); 0376 } 0377 0378 bool KCalendarSystemEthiopian::isProleptic() const 0379 { 0380 return false; 0381 } 0382 0383 bool KCalendarSystemEthiopian::julianDayToDate(qint64 jd, int &year, int &month, int &day) const 0384 { 0385 return KCalendarSystemCoptic::julianDayToDate(jd, year, month, day); 0386 } 0387 0388 bool KCalendarSystemEthiopian::dateToJulianDay(int year, int month, int day, qint64 &jd) const 0389 { 0390 return KCalendarSystemCoptic::dateToJulianDay(year, month, day, jd); 0391 }