KDECore
kcalendarsystemjapanese.cpp
Go to the documentation of this file.
00001 /* 00002 Copyright 2009, 2010 John Layt <john@layt.net> 00003 00004 This library is free software; you can redistribute it and/or 00005 modify it under the terms of the GNU Library General Public 00006 License as published by the Free Software Foundation; either 00007 version 2 of the License, or (at your option) any later version. 00008 00009 This library is distributed in the hope that it will be useful, 00010 but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00012 Library General Public License for more details. 00013 00014 You should have received a copy of the GNU Library General Public License 00015 along with this library; see the file COPYING.LIB. If not, write to 00016 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00017 Boston, MA 02110-1301, USA. 00018 */ 00019 00020 #include "kcalendarsystemjapanese_p.h" 00021 #include "kcalendarsystemgregorianprivate_p.h" 00022 00023 #include "kdebug.h" 00024 #include "klocale.h" 00025 00026 #include <QtCore/QDate> 00027 00028 //Reuse the Gregorian private implementation 00029 class KCalendarSystemJapanesePrivate : public KCalendarSystemGregorianPrivate 00030 { 00031 public: 00032 explicit KCalendarSystemJapanesePrivate(KCalendarSystemJapanese *q); 00033 virtual ~KCalendarSystemJapanesePrivate(); 00034 00035 virtual KLocale::CalendarSystem calendarSystem() const; 00036 virtual void loadDefaultEraList(); 00037 virtual int earliestValidYear() const; 00038 }; 00039 00040 //Override only a few of the Gregorian private methods 00041 00042 KCalendarSystemJapanesePrivate::KCalendarSystemJapanesePrivate(KCalendarSystemJapanese *q) 00043 : KCalendarSystemGregorianPrivate(q) 00044 { 00045 } 00046 00047 KCalendarSystemJapanesePrivate::~KCalendarSystemJapanesePrivate() 00048 { 00049 } 00050 00051 KLocale::CalendarSystem KCalendarSystemJapanesePrivate::calendarSystem() const 00052 { 00053 return KLocale::JapaneseCalendar; 00054 } 00055 00056 void KCalendarSystemJapanesePrivate::loadDefaultEraList() 00057 { 00058 QString name, shortName, format; 00059 00060 // Nengō, Only do most recent for now, use AD for the rest. 00061 // Feel free to add more, but have mercy on the translators :-) 00062 00063 name = i18nc("Calendar Era: Gregorian Christian Era, years > 0, LongFormat", "Anno Domini"); 00064 shortName = i18nc("Calendar Era: Gregorian Christian Era, years > 0, ShortFormat", "AD"); 00065 format = i18nc("(kdedt-format) Gregorian, AD, full era year format used for %EY, e.g. 2000 AD", "%Ey %EC"); 00066 addEra('+', 1, q->epoch(), 1, QDate(1868, 9, 7), name, shortName, format); 00067 00068 name = i18nc("Calendar Era: Japanese Nengō, Meiji Era, LongFormat", "Meiji"); 00069 shortName = name; 00070 format = i18nc("(kdedt-format) Japanese, Meiji, full era year format used for %EY, year = 1, e.g. Meiji 1", "%EC Gannen"); 00071 addEra('+', 1, QDate(1868, 9, 8), 1868, QDate(1868, 12, 31), name, shortName, format); 00072 format = i18nc("(kdedt-format) Japanese, Meiji, full era year format used for %EY, year > 1, e.g. Meiji 22", "%EC %Ey"); 00073 addEra('+', 2, QDate(1869, 1, 1), 1869, QDate(1912, 7, 29), name, shortName, format); 00074 00075 name = i18nc("Calendar Era: Japanese Nengō, Taishō Era, LongFormat", "Taishō"); 00076 shortName = name; 00077 format = i18nc("(kdedt-format) Japanese, Taishō, full era year format used for %EY, year = 1, e.g. Taishō 1", "%EC Gannen"); 00078 addEra('+', 1, QDate(1912, 7, 30), 1912, QDate(1912, 12, 31), name, shortName, format); 00079 format = i18nc("(kdedt-format) Japanese, Taishō, full era year format used for %EY, year > 1, e.g. Taishō 22", "%EC %Ey"); 00080 addEra('+', 2, QDate(1913, 1, 1), 1913, QDate(1926, 12, 24), name, shortName, format); 00081 00082 name = i18nc("Calendar Era: Japanese Nengō, Shōwa Era, LongFormat", "Shōwa"); 00083 shortName = name; 00084 format = i18nc("(kdedt-format) Japanese, Shōwa, full era year format used for %EY, year = 1, e.g. Shōwa 1", "%EC Gannen"); 00085 addEra('+', 1, QDate(1926, 12, 25), 1926, QDate(1926, 12, 31), name, shortName, format); 00086 format = i18nc("(kdedt-format) Japanese, Shōwa, full era year format used for %EY, year > 1, e.g. Shōwa 22", "%EC %Ey"); 00087 addEra('+', 2, QDate(1927, 1, 1), 1927, QDate(1989, 1, 7), name, shortName, format); 00088 00089 name = i18nc("Calendar Era: Japanese Nengō, Heisei Era, LongFormat", "Heisei"); 00090 shortName = name; 00091 format = i18nc("(kdedt-format) Japanese, Heisei, full era year format used for %EY, year = 1, e.g. Heisei 1", "%EC Gannen"); 00092 addEra('+', 1, QDate(1989, 1, 8), 1989, QDate(1989, 12, 31), name, shortName, format); 00093 format = i18nc("(kdedt-format) Japanese, Heisei, full era year format used for %EY, year > 1, e.g. Heisei 22", "%EC %Ey"); 00094 addEra('+', 2, QDate(1990, 1, 1), 1990, q->latestValidDate(), name, shortName, format); 00095 } 00096 00097 int KCalendarSystemJapanesePrivate::earliestValidYear() const 00098 { 00099 return 1; 00100 } 00101 00102 00103 KCalendarSystemJapanese::KCalendarSystemJapanese(const KLocale *locale) 00104 : KCalendarSystemGregorian(*new KCalendarSystemJapanesePrivate(this), KSharedConfig::Ptr(), locale) 00105 { 00106 d_ptr->loadConfig(calendarType()); 00107 } 00108 00109 KCalendarSystemJapanese::KCalendarSystemJapanese(const KSharedConfig::Ptr config, const KLocale *locale) 00110 : KCalendarSystemGregorian(*new KCalendarSystemJapanesePrivate(this), config, locale) 00111 { 00112 d_ptr->loadConfig(calendarType()); 00113 } 00114 00115 KCalendarSystemJapanese::KCalendarSystemJapanese(KCalendarSystemJapanesePrivate &dd, 00116 const KSharedConfig::Ptr config, const KLocale *locale) 00117 : KCalendarSystemGregorian(dd, config, locale) 00118 { 00119 d_ptr->loadConfig(calendarType()); 00120 } 00121 00122 KCalendarSystemJapanese::~KCalendarSystemJapanese() 00123 { 00124 } 00125 00126 QString KCalendarSystemJapanese::calendarType() const 00127 { 00128 return QLatin1String("japanese"); 00129 } 00130 00131 QDate KCalendarSystemJapanese::epoch() const 00132 { 00133 // 0001-01-01 Gregorian for now 00134 return QDate::fromJulianDay(1721426); 00135 } 00136 00137 QDate KCalendarSystemJapanese::earliestValidDate() const 00138 { 00139 // 0001-01-01 Gregorian for now 00140 return QDate::fromJulianDay(1721426); 00141 } 00142 00143 QDate KCalendarSystemJapanese::latestValidDate() const 00144 { 00145 // Set to last day of year 9999 until confirm date formats & widgets support > 9999 00146 // 9999-12-31 Gregorian 00147 return QDate::fromJulianDay(5373484); 00148 } 00149 00150 bool KCalendarSystemJapanese::isValid(int year, int month, int day) const 00151 { 00152 return KCalendarSystemGregorian::isValid(year, month, day); 00153 } 00154 00155 bool KCalendarSystemJapanese::isValid(const QDate &date) const 00156 { 00157 return KCalendarSystemGregorian::isValid(date); 00158 } 00159 00160 bool KCalendarSystemJapanese::isLeapYear(int year) const 00161 { 00162 return KCalendarSystemGregorian::isLeapYear(year); 00163 } 00164 00165 bool KCalendarSystemJapanese::isLeapYear(const QDate &date) const 00166 { 00167 return KCalendarSystemGregorian::isLeapYear(date); 00168 } 00169 00170 QString KCalendarSystemJapanese::monthName(int month, int year, MonthNameFormat format) const 00171 { 00172 return KCalendarSystemGregorian::monthName(month, year, format); 00173 } 00174 00175 QString KCalendarSystemJapanese::monthName(const QDate &date, MonthNameFormat format) const 00176 { 00177 return KCalendarSystemGregorian::monthName(date, format); 00178 } 00179 00180 QString KCalendarSystemJapanese::weekDayName(int weekDay, WeekDayNameFormat format) const 00181 { 00182 return KCalendarSystemGregorian::weekDayName(weekDay, format); 00183 } 00184 00185 QString KCalendarSystemJapanese::weekDayName(const QDate &date, WeekDayNameFormat format) const 00186 { 00187 return KCalendarSystemGregorian::weekDayName(date, format); 00188 } 00189 00190 int KCalendarSystemJapanese::yearStringToInteger(const QString &sNum, int &iLength) const 00191 { 00192 QString gannen = i18nc("Japanese year 1 of era", "Gannen"); 00193 if (sNum.startsWith(gannen, Qt::CaseInsensitive)) { 00194 iLength = gannen.length(); 00195 return 1; 00196 } else { 00197 return KCalendarSystemGregorian::yearStringToInteger(sNum, iLength); 00198 } 00199 } 00200 00201 int KCalendarSystemJapanese::weekDayOfPray() const 00202 { 00203 return 7; // TODO JPL ??? 00204 } 00205 00206 bool KCalendarSystemJapanese::isLunar() const 00207 { 00208 return KCalendarSystemGregorian::isLunar(); 00209 } 00210 00211 bool KCalendarSystemJapanese::isLunisolar() const 00212 { 00213 return KCalendarSystemGregorian::isLunisolar(); 00214 } 00215 00216 bool KCalendarSystemJapanese::isSolar() const 00217 { 00218 return KCalendarSystemGregorian::isSolar(); 00219 } 00220 00221 bool KCalendarSystemJapanese::isProleptic() const 00222 { 00223 return false; 00224 } 00225 00226 bool KCalendarSystemJapanese::julianDayToDate(int jd, int &year, int &month, int &day) const 00227 { 00228 return KCalendarSystemGregorian::julianDayToDate(jd, year, month, day); 00229 } 00230 00231 bool KCalendarSystemJapanese::dateToJulianDay(int year, int month, int day, int &jd) const 00232 { 00233 return KCalendarSystemGregorian::dateToJulianDay(year, month, day, jd); 00234 }
KDE 4.7 API Reference