KDELibs4Support

kcalendarsystemjapanese.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 "kcalendarsystemjapanese_p.h"
21 #include "kcalendarsystemgregorianprivate_p.h"
22 
23 #include "klocale.h"
24 #include "klocalizedstring.h"
25 
26 #include <QDate>
27 
28 //Reuse the Gregorian private implementation
29 class KCalendarSystemJapanesePrivate : public KCalendarSystemGregorianPrivate
30 {
31 public:
32  KDELIBS4SUPPORT_DEPRECATED explicit KCalendarSystemJapanesePrivate(KCalendarSystemJapanese *q);
33  virtual ~KCalendarSystemJapanesePrivate();
34 
35  void loadDefaultEraList() override;
36  int earliestValidYear() const override;
37 };
38 
39 //Override only a few of the Gregorian private methods
40 
41 KCalendarSystemJapanesePrivate::KCalendarSystemJapanesePrivate(KCalendarSystemJapanese *q)
42  : KCalendarSystemGregorianPrivate(q)
43 {
44 }
45 
46 KCalendarSystemJapanesePrivate::~KCalendarSystemJapanesePrivate()
47 {
48 }
49 
50 void KCalendarSystemJapanesePrivate::loadDefaultEraList()
51 {
52  QString name, shortName, format;
53 
54  // Nengō, Only do most recent for now, use AD for the rest.
55  // Feel free to add more, but have mercy on the translators :-)
56 
57  name = i18nc("Calendar Era: Gregorian Christian Era, years > 0, LongFormat", "Anno Domini");
58  shortName = i18nc("Calendar Era: Gregorian Christian Era, years > 0, ShortFormat", "AD");
59  format = i18nc("(kdedt-format) Gregorian, AD, full era year format used for %EY, e.g. 2000 AD", "%Ey %EC");
60  addEra('+', 1, q->epoch(), 1, QDate(1868, 9, 7), name, shortName, format);
61 
62  name = i18nc("Calendar Era: Japanese Nengō, Meiji Era, LongFormat", "Meiji");
63  shortName = name;
64  format = i18nc("(kdedt-format) Japanese, Meiji, full era year format used for %EY, year = 1, e.g. Meiji 1", "%EC Gannen");
65  addEra('+', 1, QDate(1868, 9, 8), 1868, QDate(1868, 12, 31), name, shortName, format);
66  format = i18nc("(kdedt-format) Japanese, Meiji, full era year format used for %EY, year > 1, e.g. Meiji 22", "%EC %Ey");
67  addEra('+', 2, QDate(1869, 1, 1), 1869, QDate(1912, 7, 29), name, shortName, format);
68 
69  name = i18nc("Calendar Era: Japanese Nengō, Taishō Era, LongFormat", "Taishō");
70  shortName = name;
71  format = i18nc("(kdedt-format) Japanese, Taishō, full era year format used for %EY, year = 1, e.g. Taishō 1", "%EC Gannen");
72  addEra('+', 1, QDate(1912, 7, 30), 1912, QDate(1912, 12, 31), name, shortName, format);
73  format = i18nc("(kdedt-format) Japanese, Taishō, full era year format used for %EY, year > 1, e.g. Taishō 22", "%EC %Ey");
74  addEra('+', 2, QDate(1913, 1, 1), 1913, QDate(1926, 12, 24), name, shortName, format);
75 
76  name = i18nc("Calendar Era: Japanese Nengō, Shōwa Era, LongFormat", "Shōwa");
77  shortName = name;
78  format = i18nc("(kdedt-format) Japanese, Shōwa, full era year format used for %EY, year = 1, e.g. Shōwa 1", "%EC Gannen");
79  addEra('+', 1, QDate(1926, 12, 25), 1926, QDate(1926, 12, 31), name, shortName, format);
80  format = i18nc("(kdedt-format) Japanese, Shōwa, full era year format used for %EY, year > 1, e.g. Shōwa 22", "%EC %Ey");
81  addEra('+', 2, QDate(1927, 1, 1), 1927, QDate(1989, 1, 7), name, shortName, format);
82 
83  name = i18nc("Calendar Era: Japanese Nengō, Heisei Era, LongFormat", "Heisei");
84  shortName = name;
85  format = i18nc("(kdedt-format) Japanese, Heisei, full era year format used for %EY, year = 1, e.g. Heisei 1", "%EC Gannen");
86  addEra('+', 1, QDate(1989, 1, 8), 1989, QDate(1989, 12, 31), name, shortName, format);
87  format = i18nc("(kdedt-format) Japanese, Heisei, full era year format used for %EY, year > 1, e.g. Heisei 22", "%EC %Ey");
88  addEra('+', 2, QDate(1990, 1, 1), 1990, q->latestValidDate(), name, shortName, format);
89 }
90 
91 int KCalendarSystemJapanesePrivate::earliestValidYear() const
92 {
93  return 1;
94 }
95 
96 KCalendarSystemJapanese::KCalendarSystemJapanese(const KSharedConfig::Ptr config, const KLocale *locale)
97  : KCalendarSystemGregorian(*new KCalendarSystemJapanesePrivate(this), config, locale)
98 {
99  d_ptr->loadConfig(calendarType());
100 }
101 
102 KCalendarSystemJapanese::KCalendarSystemJapanese(KCalendarSystemJapanesePrivate &dd,
103  const KSharedConfig::Ptr config, const KLocale *locale)
104  : KCalendarSystemGregorian(dd, config, locale)
105 {
106  d_ptr->loadConfig(calendarType());
107 }
108 
109 KCalendarSystemJapanese::~KCalendarSystemJapanese()
110 {
111 }
112 
113 QString KCalendarSystemJapanese::calendarType() const
114 {
115  return QLatin1String("japanese");
116 }
117 
118 KLocale::CalendarSystem KCalendarSystemJapanese::calendarSystem() const
119 {
121 }
122 
123 QDate KCalendarSystemJapanese::epoch() const
124 {
125  // 0001-01-01 Gregorian for now
126  return QDate::fromJulianDay(1721426);
127 }
128 
129 QDate KCalendarSystemJapanese::earliestValidDate() const
130 {
131  // 0001-01-01 Gregorian for now
132  return QDate::fromJulianDay(1721426);
133 }
134 
135 QDate KCalendarSystemJapanese::latestValidDate() const
136 {
137  // Set to last day of year 9999 until confirm date formats & widgets support > 9999
138  // 9999-12-31 Gregorian
139  return QDate::fromJulianDay(5373484);
140 }
141 
142 QString KCalendarSystemJapanese::monthName(int month, int year, MonthNameFormat format) const
143 {
144  return KCalendarSystemGregorian::monthName(month, year, format);
145 }
146 
147 QString KCalendarSystemJapanese::monthName(const QDate &date, MonthNameFormat format) const
148 {
149  return KCalendarSystemGregorian::monthName(date, format);
150 }
151 
152 QString KCalendarSystemJapanese::weekDayName(int weekDay, WeekDayNameFormat format) const
153 {
154  return KCalendarSystemGregorian::weekDayName(weekDay, format);
155 }
156 
157 QString KCalendarSystemJapanese::weekDayName(const QDate &date, WeekDayNameFormat format) const
158 {
159  return KCalendarSystemGregorian::weekDayName(date, format);
160 }
161 
162 int KCalendarSystemJapanese::yearStringToInteger(const QString &sNum, int &iLength) const
163 {
164  QString gannen = i18nc("Japanese year 1 of era", "Gannen");
165  if (sNum.startsWith(gannen, Qt::CaseInsensitive)) {
166  iLength = gannen.length();
167  return 1;
168  } else {
169  return KCalendarSystemGregorian::yearStringToInteger(sNum, iLength);
170  }
171 }
172 
173 bool KCalendarSystemJapanese::isLunar() const
174 {
175  return KCalendarSystemGregorian::isLunar();
176 }
177 
178 bool KCalendarSystemJapanese::isLunisolar() const
179 {
180  return KCalendarSystemGregorian::isLunisolar();
181 }
182 
183 bool KCalendarSystemJapanese::isSolar() const
184 {
185  return KCalendarSystemGregorian::isSolar();
186 }
187 
188 bool KCalendarSystemJapanese::isProleptic() const
189 {
190  return false;
191 }
192 
193 bool KCalendarSystemJapanese::julianDayToDate(qint64 jd, int &year, int &month, int &day) const
194 {
195  return KCalendarSystemGregorian::julianDayToDate(jd, year, month, day);
196 }
197 
198 bool KCalendarSystemJapanese::dateToJulianDay(int year, int month, int day, qint64 &jd) const
199 {
200  return KCalendarSystemGregorian::dateToJulianDay(year, month, day, jd);
201 }
QString name(const QVariant &location)
Japanese Calendar, Gregorian calculation using Japanese Era (Nengô)
Definition: klocale.h:664
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.
CalendarSystem
Definition: klocale.h:646
QString i18nc(const char *context, const char *text, const TYPE &arg...)
CaseInsensitive
bool startsWith(const QString &s, Qt::CaseSensitivity cs) const const
virtual int month(const QDate &date) const
Returns the month portion of a given date in the current calendar system.
const KLocale * locale() const
Returns the locale used for translations and formats for this calendar system instance.
WeekDayNameFormat
Format for returned month / day name.
virtual int year(const QDate &date) const
Returns the year portion of a given date in the current calendar system.
KLocale provides support for language and country specific stuff.
Definition: klocale.h:75
int length() const const
QDate fromJulianDay(qint64 jd)
virtual QString calendarType() const =0
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Fri Jul 3 2020 22:57:52 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.