File indexing completed on 2024-04-28 11:36:02

0001 /*
0002     Copyright 2010 John Layt <john@layt.net>
0003 
0004     This library is free software; you can redistribute it and/or
0005     modify it under the terms of the GNU Library General Public
0006     License as published by the Free Software Foundation; either
0007     version 2 of the License, or (at your option) any later version.
0008 
0009     This library is distributed in the hope that it will be useful,
0010     but WITHOUT ANY WARRANTY; without even the implied warranty of
0011     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0012     Library General Public License for more details.
0013 
0014     You should have received a copy of the GNU Library General Public License
0015     along with this library; see the file COPYING.LIB.  If not, write to
0016     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0017     Boston, MA 02110-1301, USA.
0018 */
0019 
0020 #include "kcalendarsystemminguo_p.h"
0021 #include "kcalendarsystemgregorianprivate_p.h"
0022 
0023 #include "klocale.h"
0024 #include "klocalizedstring.h"
0025 
0026 #include <QDate>
0027 
0028 //Reuse the Gregorian private implementation
0029 class KCalendarSystemMinguoPrivate : public KCalendarSystemGregorianPrivate
0030 {
0031 public:
0032     KDELIBS4SUPPORT_DEPRECATED explicit KCalendarSystemMinguoPrivate(KCalendarSystemMinguo *q);
0033     ~KCalendarSystemMinguoPrivate() override;
0034 
0035     void loadDefaultEraList() override;
0036     int daysInMonth(int year, int month) const override;
0037     int daysInYear(int year) const override;
0038     bool isLeapYear(int year) const override;
0039     int earliestValidYear() const override;
0040 };
0041 
0042 //Override only a few of the Gregorian private methods
0043 
0044 KCalendarSystemMinguoPrivate::KCalendarSystemMinguoPrivate(KCalendarSystemMinguo *q)
0045     : KCalendarSystemGregorianPrivate(q)
0046 {
0047 }
0048 
0049 KCalendarSystemMinguoPrivate::~KCalendarSystemMinguoPrivate()
0050 {
0051 }
0052 
0053 void KCalendarSystemMinguoPrivate::loadDefaultEraList()
0054 {
0055     QString name, shortName, format;
0056 
0057     name = i18nc("Calendar Era: Taiwan Republic of China Era, years > 0, LongFormat", "Republic of China Era");
0058     shortName = i18nc("Calendar Era: Taiwan Republic of China Era, years > 0, ShortFormat", "ROC");
0059     format = i18nc("(kdedt-format) Taiwan, ROC, full era year format used for %EY, e.g. ROC 99", "%EC %Ey");
0060     addEra('+', 1, q->epoch(), 1, q->latestValidDate(), name, shortName, format);
0061 }
0062 
0063 int KCalendarSystemMinguoPrivate::daysInMonth(int year, int month) const
0064 {
0065     return KCalendarSystemGregorianPrivate::daysInMonth(year + 1911, month);
0066 }
0067 
0068 int KCalendarSystemMinguoPrivate::daysInYear(int year) const
0069 {
0070     return KCalendarSystemGregorianPrivate::daysInYear(year + 1911);
0071 }
0072 
0073 bool KCalendarSystemMinguoPrivate::isLeapYear(int year) const
0074 {
0075     return KCalendarSystemGregorianPrivate::isLeapYear(year + 1911);
0076 }
0077 
0078 int KCalendarSystemMinguoPrivate::earliestValidYear() const
0079 {
0080     return 1;
0081 }
0082 
0083 KCalendarSystemMinguo::KCalendarSystemMinguo(const KSharedConfig::Ptr config, const KLocale *locale)
0084     : KCalendarSystemGregorian(*new KCalendarSystemMinguoPrivate(this), config, locale)
0085 {
0086     d_ptr->loadConfig(calendarType());
0087 }
0088 
0089 KCalendarSystemMinguo::KCalendarSystemMinguo(KCalendarSystemMinguoPrivate &dd,
0090         const KSharedConfig::Ptr config, const KLocale *locale)
0091     : KCalendarSystemGregorian(dd, config, locale)
0092 {
0093     d_ptr->loadConfig(calendarType());
0094 }
0095 
0096 KCalendarSystemMinguo::~KCalendarSystemMinguo()
0097 {
0098 }
0099 
0100 QString KCalendarSystemMinguo::calendarType() const
0101 {
0102     return QLatin1String("minguo");
0103 }
0104 
0105 KLocale::CalendarSystem KCalendarSystemMinguo::calendarSystem() const
0106 {
0107     return KLocale::MinguoCalendar;
0108 }
0109 
0110 QDate KCalendarSystemMinguo::epoch() const
0111 {
0112     // 0001-01-01 = 1912-01-01 AD Gregorian
0113     return QDate::fromJulianDay(2419403);
0114 }
0115 
0116 QDate KCalendarSystemMinguo::earliestValidDate() const
0117 {
0118     return epoch();
0119 }
0120 
0121 QDate KCalendarSystemMinguo::latestValidDate() const
0122 {
0123     // Set to last day of year 9999 until confirm date formats & widgets support > 9999
0124     // 9999-12-31 = 11910-12-31 AD Gregorian
0125     return QDate::fromJulianDay(6071462);
0126 }
0127 
0128 QString KCalendarSystemMinguo::monthName(int month, int year, MonthNameFormat format) const
0129 {
0130     return KCalendarSystemGregorian::monthName(month, year, format);
0131 }
0132 
0133 QString KCalendarSystemMinguo::monthName(const QDate &date, MonthNameFormat format) const
0134 {
0135     return KCalendarSystemGregorian::monthName(date, format);
0136 }
0137 
0138 QString KCalendarSystemMinguo::weekDayName(int weekDay, WeekDayNameFormat format) const
0139 {
0140     return KCalendarSystemGregorian::weekDayName(weekDay, format);
0141 }
0142 
0143 QString KCalendarSystemMinguo::weekDayName(const QDate &date, WeekDayNameFormat format) const
0144 {
0145     return KCalendarSystemGregorian::weekDayName(date, format);
0146 }
0147 
0148 bool KCalendarSystemMinguo::isLunar() const
0149 {
0150     return KCalendarSystemGregorian::isLunar();
0151 }
0152 
0153 bool KCalendarSystemMinguo::isLunisolar() const
0154 {
0155     return KCalendarSystemGregorian::isLunisolar();
0156 }
0157 
0158 bool KCalendarSystemMinguo::isSolar() const
0159 {
0160     return KCalendarSystemGregorian::isSolar();
0161 }
0162 
0163 bool KCalendarSystemMinguo::isProleptic() const
0164 {
0165     return false;
0166 }
0167 
0168 bool KCalendarSystemMinguo::julianDayToDate(qint64 jd, int &year, int &month, int &day) const
0169 {
0170     bool result = KCalendarSystemGregorian::julianDayToDate(jd, year, month, day);
0171     year = year - 1911;
0172     return result;
0173 }
0174 
0175 bool KCalendarSystemMinguo::dateToJulianDay(int year, int month, int day, qint64 &jd) const
0176 {
0177     return KCalendarSystemGregorian::dateToJulianDay(year + 1911, month, day, jd);
0178 }
0179