00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include "kcalendarsystemgregorian.h"
00025
00026 #include "kdebug.h"
00027 #include "klocale.h"
00028
00029 #include <QtCore/QDate>
00030 #include <QtCore/QCharRef>
00031
00032 KCalendarSystemGregorian::KCalendarSystemGregorian( const KLocale * locale )
00033 : KCalendarSystem( locale ), d( 0 )
00034 {
00035 }
00036
00037 KCalendarSystemGregorian::~KCalendarSystemGregorian()
00038 {
00039 }
00040
00041 QString KCalendarSystemGregorian::calendarType() const
00042 {
00043 return QLatin1String( "gregorian" );
00044 }
00045
00046 QDate KCalendarSystemGregorian::epoch() const
00047 {
00048 return QDate::fromJulianDay( 1721426 );
00049 }
00050
00051 QDate KCalendarSystemGregorian::earliestValidDate() const
00052 {
00053 return QDate::fromJulianDay( 1 );
00054 }
00055
00056 QDate KCalendarSystemGregorian::latestValidDate() const
00057 {
00058
00059
00060
00061 return QDate::fromJulianDay( 5373484 );
00062 }
00063
00064 bool KCalendarSystemGregorian::isValid( int year, int month, int day ) const
00065 {
00066
00067 if ( year <= 9999 ) {
00068 return QDate::isValid( year, month, day );
00069 }
00070
00071 return false;
00072 }
00073
00074 bool KCalendarSystemGregorian::isValid( const QDate &date ) const
00075 {
00076 return KCalendarSystem::isValid( date );
00077 }
00078
00079 bool KCalendarSystemGregorian::setDate( QDate &date, int year, int month, int day ) const
00080 {
00081 return KCalendarSystem::setDate( date, year, month, day );
00082 }
00083
00084
00085 bool KCalendarSystemGregorian::setYMD( QDate &date, int y, int m, int d ) const
00086 {
00087 return KCalendarSystem::setDate( date, y, m, d );
00088 }
00089
00090 int KCalendarSystemGregorian::year( const QDate &date ) const
00091 {
00092 return KCalendarSystem::year( date );
00093 }
00094
00095 int KCalendarSystemGregorian::month( const QDate &date ) const
00096 {
00097 return KCalendarSystem::month( date );
00098 }
00099
00100 int KCalendarSystemGregorian::day( const QDate &date ) const
00101 {
00102 return KCalendarSystem::day( date );
00103 }
00104
00105 QDate KCalendarSystemGregorian::addYears( const QDate &date, int nyears ) const
00106 {
00107 return KCalendarSystem::addYears( date, nyears );
00108 }
00109
00110 QDate KCalendarSystemGregorian::addMonths( const QDate &date, int nmonths ) const
00111 {
00112 return KCalendarSystem::addMonths( date, nmonths );
00113 }
00114
00115 QDate KCalendarSystemGregorian::addDays( const QDate &date, int ndays ) const
00116 {
00117 return KCalendarSystem::addDays( date, ndays );
00118 }
00119
00120 int KCalendarSystemGregorian::monthsInYear( const QDate &date ) const
00121 {
00122 Q_UNUSED( date )
00123 return 12;
00124 }
00125
00126 int KCalendarSystemGregorian::weeksInYear( const QDate &date ) const
00127 {
00128 return KCalendarSystem::weeksInYear( date );
00129 }
00130
00131 int KCalendarSystemGregorian::weeksInYear( int year ) const
00132 {
00133 return KCalendarSystem::weeksInYear( year );
00134 }
00135
00136 int KCalendarSystemGregorian::daysInYear( const QDate &date ) const
00137 {
00138 return KCalendarSystem::daysInYear( date );
00139 }
00140
00141 int KCalendarSystemGregorian::daysInMonth( const QDate &date ) const
00142 {
00143 return KCalendarSystem::daysInMonth( date );
00144 }
00145
00146 int KCalendarSystemGregorian::daysInWeek( const QDate &date ) const
00147 {
00148 Q_UNUSED( date );
00149 return 7;
00150 }
00151
00152 int KCalendarSystemGregorian::dayOfYear( const QDate &date ) const
00153 {
00154
00155
00156
00157
00158 if ( year( date ) == -4713 ) {
00159 QDate secondDayOfYear;
00160 if ( setDate( secondDayOfYear, -4713, 1, 2 ) ) {
00161 return ( date.toJulianDay() - secondDayOfYear.toJulianDay() + 2 );
00162 }
00163 } else {
00164 return KCalendarSystem::dayOfYear( date );
00165 }
00166
00167 return -1;
00168 }
00169
00170 int KCalendarSystemGregorian::dayOfWeek( const QDate &date ) const
00171 {
00172 return KCalendarSystem::dayOfWeek( date );
00173 }
00174
00175 int KCalendarSystemGregorian::weekNumber( const QDate &date, int * yearNum ) const
00176 {
00177 return KCalendarSystem::weekNumber( date, yearNum );
00178 }
00179
00180 bool KCalendarSystemGregorian::isLeapYear( int year ) const
00181 {
00182
00183 return QDate::isLeapYear( year );
00184 }
00185
00186 bool KCalendarSystemGregorian::isLeapYear( const QDate &date ) const
00187 {
00188 return KCalendarSystem::isLeapYear( date );
00189 }
00190
00191 QString KCalendarSystemGregorian::monthName( int month, int year, MonthNameFormat format ) const
00192 {
00193 Q_UNUSED( year );
00194
00195 if ( format == ShortNamePossessive ) {
00196 switch ( month ) {
00197 case 1:
00198 return ki18nc( "of January", "of Jan" ).toString( locale() );
00199 case 2:
00200 return ki18nc( "of February", "of Feb" ).toString( locale() );
00201 case 3:
00202 return ki18nc( "of March", "of Mar" ).toString( locale() );
00203 case 4:
00204 return ki18nc( "of April", "of Apr" ).toString( locale() );
00205 case 5:
00206 return ki18nc( "of May short", "of May" ).toString( locale() );
00207 case 6:
00208 return ki18nc( "of June", "of Jun" ).toString( locale() );
00209 case 7:
00210 return ki18nc( "of July", "of Jul" ).toString( locale() );
00211 case 8:
00212 return ki18nc( "of August", "of Aug" ).toString( locale() );
00213 case 9:
00214 return ki18nc( "of September", "of Sep" ).toString( locale() );
00215 case 10:
00216 return ki18nc( "of October", "of Oct" ).toString( locale() );
00217 case 11:
00218 return ki18nc( "of November", "of Nov" ).toString( locale() );
00219 case 12:
00220 return ki18nc( "of December", "of Dec" ).toString( locale() );
00221 default:
00222 return QString();
00223 }
00224 }
00225
00226 if ( format == LongNamePossessive ) {
00227 switch ( month ) {
00228 case 1:
00229 return ki18n( "of January" ).toString( locale() );
00230 case 2:
00231 return ki18n( "of February" ).toString( locale() );
00232 case 3:
00233 return ki18n( "of March" ).toString( locale() );
00234 case 4:
00235 return ki18n( "of April" ).toString( locale() );
00236 case 5:
00237 return ki18nc( "of May long", "of May" ).toString( locale() );
00238 case 6:
00239 return ki18n( "of June" ).toString( locale() );
00240 case 7:
00241 return ki18n( "of July" ).toString( locale() );
00242 case 8:
00243 return ki18n( "of August" ).toString( locale() );
00244 case 9:
00245 return ki18n( "of September" ).toString( locale() );
00246 case 10:
00247 return ki18n( "of October" ).toString( locale() );
00248 case 11:
00249 return ki18n( "of November" ).toString( locale() );
00250 case 12:
00251 return ki18n( "of December" ).toString( locale() );
00252 default:
00253 return QString();
00254 }
00255 }
00256
00257 if ( format == ShortName ) {
00258 switch ( month ) {
00259 case 1:
00260 return ki18nc( "January", "Jan" ).toString( locale() );
00261 case 2:
00262 return ki18nc( "February", "Feb" ).toString( locale() );
00263 case 3:
00264 return ki18nc( "March", "Mar" ).toString( locale() );
00265 case 4:
00266 return ki18nc( "April", "Apr" ).toString( locale() );
00267 case 5:
00268 return ki18nc( "May short", "May" ).toString( locale() );
00269 case 6:
00270 return ki18nc( "June", "Jun" ).toString( locale() );
00271 case 7:
00272 return ki18nc( "July", "Jul" ).toString( locale() );
00273 case 8:
00274 return ki18nc( "August", "Aug" ).toString( locale() );
00275 case 9:
00276 return ki18nc( "September", "Sep" ).toString( locale() );
00277 case 10:
00278 return ki18nc( "October", "Oct" ).toString( locale() );
00279 case 11:
00280 return ki18nc( "November", "Nov" ).toString( locale() );
00281 case 12:
00282 return ki18nc( "December", "Dec" ).toString( locale() );
00283 default:
00284 return QString();
00285 }
00286 }
00287
00288
00289 switch ( month ) {
00290 case 1:
00291 return ki18n( "January" ).toString( locale() );
00292 case 2:
00293 return ki18n( "February" ).toString( locale() );
00294 case 3:
00295 return ki18nc( "March long", "March" ).toString( locale() );
00296 case 4:
00297 return ki18n( "April" ).toString( locale() );
00298 case 5:
00299 return ki18nc( "May long", "May" ).toString( locale() );
00300 case 6:
00301 return ki18n( "June" ).toString( locale() );
00302 case 7:
00303 return ki18n( "July" ).toString( locale() );
00304 case 8:
00305 return ki18nc( "August long", "August" ).toString( locale() );
00306 case 9:
00307 return ki18n( "September" ).toString( locale() );
00308 case 10:
00309 return ki18n( "October" ).toString( locale() );
00310 case 11:
00311 return ki18n( "November" ).toString( locale() );
00312 case 12:
00313 return ki18n( "December" ).toString( locale() );
00314 default:
00315 return QString();
00316 }
00317 }
00318
00319 QString KCalendarSystemGregorian::monthName( const QDate &date, MonthNameFormat format ) const
00320 {
00321 return KCalendarSystem::monthName( date, format );
00322 }
00323
00324
00325 QString KCalendarSystemGregorian::weekDayName( int weekDay, WeekDayNameFormat format ) const
00326 {
00327 if ( format == ShortDayName ) {
00328 switch ( weekDay ) {
00329 case 1: return ki18nc( "Monday", "Mon" ).toString( locale() );
00330 case 2: return ki18nc( "Tuesday", "Tue" ).toString( locale() );
00331 case 3: return ki18nc( "Wednesday", "Wed" ).toString( locale() );
00332 case 4: return ki18nc( "Thursday", "Thu" ).toString( locale() );
00333 case 5: return ki18nc( "Friday", "Fri" ).toString( locale() );
00334 case 6: return ki18nc( "Saturday", "Sat" ).toString( locale() );
00335 case 7: return ki18nc( "Sunday", "Sun" ).toString( locale() );
00336 default: return QString();
00337 }
00338 }
00339
00340 switch ( weekDay ) {
00341 case 1: return ki18n( "Monday" ).toString( locale() );
00342 case 2: return ki18n( "Tuesday" ).toString( locale() );
00343 case 3: return ki18n( "Wednesday" ).toString( locale() );
00344 case 4: return ki18n( "Thursday" ).toString( locale() );
00345 case 5: return ki18n( "Friday" ).toString( locale() );
00346 case 6: return ki18n( "Saturday" ).toString( locale() );
00347 case 7: return ki18n( "Sunday" ).toString( locale() );
00348 default: return QString();
00349 }
00350 }
00351
00352 QString KCalendarSystemGregorian::weekDayName( const QDate &date, WeekDayNameFormat format ) const
00353 {
00354 return KCalendarSystem::weekDayName( date, format );
00355 }
00356
00357 QString KCalendarSystemGregorian::yearString( const QDate &pDate, StringFormat format ) const
00358 {
00359 return KCalendarSystem::yearString( pDate, format );
00360 }
00361
00362 QString KCalendarSystemGregorian::monthString( const QDate &pDate, StringFormat format ) const
00363 {
00364 return KCalendarSystem::monthString( pDate, format );
00365 }
00366
00367 QString KCalendarSystemGregorian::dayString( const QDate &pDate, StringFormat format ) const
00368 {
00369 return KCalendarSystem::dayString( pDate, format );
00370 }
00371
00372 int KCalendarSystemGregorian::yearStringToInteger( const QString &sNum, int &iLength ) const
00373 {
00374 return KCalendarSystem::yearStringToInteger( sNum, iLength );
00375 }
00376
00377 int KCalendarSystemGregorian::monthStringToInteger( const QString &sNum, int &iLength ) const
00378 {
00379 return KCalendarSystem::monthStringToInteger( sNum, iLength );
00380 }
00381
00382 int KCalendarSystemGregorian::dayStringToInteger( const QString &sNum, int &iLength ) const
00383 {
00384 return KCalendarSystem::dayStringToInteger( sNum, iLength );
00385 }
00386
00387 QString KCalendarSystemGregorian::formatDate( const QDate &date, KLocale::DateFormat format ) const
00388 {
00389 return KCalendarSystem::formatDate( date, format );
00390 }
00391
00392 QDate KCalendarSystemGregorian::readDate( const QString &str, bool *ok ) const
00393 {
00394 return KCalendarSystem::readDate( str, ok );
00395 }
00396
00397 QDate KCalendarSystemGregorian::readDate( const QString &intstr, const QString &fmt, bool *ok ) const
00398 {
00399 return KCalendarSystem::readDate( intstr, fmt, ok );
00400 }
00401
00402 QDate KCalendarSystemGregorian::readDate( const QString &str, KLocale::ReadDateFlags flags, bool *ok ) const
00403 {
00404 return KCalendarSystem::readDate( str, flags, ok );
00405 }
00406
00407 int KCalendarSystemGregorian::weekStartDay() const
00408 {
00409 return KCalendarSystem::weekStartDay();
00410 }
00411
00412 int KCalendarSystemGregorian::weekDayOfPray() const
00413 {
00414 return 7;
00415 }
00416
00417 bool KCalendarSystemGregorian::isLunar() const
00418 {
00419 return false;
00420 }
00421
00422 bool KCalendarSystemGregorian::isLunisolar() const
00423 {
00424 return false;
00425 }
00426
00427 bool KCalendarSystemGregorian::isSolar() const
00428 {
00429 return true;
00430 }
00431
00432 bool KCalendarSystemGregorian::isProleptic() const
00433 {
00434 return false;
00435 }
00436
00437 bool KCalendarSystemGregorian::julianDayToDate( int jd, int &year, int &month, int &day ) const
00438 {
00439 QDate date = QDate::fromJulianDay( jd );
00440
00441 if ( date.isValid() ) {
00442 year = date.year();
00443 month = date.month();
00444 day = date.day();
00445 }
00446
00447 return date.isValid();
00448 }
00449
00450 bool KCalendarSystemGregorian::dateToJulianDay( int year, int month, int day, int &jd ) const
00451 {
00452 QDate date;
00453
00454 if ( date.setDate( year, month, day ) ) {
00455 jd = date.toJulianDay();
00456 return true;
00457 }
00458
00459 return false;
00460 }