KDELibs4Support

kcalendarsystemminguo.cpp
1 /*
2  Copyright 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 "kcalendarsystemminguo_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 KCalendarSystemMinguoPrivate : public KCalendarSystemGregorianPrivate
30 {
31 public:
32  KDELIBS4SUPPORT_DEPRECATED explicit KCalendarSystemMinguoPrivate(KCalendarSystemMinguo *q);
33  virtual ~KCalendarSystemMinguoPrivate();
34 
35  void loadDefaultEraList() override;
36  int daysInMonth(int year, int month) const override;
37  int daysInYear(int year) const override;
38  bool isLeapYear(int year) const override;
39  int earliestValidYear() const override;
40 };
41 
42 //Override only a few of the Gregorian private methods
43 
44 KCalendarSystemMinguoPrivate::KCalendarSystemMinguoPrivate(KCalendarSystemMinguo *q)
45  : KCalendarSystemGregorianPrivate(q)
46 {
47 }
48 
49 KCalendarSystemMinguoPrivate::~KCalendarSystemMinguoPrivate()
50 {
51 }
52 
53 void KCalendarSystemMinguoPrivate::loadDefaultEraList()
54 {
55  QString name, shortName, format;
56 
57  name = i18nc("Calendar Era: Taiwan Republic of China Era, years > 0, LongFormat", "Republic of China Era");
58  shortName = i18nc("Calendar Era: Taiwan Republic of China Era, years > 0, ShortFormat", "ROC");
59  format = i18nc("(kdedt-format) Taiwan, ROC, full era year format used for %EY, e.g. ROC 99", "%EC %Ey");
60  addEra('+', 1, q->epoch(), 1, q->latestValidDate(), name, shortName, format);
61 }
62 
63 int KCalendarSystemMinguoPrivate::daysInMonth(int year, int month) const
64 {
65  return KCalendarSystemGregorianPrivate::daysInMonth(year + 1911, month);
66 }
67 
68 int KCalendarSystemMinguoPrivate::daysInYear(int year) const
69 {
70  return KCalendarSystemGregorianPrivate::daysInYear(year + 1911);
71 }
72 
73 bool KCalendarSystemMinguoPrivate::isLeapYear(int year) const
74 {
75  return KCalendarSystemGregorianPrivate::isLeapYear(year + 1911);
76 }
77 
78 int KCalendarSystemMinguoPrivate::earliestValidYear() const
79 {
80  return 1;
81 }
82 
83 KCalendarSystemMinguo::KCalendarSystemMinguo(const KSharedConfig::Ptr config, const KLocale *locale)
84  : KCalendarSystemGregorian(*new KCalendarSystemMinguoPrivate(this), config, locale)
85 {
86  d_ptr->loadConfig(calendarType());
87 }
88 
89 KCalendarSystemMinguo::KCalendarSystemMinguo(KCalendarSystemMinguoPrivate &dd,
90  const KSharedConfig::Ptr config, const KLocale *locale)
91  : KCalendarSystemGregorian(dd, config, locale)
92 {
93  d_ptr->loadConfig(calendarType());
94 }
95 
96 KCalendarSystemMinguo::~KCalendarSystemMinguo()
97 {
98 }
99 
100 QString KCalendarSystemMinguo::calendarType() const
101 {
102  return QLatin1String("minguo");
103 }
104 
105 KLocale::CalendarSystem KCalendarSystemMinguo::calendarSystem() const
106 {
108 }
109 
110 QDate KCalendarSystemMinguo::epoch() const
111 {
112  // 0001-01-01 = 1912-01-01 AD Gregorian
113  return QDate::fromJulianDay(2419403);
114 }
115 
116 QDate KCalendarSystemMinguo::earliestValidDate() const
117 {
118  return epoch();
119 }
120 
121 QDate KCalendarSystemMinguo::latestValidDate() const
122 {
123  // Set to last day of year 9999 until confirm date formats & widgets support > 9999
124  // 9999-12-31 = 11910-12-31 AD Gregorian
125  return QDate::fromJulianDay(6071462);
126 }
127 
128 QString KCalendarSystemMinguo::monthName(int month, int year, MonthNameFormat format) const
129 {
130  return KCalendarSystemGregorian::monthName(month, year, format);
131 }
132 
133 QString KCalendarSystemMinguo::monthName(const QDate &date, MonthNameFormat format) const
134 {
135  return KCalendarSystemGregorian::monthName(date, format);
136 }
137 
138 QString KCalendarSystemMinguo::weekDayName(int weekDay, WeekDayNameFormat format) const
139 {
140  return KCalendarSystemGregorian::weekDayName(weekDay, format);
141 }
142 
143 QString KCalendarSystemMinguo::weekDayName(const QDate &date, WeekDayNameFormat format) const
144 {
145  return KCalendarSystemGregorian::weekDayName(date, format);
146 }
147 
148 bool KCalendarSystemMinguo::isLunar() const
149 {
150  return KCalendarSystemGregorian::isLunar();
151 }
152 
153 bool KCalendarSystemMinguo::isLunisolar() const
154 {
155  return KCalendarSystemGregorian::isLunisolar();
156 }
157 
158 bool KCalendarSystemMinguo::isSolar() const
159 {
160  return KCalendarSystemGregorian::isSolar();
161 }
162 
163 bool KCalendarSystemMinguo::isProleptic() const
164 {
165  return false;
166 }
167 
168 bool KCalendarSystemMinguo::julianDayToDate(qint64 jd, int &year, int &month, int &day) const
169 {
170  bool result = KCalendarSystemGregorian::julianDayToDate(jd, year, month, day);
171  year = year - 1911;
172  return result;
173 }
174 
175 bool KCalendarSystemMinguo::dateToJulianDay(int year, int month, int day, qint64 &jd) const
176 {
177  return KCalendarSystemGregorian::dateToJulianDay(year + 1911, month, day, jd);
178 }
179 
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.
virtual QDate epoch() const =0
Returns a QDate holding the epoch of the calendar system.
CalendarSystem
Definition: klocale.h:646
Minguo Calendar, aka ROC, Republic of China or Taiwanese.
Definition: klocale.h:667
QString i18nc(const char *context, const char *text, const TYPE &arg...)
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
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 Aug 7 2020 22:56:37 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.