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 "kcalendarsystemgregorianprolepticprivate_p.h" 00022 00023 #include "kdebug.h" 00024 #include "klocale.h" 00025 00026 #include <QtCore/QDate> 00027 00028 //Reuse the Gregorian Proleptic private implementation 00029 class KCalendarSystemJapanesePrivate : public KCalendarSystemGregorianProlepticPrivate 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 Proleptic private methods 00041 00042 KCalendarSystemJapanesePrivate::KCalendarSystemJapanesePrivate( KCalendarSystemJapanese *q ) 00043 : KCalendarSystemGregorianProlepticPrivate( 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 : KCalendarSystemGregorianProleptic( *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 : KCalendarSystemGregorianProleptic( *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 : KCalendarSystemGregorianProleptic( 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 KCalendarSystemGregorianProleptic::isValid( year, month, day ); 00153 } 00154 00155 bool KCalendarSystemJapanese::isValid( const QDate &date ) const 00156 { 00157 return KCalendarSystemGregorianProleptic::isValid( date ); 00158 } 00159 00160 bool KCalendarSystemJapanese::setDate( QDate &date, int year, int month, int day ) const 00161 { 00162 return KCalendarSystemGregorianProleptic::setDate( date, year, month, day ); 00163 } 00164 00165 // Deprecated 00166 bool KCalendarSystemJapanese::setYMD( QDate &date, int y, int m, int d ) const 00167 { 00168 return KCalendarSystemGregorianProleptic::setDate( date, y, m, d ); 00169 } 00170 00171 int KCalendarSystemJapanese::year( const QDate &date ) const 00172 { 00173 return KCalendarSystemGregorianProleptic::year( date ); 00174 } 00175 00176 int KCalendarSystemJapanese::month( const QDate &date ) const 00177 { 00178 return KCalendarSystemGregorianProleptic::month( date ); 00179 } 00180 00181 int KCalendarSystemJapanese::day( const QDate &date ) const 00182 { 00183 return KCalendarSystemGregorianProleptic::day( date ); 00184 } 00185 00186 QDate KCalendarSystemJapanese::addYears( const QDate &date, int nyears ) const 00187 { 00188 return KCalendarSystemGregorianProleptic::addYears( date, nyears ); 00189 } 00190 00191 QDate KCalendarSystemJapanese::addMonths( const QDate &date, int nmonths ) const 00192 { 00193 return KCalendarSystemGregorianProleptic::addMonths( date, nmonths ); 00194 } 00195 00196 QDate KCalendarSystemJapanese::addDays( const QDate &date, int ndays ) const 00197 { 00198 return KCalendarSystemGregorianProleptic::addDays( date, ndays ); 00199 } 00200 00201 int KCalendarSystemJapanese::monthsInYear( const QDate &date ) const 00202 { 00203 return KCalendarSystemGregorianProleptic::monthsInYear( date ); 00204 } 00205 00206 int KCalendarSystemJapanese::weeksInYear( const QDate &date ) const 00207 { 00208 return KCalendarSystemGregorianProleptic::weeksInYear( date ); 00209 } 00210 00211 int KCalendarSystemJapanese::weeksInYear( int year ) const 00212 { 00213 return KCalendarSystemGregorianProleptic::weeksInYear( year ); 00214 } 00215 00216 int KCalendarSystemJapanese::daysInYear( const QDate &date ) const 00217 { 00218 return KCalendarSystemGregorianProleptic::daysInYear( date ); 00219 } 00220 00221 int KCalendarSystemJapanese::daysInMonth( const QDate &date ) const 00222 { 00223 return KCalendarSystemGregorianProleptic::daysInMonth( date ); 00224 } 00225 00226 int KCalendarSystemJapanese::daysInWeek( const QDate &date ) const 00227 { 00228 return KCalendarSystemGregorianProleptic::daysInWeek( date ); 00229 } 00230 00231 int KCalendarSystemJapanese::dayOfYear( const QDate &date ) const 00232 { 00233 return KCalendarSystemGregorianProleptic::dayOfYear( date ); 00234 } 00235 00236 int KCalendarSystemJapanese::dayOfWeek( const QDate &date ) const 00237 { 00238 return KCalendarSystemGregorianProleptic::dayOfWeek( date ); 00239 } 00240 00241 int KCalendarSystemJapanese::weekNumber( const QDate &date, int * yearNum ) const 00242 { 00243 return KCalendarSystemGregorianProleptic::weekNumber( date, yearNum ); 00244 } 00245 00246 bool KCalendarSystemJapanese::isLeapYear( int year ) const 00247 { 00248 return KCalendarSystemGregorianProleptic::isLeapYear( year ); 00249 } 00250 00251 bool KCalendarSystemJapanese::isLeapYear( const QDate &date ) const 00252 { 00253 return KCalendarSystemGregorianProleptic::isLeapYear( date ); 00254 } 00255 00256 QString KCalendarSystemJapanese::monthName( int month, int year, MonthNameFormat format ) const 00257 { 00258 return KCalendarSystemGregorianProleptic::monthName( month, year, format ); 00259 } 00260 00261 QString KCalendarSystemJapanese::monthName( const QDate &date, MonthNameFormat format ) const 00262 { 00263 return KCalendarSystemGregorianProleptic::monthName( date, format ); 00264 } 00265 00266 QString KCalendarSystemJapanese::weekDayName( int weekDay, WeekDayNameFormat format ) const 00267 { 00268 return KCalendarSystemGregorianProleptic::weekDayName( weekDay, format ); 00269 } 00270 00271 QString KCalendarSystemJapanese::weekDayName( const QDate &date, WeekDayNameFormat format ) const 00272 { 00273 return KCalendarSystemGregorianProleptic::weekDayName( date, format ); 00274 } 00275 00276 QString KCalendarSystemJapanese::yearString( const QDate &pDate, StringFormat format ) const 00277 { 00278 return KCalendarSystemGregorianProleptic::yearString( pDate, format ); 00279 } 00280 00281 QString KCalendarSystemJapanese::monthString( const QDate &pDate, StringFormat format ) const 00282 { 00283 return KCalendarSystemGregorianProleptic::monthString( pDate, format ); 00284 } 00285 00286 QString KCalendarSystemJapanese::dayString( const QDate &pDate, StringFormat format ) const 00287 { 00288 return KCalendarSystemGregorianProleptic::dayString( pDate, format ); 00289 } 00290 00291 int KCalendarSystemJapanese::yearStringToInteger( const QString &sNum, int &iLength ) const 00292 { 00293 QString gannen = i18nc( "Japanese year 1 of era", "Gannen" ); 00294 if ( sNum.startsWith( gannen, Qt::CaseInsensitive ) ) { 00295 iLength = gannen.length(); 00296 return 1; 00297 } else { 00298 return KCalendarSystemGregorianProleptic::yearStringToInteger( sNum, iLength ); 00299 } 00300 } 00301 00302 int KCalendarSystemJapanese::monthStringToInteger( const QString &sNum, int &iLength ) const 00303 { 00304 return KCalendarSystemGregorianProleptic::monthStringToInteger( sNum, iLength ); 00305 } 00306 00307 int KCalendarSystemJapanese::dayStringToInteger( const QString &sNum, int &iLength ) const 00308 { 00309 return KCalendarSystemGregorianProleptic::dayStringToInteger( sNum, iLength ); 00310 } 00311 00312 QString KCalendarSystemJapanese::formatDate( const QDate &date, KLocale::DateFormat format ) const 00313 { 00314 return KCalendarSystemGregorianProleptic::formatDate( date, format ); 00315 } 00316 00317 QDate KCalendarSystemJapanese::readDate( const QString &str, bool *ok ) const 00318 { 00319 return KCalendarSystemGregorianProleptic::readDate( str, ok ); 00320 } 00321 00322 QDate KCalendarSystemJapanese::readDate( const QString &intstr, const QString &fmt, bool *ok ) const 00323 { 00324 return KCalendarSystemGregorianProleptic::readDate( intstr, fmt, ok ); 00325 } 00326 00327 QDate KCalendarSystemJapanese::readDate( const QString &str, KLocale::ReadDateFlags flags, bool *ok ) const 00328 { 00329 return KCalendarSystemGregorianProleptic::readDate( str, flags, ok ); 00330 } 00331 00332 int KCalendarSystemJapanese::weekStartDay() const 00333 { 00334 return KCalendarSystemGregorianProleptic::weekStartDay(); 00335 } 00336 00337 int KCalendarSystemJapanese::weekDayOfPray() const 00338 { 00339 return 7; // TODO JPL ??? 00340 } 00341 00342 bool KCalendarSystemJapanese::isLunar() const 00343 { 00344 return KCalendarSystemGregorianProleptic::isLunar(); 00345 } 00346 00347 bool KCalendarSystemJapanese::isLunisolar() const 00348 { 00349 return KCalendarSystemGregorianProleptic::isLunisolar(); 00350 } 00351 00352 bool KCalendarSystemJapanese::isSolar() const 00353 { 00354 return KCalendarSystemGregorianProleptic::isSolar(); 00355 } 00356 00357 bool KCalendarSystemJapanese::isProleptic() const 00358 { 00359 return false; 00360 } 00361 00362 bool KCalendarSystemJapanese::julianDayToDate( int jd, int &year, int &month, int &day ) const 00363 { 00364 return KCalendarSystemGregorianProleptic::julianDayToDate( jd, year, month, day ); 00365 } 00366 00367 bool KCalendarSystemJapanese::dateToJulianDay( int year, int month, int day, int &jd ) const 00368 { 00369 return KCalendarSystemGregorianProleptic::dateToJulianDay( year, month, day, jd ); 00370 }
KDE 4.6 API Reference