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

KDECore

  • 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
29class KCalendarSystemJapanesePrivate : public KCalendarSystemGregorianPrivate
30{
31public:
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
42KCalendarSystemJapanesePrivate::KCalendarSystemJapanesePrivate(KCalendarSystemJapanese *q)
43 : KCalendarSystemGregorianPrivate(q)
44{
45}
46
47KCalendarSystemJapanesePrivate::~KCalendarSystemJapanesePrivate()
48{
49}
50
51KLocale::CalendarSystem KCalendarSystemJapanesePrivate::calendarSystem() const
52{
53 return KLocale::JapaneseCalendar;
54}
55
56void 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
97int KCalendarSystemJapanesePrivate::earliestValidYear() const
98{
99 return 1;
100}
101
102
103KCalendarSystemJapanese::KCalendarSystemJapanese(const KLocale *locale)
104 : KCalendarSystemGregorian(*new KCalendarSystemJapanesePrivate(this), KSharedConfig::Ptr(), locale)
105{
106 d_ptr->loadConfig(calendarType());
107}
108
109KCalendarSystemJapanese::KCalendarSystemJapanese(const KSharedConfig::Ptr config, const KLocale *locale)
110 : KCalendarSystemGregorian(*new KCalendarSystemJapanesePrivate(this), config, locale)
111{
112 d_ptr->loadConfig(calendarType());
113}
114
115KCalendarSystemJapanese::KCalendarSystemJapanese(KCalendarSystemJapanesePrivate &dd,
116 const KSharedConfig::Ptr config, const KLocale *locale)
117 : KCalendarSystemGregorian(dd, config, locale)
118{
119 d_ptr->loadConfig(calendarType());
120}
121
122KCalendarSystemJapanese::~KCalendarSystemJapanese()
123{
124}
125
126QString KCalendarSystemJapanese::calendarType() const
127{
128 return QLatin1String("japanese");
129}
130
131QDate KCalendarSystemJapanese::epoch() const
132{
133 // 0001-01-01 Gregorian for now
134 return QDate::fromJulianDay(1721426);
135}
136
137QDate KCalendarSystemJapanese::earliestValidDate() const
138{
139 // 0001-01-01 Gregorian for now
140 return QDate::fromJulianDay(1721426);
141}
142
143QDate 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
150bool KCalendarSystemJapanese::isValid(int year, int month, int day) const
151{
152 return KCalendarSystemGregorian::isValid(year, month, day);
153}
154
155bool KCalendarSystemJapanese::isValid(const QDate &date) const
156{
157 return KCalendarSystemGregorian::isValid(date);
158}
159
160bool KCalendarSystemJapanese::isLeapYear(int year) const
161{
162 return KCalendarSystemGregorian::isLeapYear(year);
163}
164
165bool KCalendarSystemJapanese::isLeapYear(const QDate &date) const
166{
167 return KCalendarSystemGregorian::isLeapYear(date);
168}
169
170QString KCalendarSystemJapanese::monthName(int month, int year, MonthNameFormat format) const
171{
172 return KCalendarSystemGregorian::monthName(month, year, format);
173}
174
175QString KCalendarSystemJapanese::monthName(const QDate &date, MonthNameFormat format) const
176{
177 return KCalendarSystemGregorian::monthName(date, format);
178}
179
180QString KCalendarSystemJapanese::weekDayName(int weekDay, WeekDayNameFormat format) const
181{
182 return KCalendarSystemGregorian::weekDayName(weekDay, format);
183}
184
185QString KCalendarSystemJapanese::weekDayName(const QDate &date, WeekDayNameFormat format) const
186{
187 return KCalendarSystemGregorian::weekDayName(date, format);
188}
189
190int 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
201int KCalendarSystemJapanese::weekDayOfPray() const
202{
203 return 7; // TODO JPL ???
204}
205
206bool KCalendarSystemJapanese::isLunar() const
207{
208 return KCalendarSystemGregorian::isLunar();
209}
210
211bool KCalendarSystemJapanese::isLunisolar() const
212{
213 return KCalendarSystemGregorian::isLunisolar();
214}
215
216bool KCalendarSystemJapanese::isSolar() const
217{
218 return KCalendarSystemGregorian::isSolar();
219}
220
221bool KCalendarSystemJapanese::isProleptic() const
222{
223 return false;
224}
225
226bool KCalendarSystemJapanese::julianDayToDate(int jd, int &year, int &month, int &day) const
227{
228 return KCalendarSystemGregorian::julianDayToDate(jd, year, month, day);
229}
230
231bool KCalendarSystemJapanese::dateToJulianDay(int year, int month, int day, int &jd) const
232{
233 return KCalendarSystemGregorian::dateToJulianDay(year, month, day, jd);
234}
KCalendarSystemGregorianPrivate
Definition: kcalendarsystemgregorianprivate_p.h:28
KCalendarSystemGregorianPrivate::calendarSystem
virtual KLocale::CalendarSystem calendarSystem() const
Definition: kcalendarsystemgregorian.cpp:45
KCalendarSystemGregorianPrivate::earliestValidYear
virtual int earliestValidYear() const
Definition: kcalendarsystemgregorian.cpp:154
KCalendarSystemGregorianPrivate::loadDefaultEraList
virtual void loadDefaultEraList()
Definition: kcalendarsystemgregorian.cpp:52
KCalendarSystemGregorian
Definition: kcalendarsystemgregorian_p.h:43
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
KCalendarSystemGregorian::weekDayName
virtual QString weekDayName(int weekDay, WeekDayNameFormat format=LongDayName) const
Gets specific calendar type week day name.
Definition: kcalendarsystemgregorian.cpp:466
KCalendarSystemGregorian::yearStringToInteger
virtual int yearStringToInteger(const QString &sNum, int &iLength) const
Definition: kcalendarsystemgregorian.cpp:476
KCalendarSystemGregorian::isLeapYear
virtual bool isLeapYear(int year) const
Returns whether a given year is a leap year.
Definition: kcalendarsystemgregorian.cpp:446
KCalendarSystemGregorian::isSolar
virtual bool isSolar() const
Returns whether the calendar is solar based.
Definition: kcalendarsystemgregorian.cpp:496
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
KCalendarSystemGregorian::isLunar
virtual bool isLunar() const
Returns whether the calendar is lunar based.
Definition: kcalendarsystemgregorian.cpp:486
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::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
KCalendarSystemGregorian::isLunisolar
virtual bool isLunisolar() const
Returns whether the calendar is lunisolar based.
Definition: kcalendarsystemgregorian.cpp:491
KCalendarSystemJapanese
Definition: kcalendarsystemjapanese_p.h:39
KCalendarSystemJapanese::~KCalendarSystemJapanese
virtual ~KCalendarSystemJapanese()
Definition: kcalendarsystemjapanese.cpp:122
KCalendarSystemJapanese::isLunar
virtual bool isLunar() const
Returns whether the calendar is lunar based.
Definition: kcalendarsystemjapanese.cpp:206
KCalendarSystemJapanese::isLunisolar
virtual bool isLunisolar() const
Returns whether the calendar is lunisolar based.
Definition: kcalendarsystemjapanese.cpp:211
KCalendarSystemJapanese::yearStringToInteger
virtual int yearStringToInteger(const QString &sNum, int &iLength) const
Definition: kcalendarsystemjapanese.cpp:190
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
KCalendarSystemJapanese::weekDayOfPray
virtual int weekDayOfPray() const
Definition: kcalendarsystemjapanese.cpp:201
KCalendarSystemJapanese::isProleptic
virtual bool isProleptic() const
Returns whether the calendar system is proleptic, i.e.
Definition: kcalendarsystemjapanese.cpp:221
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
KCalendarSystemJapanese::latestValidDate
virtual QDate latestValidDate() const
Returns the latest date valid in this calendar system implementation.
Definition: kcalendarsystemjapanese.cpp:143
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
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
KCalendarSystemJapanese::weekDayName
virtual QString weekDayName(int weekDay, WeekDayNameFormat format=LongDayName) const
Gets specific calendar type week day name.
Definition: kcalendarsystemjapanese.cpp:180
KCalendarSystemJapanese::epoch
virtual QDate epoch() const
Returns a QDate holding the epoch of the calendar system.
Definition: kcalendarsystemjapanese.cpp:131
KCalendarSystemJapanese::isLeapYear
virtual bool isLeapYear(int year) const
Returns whether a given year is a leap year.
Definition: kcalendarsystemjapanese.cpp:160
KCalendarSystemJapanese::earliestValidDate
virtual QDate earliestValidDate() const
Returns the earliest date valid in this calendar system implementation.
Definition: kcalendarsystemjapanese.cpp:137
KCalendarSystemJapanese::isSolar
virtual bool isSolar() const
Returns whether the calendar is solar based.
Definition: kcalendarsystemjapanese.cpp:216
KCalendarSystemPrivate::q
const KCalendarSystem * q
Definition: kcalendarsystemprivate_p.h:104
KCalendarSystem::KCalendarSystemJapanese
friend class KCalendarSystemJapanese
Definition: kcalendarsystem.h:1672
KCalendarSystem::day
virtual int day(const QDate &date) const
Returns the day portion of a given date in the current calendar system.
Definition: kcalendarsystem.cpp:1357
KCalendarSystem::year
virtual int year(const QDate &date) const
Returns the year portion of a given date in the current calendar system.
Definition: kcalendarsystem.cpp:1331
KCalendarSystem::MonthNameFormat
MonthNameFormat
Format for returned month / day name.
Definition: kcalendarsystem.h:55
KCalendarSystem::WeekDayNameFormat
WeekDayNameFormat
Format for returned month / day name.
Definition: kcalendarsystem.h:66
KCalendarSystem::month
virtual int month(const QDate &date) const
Returns the month portion of a given date in the current calendar system.
Definition: kcalendarsystem.cpp:1344
KLocale
KLocale provides support for country specific stuff like the national language.
Definition: klocale.h:70
KLocale::CalendarSystem
CalendarSystem
Definition: klocale.h:780
KLocale::JapaneseCalendar
@ JapaneseCalendar
Japanese Calendar, Gregorian calculation using Japanese Era (Nengô)
Definition: klocale.h:799
KSharedConfig
KConfig variant using shared memory.
Definition: ksharedconfig.h:41
KSharedPtr< KSharedConfig >
QString
kcalendarsystemgregorianprivate_p.h
kcalendarsystemjapanese_p.h
kdebug.h
klocale.h
i18nc
QString i18nc(const char *ctxt, const char *text)
Returns a localized version of a string and a context.
Definition: klocalizedstring.h:797
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Mon Feb 20 2023 00:00:00 by doxygen 1.9.6 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-4.14.38 API Reference

Skip menu "kdelibs-4.14.38 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
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