KDELibs4Support

kcalendarsystemethiopian.cpp
1 /*
2  Copyright 2009, 2010 John Layt <[email protected]>
3 
4  This library is free software; you can redistribute it and/or
5  modify it under the terms of the GNU Library General Public
6  License as published by the Free Software Foundation; either
7  version 2 of the License, or (at your option) any later version.
8 
9  This library is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  Library General Public License for more details.
13 
14  You should have received a copy of the GNU Library General Public License
15  along with this library; see the file COPYING.LIB. If not, write to
16  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17  Boston, MA 02110-1301, USA.
18 */
19 
20 #include "kcalendarsystemethiopian_p.h"
21 #include "kcalendarsystemcopticprivate_p.h"
22 
23 #include "klocale.h"
24 #include "klocalizedstring.h"
25 
26 #include <QDate>
27 #include <QCharRef>
28 
29 //Reuse the Coptic private implementation
30 class KCalendarSystemEthiopianPrivate : public KCalendarSystemCopticPrivate
31 {
32 public:
33  KDELIBS4SUPPORT_DEPRECATED explicit KCalendarSystemEthiopianPrivate(KCalendarSystemEthiopian *q) : KCalendarSystemCopticPrivate(q)
34  {
35  }
36 
37  virtual ~KCalendarSystemEthiopianPrivate()
38  {
39  }
40 
41  void loadDefaultEraList() override;
42  QString monthName(int month, int year, KLocale::DateTimeComponentFormat format, bool possessive) const override;
43  QString weekDayName(int weekDay, KLocale::DateTimeComponentFormat format) const override;
44 };
45 
46 void KCalendarSystemEthiopianPrivate::loadDefaultEraList()
47 {
48  QString name, shortName, format;
49  // Incarnation Era, Amätä Mehrät, "Year of Mercy".
50  name = i18nc("Calendar Era: Ethiopian Incarnation Era, years > 0, LongFormat", "Amata Mehrat");
51  shortName = i18nc("Calendar Era: Ethiopian Incarnation Era, years > 0, ShortFormat", "AM");
52  format = i18nc("(kdedt-format) Ethiopian, AM, full era year format used for %EY, e.g. 2000 AM", "%Ey %EC");
53  addEra('+', 1, q->epoch(), 1, q->latestValidDate(), name, shortName, format);
54 }
55 
56 // Names taken from http://www.ethiopianembassy.at/dates_cycles.htm, alternative transliterations exist
57 QString KCalendarSystemEthiopianPrivate::monthName(int month, int year, KLocale::DateTimeComponentFormat format, bool possessive) const
58 {
59  Q_UNUSED(year);
60 
61  QStringList languages = locale()->languageList();
62 
63  if (format == KLocale::NarrowName) {
64  switch (month) {
65  case 1:
66  return ki18nc("Ethiopian month 1 - KLocale::NarrowName", "M").toString(languages);
67  case 2:
68  return ki18nc("Ethiopian month 2 - KLocale::NarrowName", "T").toString(languages);
69  case 3:
70  return ki18nc("Ethiopian month 3 - KLocale::NarrowName", "H").toString(languages);
71  case 4:
72  return ki18nc("Ethiopian month 4 - KLocale::NarrowName", "T").toString(languages);
73  case 5:
74  return ki18nc("Ethiopian month 5 - KLocale::NarrowName", "T").toString(languages);
75  case 6:
76  return ki18nc("Ethiopian month 6 - KLocale::NarrowName", "Y").toString(languages);
77  case 7:
78  return ki18nc("Ethiopian month 7 - KLocale::NarrowName", "M").toString(languages);
79  case 8:
80  return ki18nc("Ethiopian month 8 - KLocale::NarrowName", "M").toString(languages);
81  case 9:
82  return ki18nc("Ethiopian month 9 - KLocale::NarrowName", "G").toString(languages);
83  case 10:
84  return ki18nc("Ethiopian month 10 - KLocale::NarrowName", "S").toString(languages);
85  case 11:
86  return ki18nc("Ethiopian month 11 - KLocale::NarrowName", "H").toString(languages);
87  case 12:
88  return ki18nc("Ethiopian month 12 - KLocale::NarrowName", "N").toString(languages);
89  case 13:
90  return ki18nc("Ethiopian month 13 - KLocale::NarrowName", "P").toString(languages);
91  default:
92  return QString();
93  }
94  }
95 
96  if (format == KLocale::ShortName && possessive) {
97  switch (month) {
98  case 1:
99  return ki18nc("Ethiopian month 1 - KLocale::ShortName Possessive", "of Mes").toString(languages);
100  case 2:
101  return ki18nc("Ethiopian month 2 - KLocale::ShortName Possessive", "of Teq").toString(languages);
102  case 3:
103  return ki18nc("Ethiopian month 3 - KLocale::ShortName Possessive", "of Hed").toString(languages);
104  case 4:
105  return ki18nc("Ethiopian month 4 - KLocale::ShortName Possessive", "of Tah").toString(languages);
106  case 5:
107  return ki18nc("Ethiopian month 5 - KLocale::ShortName Possessive", "of Ter").toString(languages);
108  case 6:
109  return ki18nc("Ethiopian month 6 - KLocale::ShortName Possessive", "of Yak").toString(languages);
110  case 7:
111  return ki18nc("Ethiopian month 7 - KLocale::ShortName Possessive", "of Mag").toString(languages);
112  case 8:
113  return ki18nc("Ethiopian month 8 - KLocale::ShortName Possessive", "of Miy").toString(languages);
114  case 9:
115  return ki18nc("Ethiopian month 9 - KLocale::ShortName Possessive", "of Gen").toString(languages);
116  case 10:
117  return ki18nc("Ethiopian month 10 - KLocale::ShortName Possessive", "of Sen").toString(languages);
118  case 11:
119  return ki18nc("Ethiopian month 11 - KLocale::ShortName Possessive", "of Ham").toString(languages);
120  case 12:
121  return ki18nc("Ethiopian month 12 - KLocale::ShortName Possessive", "of Neh").toString(languages);
122  case 13:
123  return ki18nc("Ethiopian month 13 - KLocale::ShortName Possessive", "of Pag").toString(languages);
124  default:
125  return QString();
126  }
127  }
128 
129  if (format == KLocale::ShortName && !possessive) {
130  switch (month) {
131  case 1:
132  return ki18nc("Ethiopian month 1 - KLocale::ShortName", "Mes").toString(languages);
133  case 2:
134  return ki18nc("Ethiopian month 2 - KLocale::ShortName", "Teq").toString(languages);
135  case 3:
136  return ki18nc("Ethiopian month 3 - KLocale::ShortName", "Hed").toString(languages);
137  case 4:
138  return ki18nc("Ethiopian month 4 - KLocale::ShortName", "Tah").toString(languages);
139  case 5:
140  return ki18nc("Ethiopian month 5 - KLocale::ShortName", "Ter").toString(languages);
141  case 6:
142  return ki18nc("Ethiopian month 6 - KLocale::ShortName", "Yak").toString(languages);
143  case 7:
144  return ki18nc("Ethiopian month 7 - KLocale::ShortName", "Mag").toString(languages);
145  case 8:
146  return ki18nc("Ethiopian month 8 - KLocale::ShortName", "Miy").toString(languages);
147  case 9:
148  return ki18nc("Ethiopian month 9 - KLocale::ShortName", "Gen").toString(languages);
149  case 10:
150  return ki18nc("Ethiopian month 10 - KLocale::ShortName", "Sen").toString(languages);
151  case 11:
152  return ki18nc("Ethiopian month 11 - KLocale::ShortName", "Ham").toString(languages);
153  case 12:
154  return ki18nc("Ethiopian month 12 - KLocale::ShortName", "Neh").toString(languages);
155  case 13:
156  return ki18nc("Ethiopian month 13 - KLocale::ShortName", "Pag").toString(languages);
157  default:
158  return QString();
159  }
160  }
161 
162  if (format == KLocale::LongName && possessive) {
163  switch (month) {
164  case 1:
165  return ki18nc("Ethiopian month 1 - KLocale::LongName Possessive", "of Meskerem").toString(languages);
166  case 2:
167  return ki18nc("Ethiopian month 2 - KLocale::LongName Possessive", "of Tequemt").toString(languages);
168  case 3:
169  return ki18nc("Ethiopian month 3 - KLocale::LongName Possessive", "of Hedar").toString(languages);
170  case 4:
171  return ki18nc("Ethiopian month 4 - KLocale::LongName Possessive", "of Tahsas").toString(languages);
172  case 5:
173  return ki18nc("Ethiopian month 5 - KLocale::LongName Possessive", "of Ter").toString(languages);
174  case 6:
175  return ki18nc("Ethiopian month 6 - KLocale::LongName Possessive", "of Yakatit").toString(languages);
176  case 7:
177  return ki18nc("Ethiopian month 7 - KLocale::LongName Possessive", "of Magabit").toString(languages);
178  case 8:
179  return ki18nc("Ethiopian month 8 - KLocale::LongName Possessive", "of Miyazya").toString(languages);
180  case 9:
181  return ki18nc("Ethiopian month 9 - KLocale::LongName Possessive", "of Genbot").toString(languages);
182  case 10:
183  return ki18nc("Ethiopian month 10 - KLocale::LongName Possessive", "of Sene").toString(languages);
184  case 11:
185  return ki18nc("Ethiopian month 11 - KLocale::LongName Possessive", "of Hamle").toString(languages);
186  case 12:
187  return ki18nc("Ethiopian month 12 - KLocale::LongName Possessive", "of Nehase").toString(languages);
188  case 13:
189  return ki18nc("Ethiopian month 13 - KLocale::LongName Possessive", "of Pagumen").toString(languages);
190  default:
191  return QString();
192  }
193  }
194 
195  // Default to LongName
196  switch (month) {
197  case 1:
198  return ki18nc("Ethiopian month 1 - KLocale::LongName", "Meskerem").toString(languages);
199  case 2:
200  return ki18nc("Ethiopian month 2 - KLocale::LongName", "Tequemt").toString(languages);
201  case 3:
202  return ki18nc("Ethiopian month 3 - KLocale::LongName", "Hedar").toString(languages);
203  case 4:
204  return ki18nc("Ethiopian month 4 - KLocale::LongName", "Tahsas").toString(languages);
205  case 5:
206  return ki18nc("Ethiopian month 5 - KLocale::LongName", "Ter").toString(languages);
207  case 6:
208  return ki18nc("Ethiopian month 6 - KLocale::LongName", "Yakatit").toString(languages);
209  case 7:
210  return ki18nc("Ethiopian month 7 - KLocale::LongName", "Magabit").toString(languages);
211  case 8:
212  return ki18nc("Ethiopian month 8 - KLocale::LongName", "Miyazya").toString(languages);
213  case 9:
214  return ki18nc("Ethiopian month 9 - KLocale::LongName", "Genbot").toString(languages);
215  case 10:
216  return ki18nc("Ethiopian month 10 - KLocale::LongName", "Sene").toString(languages);
217  case 11:
218  return ki18nc("Ethiopian month 11 - KLocale::LongName", "Hamle").toString(languages);
219  case 12:
220  return ki18nc("Ethiopian month 12 - KLocale::LongName", "Nehase").toString(languages);
221  case 13:
222  return ki18nc("Ethiopian month 13 - KLocale::LongName", "Pagumen").toString(languages);
223  default:
224  return QString();
225  }
226 }
227 
228 // Names taken from http://www.ethiopianembassy.at/dates_cycles.htm, alternative transliterations exist
229 QString KCalendarSystemEthiopianPrivate::weekDayName(int weekDay, KLocale::DateTimeComponentFormat format) const
230 {
231  QStringList languages = locale()->languageList();
232 
233  if (format == KLocale::NarrowName) {
234  switch (weekDay) {
235  case 1:
236  return ki18nc("Ethiopian weekday 1 - KLocale::NarrowName ", "S").toString(languages);
237  case 2:
238  return ki18nc("Ethiopian weekday 2 - KLocale::NarrowName ", "M").toString(languages);
239  case 3:
240  return ki18nc("Ethiopian weekday 3 - KLocale::NarrowName ", "R").toString(languages);
241  case 4:
242  return ki18nc("Ethiopian weekday 4 - KLocale::NarrowName ", "H").toString(languages);
243  case 5:
244  return ki18nc("Ethiopian weekday 5 - KLocale::NarrowName ", "A").toString(languages);
245  case 6:
246  return ki18nc("Ethiopian weekday 6 - KLocale::NarrowName ", "Q").toString(languages);
247  case 7:
248  return ki18nc("Ethiopian weekday 7 - KLocale::NarrowName ", "E").toString(languages);
249  default:
250  return QString();
251  }
252  }
253 
254  if (format == KLocale::ShortName || format == KLocale:: ShortNumber) {
255  switch (weekDay) {
256  case 1:
257  return ki18nc("Ethiopian weekday 1 - KLocale::ShortName", "Seg").toString(languages);
258  case 2:
259  return ki18nc("Ethiopian weekday 2 - KLocale::ShortName", "Mak").toString(languages);
260  case 3:
261  return ki18nc("Ethiopian weekday 3 - KLocale::ShortName", "Rob").toString(languages);
262  case 4:
263  return ki18nc("Ethiopian weekday 4 - KLocale::ShortName", "Ham").toString(languages);
264  case 5:
265  return ki18nc("Ethiopian weekday 5 - KLocale::ShortName", "Arb").toString(languages);
266  case 6:
267  return ki18nc("Ethiopian weekday 6 - KLocale::ShortName", "Qed").toString(languages);
268  case 7:
269  return ki18nc("Ethiopian weekday 7 - KLocale::ShortName", "Ehu").toString(languages);
270  default: return QString();
271  }
272  }
273 
274  switch (weekDay) {
275  case 1:
276  return ki18nc("Ethiopian weekday 1 - KLocale::LongName", "Segno").toString(languages);
277  case 2:
278  return ki18nc("Ethiopian weekday 2 - KLocale::LongName", "Maksegno").toString(languages);
279  case 3:
280  return ki18nc("Ethiopian weekday 3 - KLocale::LongName", "Rob").toString(languages);
281  case 4:
282  return ki18nc("Ethiopian weekday 4 - KLocale::LongName", "Hamus").toString(languages);
283  case 5:
284  return ki18nc("Ethiopian weekday 5 - KLocale::LongName", "Arb").toString(languages);
285  case 6:
286  return ki18nc("Ethiopian weekday 6 - KLocale::LongName", "Qedame").toString(languages);
287  case 7:
288  return ki18nc("Ethiopian weekday 7 - KLocale::LongName", "Ehud").toString(languages);
289  default:
290  return QString();
291  }
292 }
293 
294 KCalendarSystemEthiopian::KCalendarSystemEthiopian(const KSharedConfig::Ptr config, const KLocale *locale)
295  : KCalendarSystemCoptic(*new KCalendarSystemEthiopianPrivate(this), config, locale)
296 {
297  d_ptr->loadConfig(calendarType());
298 }
299 
300 KCalendarSystemEthiopian::KCalendarSystemEthiopian(KCalendarSystemEthiopianPrivate &dd,
301  const KSharedConfig::Ptr config, const KLocale *locale)
302  : KCalendarSystemCoptic(dd, config, locale)
303 {
304  d_ptr->loadConfig(calendarType());
305 }
306 
307 KCalendarSystemEthiopian::~KCalendarSystemEthiopian()
308 {
309 }
310 
311 QString KCalendarSystemEthiopian::calendarType() const
312 {
313  return QLatin1String("ethiopian");
314 }
315 
316 KLocale::CalendarSystem KCalendarSystemEthiopian::calendarSystem() const
317 {
319 }
320 
321 QDate KCalendarSystemEthiopian::epoch() const
322 {
323  //0001-01-01, no Year 0.
324  //0008-08-29 AD Julian
325  return QDate::fromJulianDay(1724221);
326 }
327 
328 QDate KCalendarSystemEthiopian::earliestValidDate() const
329 {
330  //0001-01-01, no Year 0.
331  //0008-08-29 AD Julian
332  return QDate::fromJulianDay(1724221);
333 }
334 
335 QDate KCalendarSystemEthiopian::latestValidDate() const
336 {
337  // Set to last day of year 9999 until confirm date formats & widgets support > 9999
338  //9999-12-30
339  //100008-08-29 AD Julian
340  return QDate::fromJulianDay(5376721);
341 }
342 
343 QString KCalendarSystemEthiopian::monthName(int month, int year, MonthNameFormat format) const
344 {
345  return KCalendarSystemCoptic::monthName(month, year, format);
346 }
347 
348 QString KCalendarSystemEthiopian::monthName(const QDate &date, MonthNameFormat format) const
349 {
350  return KCalendarSystemCoptic::monthName(date, format);
351 }
352 
353 QString KCalendarSystemEthiopian::weekDayName(int weekDay, WeekDayNameFormat format) const
354 {
355  return KCalendarSystemCoptic::weekDayName(weekDay, format);
356 }
357 
358 QString KCalendarSystemEthiopian::weekDayName(const QDate &date, WeekDayNameFormat format) const
359 {
360  return KCalendarSystemCoptic::weekDayName(date, format);
361 }
362 
363 bool KCalendarSystemEthiopian::isLunar() const
364 {
365  return KCalendarSystemCoptic::isLunar();
366 }
367 
368 bool KCalendarSystemEthiopian::isLunisolar() const
369 {
370  return KCalendarSystemCoptic::isLunisolar();
371 }
372 
373 bool KCalendarSystemEthiopian::isSolar() const
374 {
375  return KCalendarSystemCoptic::isSolar();
376 }
377 
378 bool KCalendarSystemEthiopian::isProleptic() const
379 {
380  return false;
381 }
382 
383 bool KCalendarSystemEthiopian::julianDayToDate(qint64 jd, int &year, int &month, int &day) const
384 {
385  return KCalendarSystemCoptic::julianDayToDate(jd, year, month, day);
386 }
387 
388 bool KCalendarSystemEthiopian::dateToJulianDay(int year, int month, int day, qint64 &jd) const
389 {
390  return KCalendarSystemCoptic::dateToJulianDay(year, month, day, jd);
391 }
Narrow text format, may not be unique, e.g.
Definition: klocale.h:775
Ethiopian Calendar, aka Ethiopic Calendar.
Definition: klocale.h:652
QString toString() const
QString name(const QVariant &location)
virtual int day(const QDate &date) const
Returns the day portion of a given date in the current calendar system.
MonthNameFormat
Format for returned month / day name.
Number at its natural width, e.g.
Definition: klocale.h:772
DateTimeComponentFormat
Definition: klocale.h:770
CalendarSystem
Definition: klocale.h:646
QString i18nc(const char *context, const char *text, const TYPE &arg...)
Long text format, e.g.
Definition: klocale.h:777
WeekDayNameFormat
Format for returned month / day name.
Short text format, e.g.
Definition: klocale.h:776
KLocalizedString KI18N_EXPORT ki18nc(const char *context, const char *text)
KLocale provides support for language and country specific stuff.
Definition: klocale.h:75
QDate fromJulianDay(qint64 jd)
virtual QString calendarType() const =0
LocaleWrapper locale()
Returns the global locale object.
Definition: kglobal.cpp:119
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Thu Jul 9 2020 22:57:47 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.