• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdelibs API Reference
  • KDE Home
  • Contact Us
 

KDECore

  • sources
  • kde-4.14
  • kdelibs
  • kdecore
  • date
kcalendarsystemjapanese.cpp
Go to the documentation of this file.
1 /*
2  Copyright 2009, 2010 John Layt <john@layt.net>
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 "kdebug.h"
24 #include "klocale.h"
25 
26 #include <QtCore/QDate>
27 
28 //Reuse the Gregorian private implementation
29 class KCalendarSystemJapanesePrivate : public KCalendarSystemGregorianPrivate
30 {
31 public:
32  explicit KCalendarSystemJapanesePrivate(KCalendarSystemJapanese *q);
33  virtual ~KCalendarSystemJapanesePrivate();
34 
35  virtual KLocale::CalendarSystem calendarSystem() const;
36  virtual void loadDefaultEraList();
37  virtual int earliestValidYear() const;
38 };
39 
40 //Override only a few of the Gregorian private methods
41 
42 KCalendarSystemJapanesePrivate::KCalendarSystemJapanesePrivate(KCalendarSystemJapanese *q)
43  : KCalendarSystemGregorianPrivate(q)
44 {
45 }
46 
47 KCalendarSystemJapanesePrivate::~KCalendarSystemJapanesePrivate()
48 {
49 }
50 
51 KLocale::CalendarSystem KCalendarSystemJapanesePrivate::calendarSystem() const
52 {
53  return KLocale::JapaneseCalendar;
54 }
55 
56 void KCalendarSystemJapanesePrivate::loadDefaultEraList()
57 {
58  QString name, shortName, format;
59 
60  // Nengō, Only do most recent for now, use AD for the rest.
61  // Feel free to add more, but have mercy on the translators :-)
62 
63  name = i18nc("Calendar Era: Gregorian Christian Era, years > 0, LongFormat", "Anno Domini");
64  shortName = i18nc("Calendar Era: Gregorian Christian Era, years > 0, ShortFormat", "AD");
65  format = i18nc("(kdedt-format) Gregorian, AD, full era year format used for %EY, e.g. 2000 AD", "%Ey %EC");
66  addEra('+', 1, q->epoch(), 1, QDate(1868, 9, 7), name, shortName, format);
67 
68  name = i18nc("Calendar Era: Japanese Nengō, Meiji Era, LongFormat", "Meiji");
69  shortName = name;
70  format = i18nc("(kdedt-format) Japanese, Meiji, full era year format used for %EY, year = 1, e.g. Meiji 1", "%EC Gannen");
71  addEra('+', 1, QDate(1868, 9, 8), 1868, QDate(1868, 12, 31), name, shortName, format);
72  format = i18nc("(kdedt-format) Japanese, Meiji, full era year format used for %EY, year > 1, e.g. Meiji 22", "%EC %Ey");
73  addEra('+', 2, QDate(1869, 1, 1), 1869, QDate(1912, 7, 29), name, shortName, format);
74 
75  name = i18nc("Calendar Era: Japanese Nengō, Taishō Era, LongFormat", "Taishō");
76  shortName = name;
77  format = i18nc("(kdedt-format) Japanese, Taishō, full era year format used for %EY, year = 1, e.g. Taishō 1", "%EC Gannen");
78  addEra('+', 1, QDate(1912, 7, 30), 1912, QDate(1912, 12, 31), name, shortName, format);
79  format = i18nc("(kdedt-format) Japanese, Taishō, full era year format used for %EY, year > 1, e.g. Taishō 22", "%EC %Ey");
80  addEra('+', 2, QDate(1913, 1, 1), 1913, QDate(1926, 12, 24), name, shortName, format);
81 
82  name = i18nc("Calendar Era: Japanese Nengō, Shōwa Era, LongFormat", "Shōwa");
83  shortName = name;
84  format = i18nc("(kdedt-format) Japanese, Shōwa, full era year format used for %EY, year = 1, e.g. Shōwa 1", "%EC Gannen");
85  addEra('+', 1, QDate(1926, 12, 25), 1926, QDate(1926, 12, 31), name, shortName, format);
86  format = i18nc("(kdedt-format) Japanese, Shōwa, full era year format used for %EY, year > 1, e.g. Shōwa 22", "%EC %Ey");
87  addEra('+', 2, QDate(1927, 1, 1), 1927, QDate(1989, 1, 7), name, shortName, format);
88 
89  name = i18nc("Calendar Era: Japanese Nengō, Heisei Era, LongFormat", "Heisei");
90  shortName = name;
91  format = i18nc("(kdedt-format) Japanese, Heisei, full era year format used for %EY, year = 1, e.g. Heisei 1", "%EC Gannen");
92  addEra('+', 1, QDate(1989, 1, 8), 1989, QDate(1989, 12, 31), name, shortName, format);
93  format = i18nc("(kdedt-format) Japanese, Heisei, full era year format used for %EY, year > 1, e.g. Heisei 22", "%EC %Ey");
94  addEra('+', 2, QDate(1990, 1, 1), 1990, q->latestValidDate(), name, shortName, format);
95 }
96 
97 int KCalendarSystemJapanesePrivate::earliestValidYear() const
98 {
99  return 1;
100 }
101 
102 
103 KCalendarSystemJapanese::KCalendarSystemJapanese(const KLocale *locale)
104  : KCalendarSystemGregorian(*new KCalendarSystemJapanesePrivate(this), KSharedConfig::Ptr(), locale)
105 {
106  d_ptr->loadConfig(calendarType());
107 }
108 
109 KCalendarSystemJapanese::KCalendarSystemJapanese(const KSharedConfig::Ptr config, const KLocale *locale)
110  : KCalendarSystemGregorian(*new KCalendarSystemJapanesePrivate(this), config, locale)
111 {
112  d_ptr->loadConfig(calendarType());
113 }
114 
115 KCalendarSystemJapanese::KCalendarSystemJapanese(KCalendarSystemJapanesePrivate &dd,
116  const KSharedConfig::Ptr config, const KLocale *locale)
117  : KCalendarSystemGregorian(dd, config, locale)
118 {
119  d_ptr->loadConfig(calendarType());
120 }
121 
122 KCalendarSystemJapanese::~KCalendarSystemJapanese()
123 {
124 }
125 
126 QString KCalendarSystemJapanese::calendarType() const
127 {
128  return QLatin1String("japanese");
129 }
130 
131 QDate KCalendarSystemJapanese::epoch() const
132 {
133  // 0001-01-01 Gregorian for now
134  return QDate::fromJulianDay(1721426);
135 }
136 
137 QDate KCalendarSystemJapanese::earliestValidDate() const
138 {
139  // 0001-01-01 Gregorian for now
140  return QDate::fromJulianDay(1721426);
141 }
142 
143 QDate KCalendarSystemJapanese::latestValidDate() const
144 {
145  // Set to last day of year 9999 until confirm date formats & widgets support > 9999
146  // 9999-12-31 Gregorian
147  return QDate::fromJulianDay(5373484);
148 }
149 
150 bool KCalendarSystemJapanese::isValid(int year, int month, int day) const
151 {
152  return KCalendarSystemGregorian::isValid(year, month, day);
153 }
154 
155 bool KCalendarSystemJapanese::isValid(const QDate &date) const
156 {
157  return KCalendarSystemGregorian::isValid(date);
158 }
159 
160 bool KCalendarSystemJapanese::isLeapYear(int year) const
161 {
162  return KCalendarSystemGregorian::isLeapYear(year);
163 }
164 
165 bool KCalendarSystemJapanese::isLeapYear(const QDate &date) const
166 {
167  return KCalendarSystemGregorian::isLeapYear(date);
168 }
169 
170 QString KCalendarSystemJapanese::monthName(int month, int year, MonthNameFormat format) const
171 {
172  return KCalendarSystemGregorian::monthName(month, year, format);
173 }
174 
175 QString KCalendarSystemJapanese::monthName(const QDate &date, MonthNameFormat format) const
176 {
177  return KCalendarSystemGregorian::monthName(date, format);
178 }
179 
180 QString KCalendarSystemJapanese::weekDayName(int weekDay, WeekDayNameFormat format) const
181 {
182  return KCalendarSystemGregorian::weekDayName(weekDay, format);
183 }
184 
185 QString KCalendarSystemJapanese::weekDayName(const QDate &date, WeekDayNameFormat format) const
186 {
187  return KCalendarSystemGregorian::weekDayName(date, format);
188 }
189 
190 int KCalendarSystemJapanese::yearStringToInteger(const QString &sNum, int &iLength) const
191 {
192  QString gannen = i18nc("Japanese year 1 of era", "Gannen");
193  if (sNum.startsWith(gannen, Qt::CaseInsensitive)) {
194  iLength = gannen.length();
195  return 1;
196  } else {
197  return KCalendarSystemGregorian::yearStringToInteger(sNum, iLength);
198  }
199 }
200 
201 int KCalendarSystemJapanese::weekDayOfPray() const
202 {
203  return 7; // TODO JPL ???
204 }
205 
206 bool KCalendarSystemJapanese::isLunar() const
207 {
208  return KCalendarSystemGregorian::isLunar();
209 }
210 
211 bool KCalendarSystemJapanese::isLunisolar() const
212 {
213  return KCalendarSystemGregorian::isLunisolar();
214 }
215 
216 bool KCalendarSystemJapanese::isSolar() const
217 {
218  return KCalendarSystemGregorian::isSolar();
219 }
220 
221 bool KCalendarSystemJapanese::isProleptic() const
222 {
223  return false;
224 }
225 
226 bool KCalendarSystemJapanese::julianDayToDate(int jd, int &year, int &month, int &day) const
227 {
228  return KCalendarSystemGregorian::julianDayToDate(jd, year, month, day);
229 }
230 
231 bool KCalendarSystemJapanese::dateToJulianDay(int year, int month, int day, int &jd) const
232 {
233  return KCalendarSystemGregorian::dateToJulianDay(year, month, day, jd);
234 }
KSharedPtr< KSharedConfig >
KSharedConfig
KConfig variant using shared memory.
Definition: ksharedconfig.h:40
KCalendarSystemGregorian::weekDayName
virtual QString weekDayName(int weekDay, WeekDayNameFormat format=LongDayName) const
Gets specific calendar type week day name.
Definition: kcalendarsystemgregorian.cpp:466
kdebug.h
KCalendarSystemJapanese
Definition: kcalendarsystemjapanese_p.h:38
KLocale::JapaneseCalendar
Japanese Calendar, Gregorian calculation using Japanese Era (Nengô)
Definition: klocale.h:799
KCalendarSystemJapanese::isLunar
virtual bool isLunar() const
Returns whether the calendar is lunar based.
Definition: kcalendarsystemjapanese.cpp:206
KCalendarSystemGregorian::yearStringToInteger
virtual int yearStringToInteger(const QString &sNum, int &iLength) const
Definition: kcalendarsystemgregorian.cpp:476
KCalendarSystemJapanese::yearStringToInteger
virtual int yearStringToInteger(const QString &sNum, int &iLength) const
Definition: kcalendarsystemjapanese.cpp:190
KCalendarSystemJapanese::isSolar
virtual bool isSolar() const
Returns whether the calendar is solar based.
Definition: kcalendarsystemjapanese.cpp:216
KCalendarSystemGregorian::isLunar
virtual bool isLunar() const
Returns whether the calendar is lunar based.
Definition: kcalendarsystemgregorian.cpp:486
KCalendarSystemJapanese::dateToJulianDay
virtual bool dateToJulianDay(int year, int month, int day, int &jd) const
Internal method to convert YMD values for this calendar system into a Julian Day number.
Definition: kcalendarsystemjapanese.cpp:231
KCalendarSystem::MonthNameFormat
MonthNameFormat
Format for returned month / day name.
Definition: kcalendarsystem.h:55
klocale.h
KCalendarSystemGregorian::julianDayToDate
virtual bool julianDayToDate(int jd, int &year, int &month, int &day) const
Internal method to convert a Julian Day number into the YMD values for this calendar system...
Definition: kcalendarsystemgregorian.cpp:506
KCalendarSystemGregorian::isLeapYear
virtual bool isLeapYear(int year) const
Returns whether a given year is a leap year.
Definition: kcalendarsystemgregorian.cpp:446
i18nc
QString i18nc(const char *ctxt, const char *text)
Returns a localized version of a string and a context.
Definition: klocalizedstring.h:797
KCalendarSystemGregorianPrivate::loadDefaultEraList
virtual void loadDefaultEraList()
Definition: kcalendarsystemgregorian.cpp:52
KGlobal::config
KSharedConfigPtr config()
Returns the general config object.
Definition: kglobal.cpp:139
KCalendarSystemJapanese::weekDayName
virtual QString weekDayName(int weekDay, WeekDayNameFormat format=LongDayName) const
Gets specific calendar type week day name.
Definition: kcalendarsystemjapanese.cpp:180
KCalendarSystemGregorianPrivate::calendarSystem
virtual KLocale::CalendarSystem calendarSystem() const
Definition: kcalendarsystemgregorian.cpp:45
KCalendarSystemJapanese::earliestValidDate
virtual QDate earliestValidDate() const
Returns the earliest date valid in this calendar system implementation.
Definition: kcalendarsystemjapanese.cpp:137
KCalendarSystemGregorian::monthName
virtual QString monthName(int month, int year, MonthNameFormat format=LongName) const
Gets specific calendar type month name for a given month number If an invalid month is specified...
Definition: kcalendarsystemgregorian.cpp:456
KLocale::CalendarSystem
CalendarSystem
Definition: klocale.h:780
QString::startsWith
bool startsWith(const QString &s, Qt::CaseSensitivity cs) const
KCalendarSystemJapanese::latestValidDate
virtual QDate latestValidDate() const
Returns the latest date valid in this calendar system implementation.
Definition: kcalendarsystemjapanese.cpp:143
KCalendarSystemJapanese::epoch
virtual QDate epoch() const
Returns a QDate holding the epoch of the calendar system.
Definition: kcalendarsystemjapanese.cpp:131
QDate
KCalendarSystemJapanese::isLunisolar
virtual bool isLunisolar() const
Returns whether the calendar is lunisolar based.
Definition: kcalendarsystemjapanese.cpp:211
QString
KCalendarSystemGregorianPrivate::earliestValidYear
virtual int earliestValidYear() const
Definition: kcalendarsystemgregorian.cpp:154
KCalendarSystem::WeekDayNameFormat
WeekDayNameFormat
Format for returned month / day name.
Definition: kcalendarsystem.h:66
KCalendarSystemJapanese::isLeapYear
virtual bool isLeapYear(int year) const
Returns whether a given year is a leap year.
Definition: kcalendarsystemjapanese.cpp:160
KCalendarSystemJapanese::isProleptic
virtual bool isProleptic() const
Returns whether the calendar system is proleptic, i.e.
Definition: kcalendarsystemjapanese.cpp:221
KCalendarSystemGregorian
Definition: kcalendarsystemgregorian_p.h:42
kcalendarsystemgregorianprivate_p.h
KGlobal::locale
KLocale * locale()
Returns the global locale object.
Definition: kglobal.cpp:170
KCalendarSystemGregorianPrivate
Definition: kcalendarsystemgregorianprivate_p.h:27
KCalendarSystemJapanese::calendarType
virtual QString calendarType() const
Definition: kcalendarsystemjapanese.cpp:126
KCalendarSystemJapanese::julianDayToDate
virtual bool julianDayToDate(int jd, int &year, int &month, int &day) const
Internal method to convert a Julian Day number into the YMD values for this calendar system...
Definition: kcalendarsystemjapanese.cpp:226
KLocale
KLocale provides support for country specific stuff like the national language.
Definition: klocale.h:69
KCalendarSystemJapanese::weekDayOfPray
virtual int weekDayOfPray() const
Definition: kcalendarsystemjapanese.cpp:201
QLatin1String
KCalendarSystemGregorian::dateToJulianDay
virtual bool dateToJulianDay(int year, int month, int day, int &jd) const
Internal method to convert YMD values for this calendar system into a Julian Day number.
Definition: kcalendarsystemgregorian.cpp:534
kcalendarsystemjapanese_p.h
KCalendarSystemGregorian::isLunisolar
virtual bool isLunisolar() const
Returns whether the calendar is lunisolar based.
Definition: kcalendarsystemgregorian.cpp:491
KCalendarSystemJapanese::monthName
virtual QString monthName(int month, int year, MonthNameFormat format=LongName) const
Gets specific calendar type month name for a given month number If an invalid month is specified...
Definition: kcalendarsystemjapanese.cpp:170
QString::length
int length() const
KCalendarSystemJapanese::KCalendarSystemJapanese
KCalendarSystemJapanese(const KLocale *locale=0)
Definition: kcalendarsystemjapanese.cpp:103
KCalendarSystemGregorian::isSolar
virtual bool isSolar() const
Returns whether the calendar is solar based.
Definition: kcalendarsystemgregorian.cpp:496
QDate::fromJulianDay
QDate fromJulianDay(int jd)
KCalendarSystemJapanese::isValid
virtual bool isValid(int year, int month, int day) const
Returns whether a given date is valid in this calendar system.
Definition: kcalendarsystemjapanese.cpp:150
KCalendarSystemGregorian::isValid
virtual bool isValid(int year, int month, int day) const
Returns whether a given date is valid in this calendar system.
Definition: kcalendarsystemgregorian.cpp:436
KCalendarSystemJapanese::~KCalendarSystemJapanese
virtual ~KCalendarSystemJapanese()
Definition: kcalendarsystemjapanese.cpp:122
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:22:10 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KDECore

Skip menu "KDECore"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Modules
  • Related Pages

kdelibs API Reference

Skip menu "kdelibs API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal