KDECore
kcalendarsystemthai.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 "kcalendarsystemthai_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 KCalendarSystemThaiPrivate : public KCalendarSystemGregorianProlepticPrivate 00030 { 00031 public: 00032 explicit KCalendarSystemThaiPrivate( KCalendarSystemThai *q ); 00033 virtual ~KCalendarSystemThaiPrivate(); 00034 00035 virtual KLocale::CalendarSystem calendarSystem() const; 00036 virtual void loadDefaultEraList(); 00037 virtual bool isLeapYear( int year ) const; 00038 virtual bool hasYearZero() const; 00039 virtual int earliestValidYear() const; 00040 }; 00041 00042 //Override only a few of the Gregorian Proleptic private methods 00043 00044 KCalendarSystemThaiPrivate::KCalendarSystemThaiPrivate( KCalendarSystemThai *q ) 00045 : KCalendarSystemGregorianProlepticPrivate( q ) 00046 { 00047 } 00048 00049 KCalendarSystemThaiPrivate::~KCalendarSystemThaiPrivate() 00050 { 00051 } 00052 00053 KLocale::CalendarSystem KCalendarSystemThaiPrivate::calendarSystem() const 00054 { 00055 return KLocale::ThaiCalendar; 00056 } 00057 00058 void KCalendarSystemThaiPrivate::loadDefaultEraList() 00059 { 00060 QString name, shortName, format; 00061 00062 name = i18nc( "Calendar Era: Thai Buddhist Era, years > 0, LongFormat", "Buddhist Era" ); 00063 shortName = i18nc( "Calendar Era: Thai Buddhist Era, years > 0, ShortFormat", "BE" ); 00064 format = i18nc( "(kdedt-format) Thai, BE, full era year format used for %EY, e.g. 2000 BE", "%Ey %EC" ); 00065 addEra( '+', 1, q->epoch(), 1, q->latestValidDate(), name, shortName, format ); 00066 } 00067 00068 bool KCalendarSystemThaiPrivate::isLeapYear( int year ) const 00069 { 00070 return KCalendarSystemGregorianProlepticPrivate::isLeapYear( year - 543 ); 00071 } 00072 00073 bool KCalendarSystemThaiPrivate::hasYearZero() const 00074 { 00075 return true; 00076 } 00077 00078 int KCalendarSystemThaiPrivate::earliestValidYear() const 00079 { 00080 return 0; 00081 } 00082 00083 00084 KCalendarSystemThai::KCalendarSystemThai( const KLocale *locale ) 00085 : KCalendarSystemGregorianProleptic( *new KCalendarSystemThaiPrivate( this ), KSharedConfig::Ptr(), locale ) 00086 { 00087 d_ptr->loadConfig( calendarType() ); 00088 } 00089 00090 KCalendarSystemThai::KCalendarSystemThai( const KSharedConfig::Ptr config, const KLocale *locale ) 00091 : KCalendarSystemGregorianProleptic( *new KCalendarSystemThaiPrivate( this ), config, locale ) 00092 { 00093 d_ptr->loadConfig( calendarType() ); 00094 } 00095 00096 KCalendarSystemThai::KCalendarSystemThai( KCalendarSystemThaiPrivate &dd, 00097 const KSharedConfig::Ptr config, const KLocale *locale ) 00098 : KCalendarSystemGregorianProleptic( dd, config, locale ) 00099 { 00100 d_ptr->loadConfig( calendarType() ); 00101 } 00102 00103 KCalendarSystemThai::~KCalendarSystemThai() 00104 { 00105 } 00106 00107 QString KCalendarSystemThai::calendarType() const 00108 { 00109 return QLatin1String( "thai" ); 00110 } 00111 00112 QDate KCalendarSystemThai::epoch() const 00113 { 00114 // 0000-01-01 = 0544-01-01 BC Gregorian = 0544-01-07 BC Julian 00115 return QDate::fromJulianDay( 1522734 ); 00116 } 00117 00118 QDate KCalendarSystemThai::earliestValidDate() const 00119 { 00120 return epoch(); 00121 } 00122 00123 QDate KCalendarSystemThai::latestValidDate() const 00124 { 00125 // Set to last day of year 9999 until confirm date formats & widgets support > 9999 00126 // 9999-12-31 = 9456-12-31 AD Gregorian 00127 return QDate::fromJulianDay( 5175158 ); 00128 } 00129 00130 bool KCalendarSystemThai::isValid( int year, int month, int day ) const 00131 { 00132 return KCalendarSystemGregorianProleptic::isValid( year, month, day ); 00133 } 00134 00135 bool KCalendarSystemThai::isValid( const QDate &date ) const 00136 { 00137 return KCalendarSystemGregorianProleptic::isValid( date ); 00138 } 00139 00140 bool KCalendarSystemThai::setDate( QDate &date, int year, int month, int day ) const 00141 { 00142 return KCalendarSystemGregorianProleptic::setDate( date, year, month, day ); 00143 } 00144 00145 // Deprecated 00146 bool KCalendarSystemThai::setYMD( QDate &date, int y, int m, int d ) const 00147 { 00148 return KCalendarSystemGregorianProleptic::setDate( date, y, m, d ); 00149 } 00150 00151 int KCalendarSystemThai::year( const QDate &date ) const 00152 { 00153 return KCalendarSystemGregorianProleptic::year( date ); 00154 } 00155 00156 int KCalendarSystemThai::month( const QDate &date ) const 00157 { 00158 return KCalendarSystemGregorianProleptic::month( date ); 00159 } 00160 00161 int KCalendarSystemThai::day( const QDate &date ) const 00162 { 00163 return KCalendarSystemGregorianProleptic::day( date ); 00164 } 00165 00166 QDate KCalendarSystemThai::addYears( const QDate &date, int nyears ) const 00167 { 00168 return KCalendarSystemGregorianProleptic::addYears( date, nyears ); 00169 } 00170 00171 QDate KCalendarSystemThai::addMonths( const QDate &date, int nmonths ) const 00172 { 00173 return KCalendarSystemGregorianProleptic::addMonths( date, nmonths ); 00174 } 00175 00176 QDate KCalendarSystemThai::addDays( const QDate &date, int ndays ) const 00177 { 00178 return KCalendarSystemGregorianProleptic::addDays( date, ndays ); 00179 } 00180 00181 int KCalendarSystemThai::monthsInYear( const QDate &date ) const 00182 { 00183 return KCalendarSystemGregorianProleptic::monthsInYear( date ); 00184 } 00185 00186 int KCalendarSystemThai::weeksInYear( const QDate &date ) const 00187 { 00188 return KCalendarSystemGregorianProleptic::weeksInYear( date ); 00189 } 00190 00191 int KCalendarSystemThai::weeksInYear( int year ) const 00192 { 00193 return KCalendarSystemGregorianProleptic::weeksInYear( year ); 00194 } 00195 00196 int KCalendarSystemThai::daysInYear( const QDate &date ) const 00197 { 00198 return KCalendarSystemGregorianProleptic::daysInYear( date ); 00199 } 00200 00201 int KCalendarSystemThai::daysInMonth( const QDate &date ) const 00202 { 00203 return KCalendarSystemGregorianProleptic::daysInMonth( date ); 00204 } 00205 00206 int KCalendarSystemThai::daysInWeek( const QDate &date ) const 00207 { 00208 return KCalendarSystemGregorianProleptic::daysInWeek( date ); 00209 } 00210 00211 int KCalendarSystemThai::dayOfYear( const QDate &date ) const 00212 { 00213 return KCalendarSystemGregorianProleptic::dayOfYear( date ); 00214 } 00215 00216 int KCalendarSystemThai::dayOfWeek( const QDate &date ) const 00217 { 00218 return KCalendarSystemGregorianProleptic::dayOfWeek( date ); 00219 } 00220 00221 int KCalendarSystemThai::weekNumber( const QDate &date, int * yearNum ) const 00222 { 00223 return KCalendarSystemGregorianProleptic::weekNumber( date, yearNum ); 00224 } 00225 00226 bool KCalendarSystemThai::isLeapYear( int year ) const 00227 { 00228 return KCalendarSystemGregorianProleptic::isLeapYear( year ); 00229 } 00230 00231 bool KCalendarSystemThai::isLeapYear( const QDate &date ) const 00232 { 00233 return KCalendarSystemGregorianProleptic::isLeapYear( date ); 00234 } 00235 00236 QString KCalendarSystemThai::monthName( int month, int year, MonthNameFormat format ) const 00237 { 00238 return KCalendarSystemGregorianProleptic::monthName( month, year, format ); 00239 } 00240 00241 QString KCalendarSystemThai::monthName( const QDate &date, MonthNameFormat format ) const 00242 { 00243 return KCalendarSystemGregorianProleptic::monthName( date, format ); 00244 } 00245 00246 QString KCalendarSystemThai::weekDayName( int weekDay, WeekDayNameFormat format ) const 00247 { 00248 return KCalendarSystemGregorianProleptic::weekDayName( weekDay, format ); 00249 } 00250 00251 QString KCalendarSystemThai::weekDayName( const QDate &date, WeekDayNameFormat format ) const 00252 { 00253 return KCalendarSystemGregorianProleptic::weekDayName( date, format ); 00254 } 00255 00256 QString KCalendarSystemThai::yearString( const QDate &pDate, StringFormat format ) const 00257 { 00258 return KCalendarSystemGregorianProleptic::yearString( pDate, format ); 00259 } 00260 00261 QString KCalendarSystemThai::monthString( const QDate &pDate, StringFormat format ) const 00262 { 00263 return KCalendarSystemGregorianProleptic::monthString( pDate, format ); 00264 } 00265 00266 QString KCalendarSystemThai::dayString( const QDate &pDate, StringFormat format ) const 00267 { 00268 return KCalendarSystemGregorianProleptic::dayString( pDate, format ); 00269 } 00270 00271 int KCalendarSystemThai::yearStringToInteger( const QString &sNum, int &iLength ) const 00272 { 00273 return KCalendarSystemGregorianProleptic::yearStringToInteger( sNum, iLength ); 00274 } 00275 00276 int KCalendarSystemThai::monthStringToInteger( const QString &sNum, int &iLength ) const 00277 { 00278 return KCalendarSystemGregorianProleptic::monthStringToInteger( sNum, iLength ); 00279 } 00280 00281 int KCalendarSystemThai::dayStringToInteger( const QString &sNum, int &iLength ) const 00282 { 00283 return KCalendarSystemGregorianProleptic::dayStringToInteger( sNum, iLength ); 00284 } 00285 00286 QString KCalendarSystemThai::formatDate( const QDate &date, KLocale::DateFormat format ) const 00287 { 00288 return KCalendarSystemGregorianProleptic::formatDate( date, format ); 00289 } 00290 00291 QDate KCalendarSystemThai::readDate( const QString &str, bool *ok ) const 00292 { 00293 return KCalendarSystemGregorianProleptic::readDate( str, ok ); 00294 } 00295 00296 QDate KCalendarSystemThai::readDate( const QString &intstr, const QString &fmt, bool *ok ) const 00297 { 00298 return KCalendarSystemGregorianProleptic::readDate( intstr, fmt, ok ); 00299 } 00300 00301 QDate KCalendarSystemThai::readDate( const QString &str, KLocale::ReadDateFlags flags, bool *ok ) const 00302 { 00303 return KCalendarSystemGregorianProleptic::readDate( str, flags, ok ); 00304 } 00305 00306 int KCalendarSystemThai::weekStartDay() const 00307 { 00308 return KCalendarSystemGregorianProleptic::weekStartDay(); 00309 } 00310 00311 int KCalendarSystemThai::weekDayOfPray() const 00312 { 00313 return 7; // TODO JPL ??? 00314 } 00315 00316 bool KCalendarSystemThai::isLunar() const 00317 { 00318 return KCalendarSystemGregorianProleptic::isLunar(); 00319 } 00320 00321 bool KCalendarSystemThai::isLunisolar() const 00322 { 00323 return KCalendarSystemGregorianProleptic::isLunisolar(); 00324 } 00325 00326 bool KCalendarSystemThai::isSolar() const 00327 { 00328 return KCalendarSystemGregorianProleptic::isSolar(); 00329 } 00330 00331 bool KCalendarSystemThai::isProleptic() const 00332 { 00333 return false; 00334 } 00335 00336 bool KCalendarSystemThai::julianDayToDate( int jd, int &year, int &month, int &day ) const 00337 { 00338 bool result = KCalendarSystemGregorianProleptic::julianDayToDate( jd, year, month, day ); 00339 year = year + 543; 00340 return result; 00341 } 00342 00343 bool KCalendarSystemThai::dateToJulianDay( int year, int month, int day, int &jd ) const 00344 { 00345 return KCalendarSystemGregorianProleptic::dateToJulianDay( year - 543, month, day, jd ); 00346 } 00347
KDE 4.6 API Reference