File indexing completed on 2023-09-24 04:04:45
0001 /* 0002 Copyright 2009, 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 "kcalendarsystemjapanese_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 KCalendarSystemJapanesePrivate : public KCalendarSystemGregorianPrivate 0030 { 0031 public: 0032 KDELIBS4SUPPORT_DEPRECATED explicit KCalendarSystemJapanesePrivate(KCalendarSystemJapanese *q); 0033 ~KCalendarSystemJapanesePrivate() override; 0034 0035 void loadDefaultEraList() override; 0036 int earliestValidYear() const override; 0037 }; 0038 0039 //Override only a few of the Gregorian private methods 0040 0041 KCalendarSystemJapanesePrivate::KCalendarSystemJapanesePrivate(KCalendarSystemJapanese *q) 0042 : KCalendarSystemGregorianPrivate(q) 0043 { 0044 } 0045 0046 KCalendarSystemJapanesePrivate::~KCalendarSystemJapanesePrivate() 0047 { 0048 } 0049 0050 void KCalendarSystemJapanesePrivate::loadDefaultEraList() 0051 { 0052 QString name, shortName, format; 0053 0054 // Nengō, Only do most recent for now, use AD for the rest. 0055 // Feel free to add more, but have mercy on the translators :-) 0056 0057 name = i18nc("Calendar Era: Gregorian Christian Era, years > 0, LongFormat", "Anno Domini"); 0058 shortName = i18nc("Calendar Era: Gregorian Christian Era, years > 0, ShortFormat", "AD"); 0059 format = i18nc("(kdedt-format) Gregorian, AD, full era year format used for %EY, e.g. 2000 AD", "%Ey %EC"); 0060 addEra('+', 1, q->epoch(), 1, QDate(1868, 9, 7), name, shortName, format); 0061 0062 name = i18nc("Calendar Era: Japanese Nengō, Meiji Era, LongFormat", "Meiji"); 0063 shortName = name; 0064 format = i18nc("(kdedt-format) Japanese, Meiji, full era year format used for %EY, year = 1, e.g. Meiji 1", "%EC Gannen"); 0065 addEra('+', 1, QDate(1868, 9, 8), 1868, QDate(1868, 12, 31), name, shortName, format); 0066 format = i18nc("(kdedt-format) Japanese, Meiji, full era year format used for %EY, year > 1, e.g. Meiji 22", "%EC %Ey"); 0067 addEra('+', 2, QDate(1869, 1, 1), 1869, QDate(1912, 7, 29), name, shortName, format); 0068 0069 name = i18nc("Calendar Era: Japanese Nengō, Taishō Era, LongFormat", "Taishō"); 0070 shortName = name; 0071 format = i18nc("(kdedt-format) Japanese, Taishō, full era year format used for %EY, year = 1, e.g. Taishō 1", "%EC Gannen"); 0072 addEra('+', 1, QDate(1912, 7, 30), 1912, QDate(1912, 12, 31), name, shortName, format); 0073 format = i18nc("(kdedt-format) Japanese, Taishō, full era year format used for %EY, year > 1, e.g. Taishō 22", "%EC %Ey"); 0074 addEra('+', 2, QDate(1913, 1, 1), 1913, QDate(1926, 12, 24), name, shortName, format); 0075 0076 name = i18nc("Calendar Era: Japanese Nengō, Shōwa Era, LongFormat", "Shōwa"); 0077 shortName = name; 0078 format = i18nc("(kdedt-format) Japanese, Shōwa, full era year format used for %EY, year = 1, e.g. Shōwa 1", "%EC Gannen"); 0079 addEra('+', 1, QDate(1926, 12, 25), 1926, QDate(1926, 12, 31), name, shortName, format); 0080 format = i18nc("(kdedt-format) Japanese, Shōwa, full era year format used for %EY, year > 1, e.g. Shōwa 22", "%EC %Ey"); 0081 addEra('+', 2, QDate(1927, 1, 1), 1927, QDate(1989, 1, 7), name, shortName, format); 0082 0083 name = i18nc("Calendar Era: Japanese Nengō, Heisei Era, LongFormat", "Heisei"); 0084 shortName = name; 0085 format = i18nc("(kdedt-format) Japanese, Heisei, full era year format used for %EY, year = 1, e.g. Heisei 1", "%EC Gannen"); 0086 addEra('+', 1, QDate(1989, 1, 8), 1989, QDate(1989, 12, 31), name, shortName, format); 0087 format = i18nc("(kdedt-format) Japanese, Heisei, full era year format used for %EY, year > 1, e.g. Heisei 22", "%EC %Ey"); 0088 addEra('+', 2, QDate(1990, 1, 1), 1990, q->latestValidDate(), name, shortName, format); 0089 } 0090 0091 int KCalendarSystemJapanesePrivate::earliestValidYear() const 0092 { 0093 return 1; 0094 } 0095 0096 KCalendarSystemJapanese::KCalendarSystemJapanese(const KSharedConfig::Ptr config, const KLocale *locale) 0097 : KCalendarSystemGregorian(*new KCalendarSystemJapanesePrivate(this), config, locale) 0098 { 0099 d_ptr->loadConfig(calendarType()); 0100 } 0101 0102 KCalendarSystemJapanese::KCalendarSystemJapanese(KCalendarSystemJapanesePrivate &dd, 0103 const KSharedConfig::Ptr config, const KLocale *locale) 0104 : KCalendarSystemGregorian(dd, config, locale) 0105 { 0106 d_ptr->loadConfig(calendarType()); 0107 } 0108 0109 KCalendarSystemJapanese::~KCalendarSystemJapanese() 0110 { 0111 } 0112 0113 QString KCalendarSystemJapanese::calendarType() const 0114 { 0115 return QLatin1String("japanese"); 0116 } 0117 0118 KLocale::CalendarSystem KCalendarSystemJapanese::calendarSystem() const 0119 { 0120 return KLocale::JapaneseCalendar; 0121 } 0122 0123 QDate KCalendarSystemJapanese::epoch() const 0124 { 0125 // 0001-01-01 Gregorian for now 0126 return QDate::fromJulianDay(1721426); 0127 } 0128 0129 QDate KCalendarSystemJapanese::earliestValidDate() const 0130 { 0131 // 0001-01-01 Gregorian for now 0132 return QDate::fromJulianDay(1721426); 0133 } 0134 0135 QDate KCalendarSystemJapanese::latestValidDate() const 0136 { 0137 // Set to last day of year 9999 until confirm date formats & widgets support > 9999 0138 // 9999-12-31 Gregorian 0139 return QDate::fromJulianDay(5373484); 0140 } 0141 0142 QString KCalendarSystemJapanese::monthName(int month, int year, MonthNameFormat format) const 0143 { 0144 return KCalendarSystemGregorian::monthName(month, year, format); 0145 } 0146 0147 QString KCalendarSystemJapanese::monthName(const QDate &date, MonthNameFormat format) const 0148 { 0149 return KCalendarSystemGregorian::monthName(date, format); 0150 } 0151 0152 QString KCalendarSystemJapanese::weekDayName(int weekDay, WeekDayNameFormat format) const 0153 { 0154 return KCalendarSystemGregorian::weekDayName(weekDay, format); 0155 } 0156 0157 QString KCalendarSystemJapanese::weekDayName(const QDate &date, WeekDayNameFormat format) const 0158 { 0159 return KCalendarSystemGregorian::weekDayName(date, format); 0160 } 0161 0162 int KCalendarSystemJapanese::yearStringToInteger(const QString &sNum, int &iLength) const 0163 { 0164 QString gannen = i18nc("Japanese year 1 of era", "Gannen"); 0165 if (sNum.startsWith(gannen, Qt::CaseInsensitive)) { 0166 iLength = gannen.length(); 0167 return 1; 0168 } else { 0169 return KCalendarSystemGregorian::yearStringToInteger(sNum, iLength); 0170 } 0171 } 0172 0173 bool KCalendarSystemJapanese::isLunar() const 0174 { 0175 return KCalendarSystemGregorian::isLunar(); 0176 } 0177 0178 bool KCalendarSystemJapanese::isLunisolar() const 0179 { 0180 return KCalendarSystemGregorian::isLunisolar(); 0181 } 0182 0183 bool KCalendarSystemJapanese::isSolar() const 0184 { 0185 return KCalendarSystemGregorian::isSolar(); 0186 } 0187 0188 bool KCalendarSystemJapanese::isProleptic() const 0189 { 0190 return false; 0191 } 0192 0193 bool KCalendarSystemJapanese::julianDayToDate(qint64 jd, int &year, int &month, int &day) const 0194 { 0195 return KCalendarSystemGregorian::julianDayToDate(jd, year, month, day); 0196 } 0197 0198 bool KCalendarSystemJapanese::dateToJulianDay(int year, int month, int day, qint64 &jd) const 0199 { 0200 return KCalendarSystemGregorian::dateToJulianDay(year, month, day, jd); 0201 }