KDECore
kcalendarsystemhijri.cpp
Go to the documentation of this file.
00001 /* 00002 Copyright (c) 2002-2003 Carlos Moro <cfmoro@correo.uniovi.es> 00003 Copyright (c) 2002-2003 Hans Petter Bieker <bieker@kde.org> 00004 Copyright 2007, 2008, 2009, 2010 John Layt <john@layt.net> 00005 00006 This library is free software; you can redistribute it and/or 00007 modify it under the terms of the GNU Library General Public 00008 License as published by the Free Software Foundation; either 00009 version 2 of the License, or (at your option) any later version. 00010 00011 This library is distributed in the hope that it will be useful, 00012 but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00014 Library General Public License for more details. 00015 00016 You should have received a copy of the GNU Library General Public License 00017 along with this library; see the file COPYING.LIB. If not, write to 00018 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00019 Boston, MA 02110-1301, USA. 00020 */ 00021 00022 #include "kcalendarsystemhijri_p.h" 00023 #include "kcalendarsystemprivate_p.h" 00024 00025 #include <QtCore/QDate> 00026 00027 class KCalendarSystemHijriPrivate : public KCalendarSystemPrivate 00028 { 00029 public: 00030 explicit KCalendarSystemHijriPrivate( KCalendarSystemHijri *q ); 00031 00032 virtual ~KCalendarSystemHijriPrivate(); 00033 00034 // Virtual methods each calendar system must re-implement 00035 virtual KLocale::CalendarSystem calendarSystem() const; 00036 virtual void loadDefaultEraList(); 00037 virtual int monthsInYear( int year ) const; 00038 virtual int daysInMonth( int year, int month ) const; 00039 virtual int daysInYear( int year ) const; 00040 virtual int daysInWeek() const; 00041 virtual bool isLeapYear( int year ) const; 00042 virtual bool hasLeapMonths() const; 00043 virtual bool hasYearZero() const; 00044 virtual int maxDaysInWeek() const; 00045 virtual int maxMonthsInYear() const; 00046 virtual int earliestValidYear() const; 00047 virtual int latestValidYear() const; 00048 }; 00049 00050 // Shared d pointer base class definitions 00051 00052 KCalendarSystemHijriPrivate::KCalendarSystemHijriPrivate( KCalendarSystemHijri *q ) 00053 :KCalendarSystemPrivate( q ) 00054 { 00055 } 00056 00057 KCalendarSystemHijriPrivate::~KCalendarSystemHijriPrivate() 00058 { 00059 } 00060 00061 KLocale::CalendarSystem KCalendarSystemHijriPrivate::calendarSystem() const 00062 { 00063 return KLocale::IslamicCivilCalendar; 00064 } 00065 00066 void KCalendarSystemHijriPrivate::loadDefaultEraList() 00067 { 00068 QString name, shortName, format; 00069 // Islamic Era, Anno Hegirae, "Year of the Hijra". 00070 name = i18nc( "Calendar Era: Hijri Islamic Era, years > 0, LongFormat", "Anno Hegirae" ); 00071 shortName = i18nc( "Calendar Era: Hijri Islamic Era, years > 0, ShortFormat", "AH" ); 00072 format = i18nc( "(kdedt-format) Hijri, AH, full era year format used for %EY, e.g. 2000 AH", "%Ey %EC" ); 00073 addEra( '+', 1, q->epoch(), 1, q->latestValidDate(), name, shortName, format ); 00074 } 00075 00076 int KCalendarSystemHijriPrivate::monthsInYear( int year ) const 00077 { 00078 Q_UNUSED( year ) 00079 return 12; 00080 } 00081 00082 int KCalendarSystemHijriPrivate::daysInMonth( int year, int month ) const 00083 { 00084 if ( month == 12 && isLeapYear( year ) ) { 00085 return 30; 00086 } 00087 00088 if ( month % 2 == 0 ) { // Even number months have 29 days 00089 return 29; 00090 } else { // Odd number months have 30 days 00091 return 30; 00092 } 00093 } 00094 00095 int KCalendarSystemHijriPrivate::daysInYear( int year ) const 00096 { 00097 if ( isLeapYear( year ) ) { 00098 return 355; 00099 } else { 00100 return 354; 00101 } 00102 } 00103 00104 int KCalendarSystemHijriPrivate::daysInWeek() const 00105 { 00106 return 7; 00107 } 00108 00109 bool KCalendarSystemHijriPrivate::isLeapYear( int year ) const 00110 { 00111 // Years 2, 5, 7, 10, 13, 16, 18, 21, 24, 26, 29 of the 30 year cycle 00112 00113 /* 00114 The following C++ code is translated from the Lisp code 00115 in ``Calendrical Calculations'' by Nachum Dershowitz and 00116 Edward M. Reingold, Software---Practice & Experience, 00117 vol. 20, no. 9 (September, 1990), pp. 899--928. 00118 00119 This code is in the public domain, but any use of it 00120 should publically acknowledge its source. 00121 */ 00122 00123 if ( ( ( ( 11 * year ) + 14 ) % 30 ) < 11 ) { 00124 return true; 00125 } else { 00126 return false; 00127 } 00128 00129 // The following variations will be implemented in separate classes in 4.5 00130 // May be cleaner to formally define using a case statement switch on (year % 30) 00131 00132 // Variation used by Bar Habraeus / Graves / Birashk / Some Microsoft products 00133 // Years 2, 5, 7, 10, 13, 15, 18, 21, 24, 26, 29 of the 30 year cycle 00134 // if ( ( ( ( 11 * year ) + 15 ) % 30 ) < 11 ) { 00135 00136 // Variation used by Bohras / Sahifa with epoch 15 July 622 jd = 1948440 00137 // Years 2, 5, 8, 10, 13, 16, 19, 21, 24, 27, 29 of the 30 year cycle 00138 // if ( ( ( ( 11 * year ) + 1 ) % 30 ) < 11 ) { 00139 } 00140 00141 bool KCalendarSystemHijriPrivate::hasLeapMonths() const 00142 { 00143 return false; 00144 } 00145 00146 bool KCalendarSystemHijriPrivate::hasYearZero() const 00147 { 00148 return false; 00149 } 00150 00151 int KCalendarSystemHijriPrivate::maxDaysInWeek() const 00152 { 00153 return 7; 00154 } 00155 00156 int KCalendarSystemHijriPrivate::maxMonthsInYear() const 00157 { 00158 return 12; 00159 } 00160 00161 int KCalendarSystemHijriPrivate::earliestValidYear() const 00162 { 00163 return 1; 00164 } 00165 00166 int KCalendarSystemHijriPrivate::latestValidYear() const 00167 { 00168 return 9999; 00169 } 00170 00171 00172 KCalendarSystemHijri::KCalendarSystemHijri( const KLocale *locale ) 00173 : KCalendarSystem( *new KCalendarSystemHijriPrivate( this ), KSharedConfig::Ptr(), locale ), 00174 dont_use( 0 ) 00175 { 00176 d_ptr->loadConfig( calendarType() ); 00177 } 00178 00179 KCalendarSystemHijri::KCalendarSystemHijri( const KSharedConfig::Ptr config, const KLocale *locale ) 00180 : KCalendarSystem( *new KCalendarSystemHijriPrivate( this ), config, locale ), 00181 dont_use( 0 ) 00182 { 00183 d_ptr->loadConfig( calendarType() ); 00184 } 00185 00186 KCalendarSystemHijri::KCalendarSystemHijri( KCalendarSystemHijriPrivate &dd, 00187 const KSharedConfig::Ptr config, const KLocale *locale ) 00188 : KCalendarSystem( dd, config, locale ), 00189 dont_use( 0 ) 00190 { 00191 d_ptr->loadConfig( calendarType() ); 00192 } 00193 00194 KCalendarSystemHijri::~KCalendarSystemHijri() 00195 { 00196 delete dont_use; 00197 } 00198 00199 QString KCalendarSystemHijri::calendarType() const 00200 { 00201 return QLatin1String( "hijri" ); 00202 } 00203 00204 QDate KCalendarSystemHijri::epoch() const 00205 { 00206 // 16 July 622 in the Julian calendar 00207 return QDate::fromJulianDay( 1948440 ); 00208 } 00209 00210 QDate KCalendarSystemHijri::earliestValidDate() const 00211 { 00212 return epoch(); 00213 } 00214 00215 QDate KCalendarSystemHijri::latestValidDate() const 00216 { 00217 // Set to last day of year 9999 00218 // Last day of Hijri year 9999 is 9999-12-29 00219 return QDate::fromJulianDay( 5491751 ); 00220 } 00221 00222 bool KCalendarSystemHijri::isValid( int year, int month, int day ) const 00223 { 00224 return KCalendarSystem::isValid( year, month, day ); 00225 } 00226 00227 bool KCalendarSystemHijri::isValid( const QDate &date ) const 00228 { 00229 return KCalendarSystem::isValid( date ); 00230 } 00231 00232 bool KCalendarSystemHijri::setDate( QDate &date, int year, int month, int day ) const 00233 { 00234 return KCalendarSystem::setDate( date, year, month, day ); 00235 } 00236 00237 // Deprecated 00238 bool KCalendarSystemHijri::setYMD( QDate &date, int year, int month, int day ) const 00239 { 00240 return KCalendarSystem::setYMD( date, year, month, day ); 00241 } 00242 00243 int KCalendarSystemHijri::year( const QDate &date ) const 00244 { 00245 return KCalendarSystem::year( date ); 00246 } 00247 00248 int KCalendarSystemHijri::month( const QDate &date ) const 00249 { 00250 return KCalendarSystem::month( date ); 00251 } 00252 00253 int KCalendarSystemHijri::day( const QDate &date ) const 00254 { 00255 return KCalendarSystem::day( date ); 00256 } 00257 00258 QDate KCalendarSystemHijri::addYears( const QDate &date, int nyears ) const 00259 { 00260 return KCalendarSystem::addYears( date, nyears ); 00261 } 00262 00263 QDate KCalendarSystemHijri::addMonths( const QDate &date, int nmonths ) const 00264 { 00265 return KCalendarSystem::addMonths( date, nmonths ); 00266 } 00267 00268 QDate KCalendarSystemHijri::addDays( const QDate &date, int ndays ) const 00269 { 00270 return KCalendarSystem::addDays( date, ndays ); 00271 } 00272 00273 int KCalendarSystemHijri::monthsInYear( const QDate &date ) const 00274 { 00275 return KCalendarSystem::monthsInYear( date ); 00276 } 00277 00278 int KCalendarSystemHijri::weeksInYear( const QDate &date ) const 00279 { 00280 return KCalendarSystem::weeksInYear( date ); 00281 } 00282 00283 int KCalendarSystemHijri::weeksInYear( int year ) const 00284 { 00285 return KCalendarSystem::weeksInYear( year ); 00286 } 00287 00288 int KCalendarSystemHijri::daysInYear( const QDate &date ) const 00289 { 00290 return KCalendarSystem::daysInYear( date ); 00291 } 00292 00293 int KCalendarSystemHijri::daysInMonth( const QDate &date ) const 00294 { 00295 return KCalendarSystem::daysInMonth( date ); 00296 } 00297 00298 int KCalendarSystemHijri::daysInWeek( const QDate &date ) const 00299 { 00300 return KCalendarSystem::daysInWeek( date ); 00301 } 00302 00303 int KCalendarSystemHijri::dayOfYear( const QDate &date ) const 00304 { 00305 return KCalendarSystem::dayOfYear( date ); 00306 } 00307 00308 int KCalendarSystemHijri::dayOfWeek( const QDate &date ) const 00309 { 00310 return KCalendarSystem::dayOfWeek( date ); 00311 } 00312 00313 int KCalendarSystemHijri::weekNumber( const QDate &date, int *yearNum ) const 00314 { 00315 return KCalendarSystem::weekNumber( date, yearNum ); 00316 } 00317 00318 bool KCalendarSystemHijri::isLeapYear( int year ) const 00319 { 00320 return KCalendarSystem::isLeapYear( year ); 00321 } 00322 00323 bool KCalendarSystemHijri::isLeapYear( const QDate &date ) const 00324 { 00325 return KCalendarSystem::isLeapYear( date ); 00326 } 00327 00328 QString KCalendarSystemHijri::monthName( int month, int year, MonthNameFormat format ) const 00329 { 00330 Q_UNUSED( year ); 00331 00332 if ( format == ShortNamePossessive ) { 00333 switch ( month ) { 00334 case 1: 00335 return ki18n( "of Muharram" ).toString( locale() ); 00336 case 2: 00337 return ki18n( "of Safar" ).toString( locale() ); 00338 case 3: 00339 return ki18n( "of R. Awal" ).toString( locale() ); 00340 case 4: 00341 return ki18n( "of R. Thaani" ).toString( locale() ); 00342 case 5: 00343 return ki18n( "of J. Awal" ).toString( locale() ); 00344 case 6: 00345 return ki18n( "of J. Thaani" ).toString( locale() ); 00346 case 7: 00347 return ki18n( "of Rajab" ).toString( locale() ); 00348 case 8: 00349 return ki18n( "of Sha`ban" ).toString( locale() ); 00350 case 9: 00351 return ki18n( "of Ramadan" ).toString( locale() ); 00352 case 10: 00353 return ki18n( "of Shawwal" ).toString( locale() ); 00354 case 11: 00355 return ki18n( "of Qi`dah" ).toString( locale() ); 00356 case 12: 00357 return ki18n( "of Hijjah" ).toString( locale() ); 00358 default: 00359 return QString(); 00360 } 00361 } 00362 00363 if ( format == LongNamePossessive ) { 00364 switch ( month ) { 00365 case 1: 00366 return ki18n( "of Muharram" ).toString( locale() ); 00367 case 2: 00368 return ki18n( "of Safar" ).toString( locale() ); 00369 case 3: 00370 return ki18n( "of Rabi` al-Awal" ).toString( locale() ); 00371 case 4: 00372 return ki18n( "of Rabi` al-Thaani" ).toString( locale() ); 00373 case 5: 00374 return ki18n( "of Jumaada al-Awal" ).toString( locale() ); 00375 case 6: 00376 return ki18n( "of Jumaada al-Thaani" ).toString( locale() ); 00377 case 7: 00378 return ki18n( "of Rajab" ).toString( locale() ); 00379 case 8: 00380 return ki18n( "of Sha`ban" ).toString( locale() ); 00381 case 9: 00382 return ki18n( "of Ramadan" ).toString( locale() ); 00383 case 10: 00384 return ki18n( "of Shawwal" ).toString( locale() ); 00385 case 11: 00386 return ki18n( "of Thu al-Qi`dah" ).toString( locale() ); 00387 case 12: 00388 return ki18n( "of Thu al-Hijjah" ).toString( locale() ); 00389 default: 00390 return QString(); 00391 } 00392 } 00393 00394 if ( format == ShortName ) { 00395 switch ( month ) { 00396 case 1: 00397 return ki18n( "Muharram" ).toString( locale() ); 00398 case 2: 00399 return ki18n( "Safar" ).toString( locale() ); 00400 case 3: 00401 return ki18n( "R. Awal" ).toString( locale() ); 00402 case 4: 00403 return ki18n( "R. Thaani" ).toString( locale() ); 00404 case 5: 00405 return ki18n( "J. Awal" ).toString( locale() ); 00406 case 6: 00407 return ki18n( "J. Thaani" ).toString( locale() ); 00408 case 7: 00409 return ki18n( "Rajab" ).toString( locale() ); 00410 case 8: 00411 return ki18n( "Sha`ban" ).toString( locale() ); 00412 case 9: 00413 return ki18n( "Ramadan" ).toString( locale() ); 00414 case 10: 00415 return ki18n( "Shawwal" ).toString( locale() ); 00416 case 11: 00417 return ki18n( "Qi`dah" ).toString( locale() ); 00418 case 12: 00419 return ki18n( "Hijjah" ).toString( locale() ); 00420 default: 00421 return QString(); 00422 } 00423 } 00424 00425 // LongName 00426 switch ( month ) { 00427 case 1: 00428 return ki18n( "Muharram" ).toString( locale() ); 00429 case 2: 00430 return ki18n( "Safar" ).toString( locale() ); 00431 case 3: 00432 return ki18n( "Rabi` al-Awal" ).toString( locale() ); 00433 case 4: 00434 return ki18n( "Rabi` al-Thaani" ).toString( locale() ); 00435 case 5: 00436 return ki18n( "Jumaada al-Awal" ).toString( locale() ); 00437 case 6: 00438 return ki18n( "Jumaada al-Thaani" ).toString( locale() ); 00439 case 7: 00440 return ki18n( "Rajab" ).toString( locale() ); 00441 case 8: 00442 return ki18n( "Sha`ban" ).toString( locale() ); 00443 case 9: 00444 return ki18n( "Ramadan" ).toString( locale() ); 00445 case 10: 00446 return ki18n( "Shawwal" ).toString( locale() ); 00447 case 11: 00448 return ki18n( "Thu al-Qi`dah" ).toString( locale() ); 00449 case 12: 00450 return ki18n( "Thu al-Hijjah" ).toString( locale() ); 00451 default: 00452 return QString(); 00453 } 00454 } 00455 00456 QString KCalendarSystemHijri::monthName( const QDate &date, MonthNameFormat format ) const 00457 { 00458 return monthName( month( date ), year( date ), format ); 00459 } 00460 00461 QString KCalendarSystemHijri::weekDayName( int weekDay, WeekDayNameFormat format ) const 00462 { 00463 if ( format == ShortDayName ) { 00464 switch ( weekDay ) { 00465 case 1: 00466 return ki18n( "Ith" ).toString( locale() ); 00467 case 2: 00468 return ki18n( "Thl" ).toString( locale() ); 00469 case 3: 00470 return ki18n( "Arb" ).toString( locale() ); 00471 case 4: 00472 return ki18n( "Kha" ).toString( locale() ); 00473 case 5: 00474 return ki18n( "Jum" ).toString( locale() ); 00475 case 6: 00476 return ki18n( "Sab" ).toString( locale() ); 00477 case 7: 00478 return ki18n( "Ahd" ).toString( locale() ); 00479 default: 00480 return QString(); 00481 } 00482 } 00483 00484 // Default to LongDayName format 00485 switch ( weekDay ) { 00486 case 1: 00487 return ki18n( "Yaum al-Ithnain" ).toString( locale() ); 00488 case 2: 00489 return ki18n( "Yau al-Thulatha" ).toString( locale() ); 00490 case 3: 00491 return ki18n( "Yaum al-Arbi'a" ).toString( locale() ); 00492 case 4: 00493 return ki18n( "Yaum al-Khamees" ).toString( locale() ); 00494 case 5: 00495 return ki18n( "Yaum al-Jumma" ).toString( locale() ); 00496 case 6: 00497 return ki18n( "Yaum al-Sabt" ).toString( locale() ); 00498 case 7: 00499 return ki18n( "Yaum al-Ahad" ).toString( locale() ); 00500 default: 00501 return QString(); 00502 } 00503 } 00504 00505 QString KCalendarSystemHijri::weekDayName( const QDate &date, WeekDayNameFormat format ) const 00506 { 00507 return weekDayName( dayOfWeek( date ), format ); 00508 } 00509 00510 QString KCalendarSystemHijri::yearString( const QDate &pDate, StringFormat format ) const 00511 { 00512 return KCalendarSystem::yearString( pDate, format ); 00513 } 00514 00515 QString KCalendarSystemHijri::monthString( const QDate &pDate, StringFormat format ) const 00516 { 00517 return KCalendarSystem::monthString( pDate, format ); 00518 } 00519 00520 QString KCalendarSystemHijri::dayString( const QDate &pDate, StringFormat format ) const 00521 { 00522 return KCalendarSystem::dayString( pDate, format ); 00523 } 00524 00525 int KCalendarSystemHijri::yearStringToInteger( const QString &sNum, int &iLength ) const 00526 { 00527 return KCalendarSystem::yearStringToInteger( sNum, iLength ); 00528 } 00529 00530 int KCalendarSystemHijri::monthStringToInteger( const QString &sNum, int &iLength ) const 00531 { 00532 return KCalendarSystem::monthStringToInteger( sNum, iLength ); 00533 } 00534 00535 int KCalendarSystemHijri::dayStringToInteger( const QString &sNum, int &iLength ) const 00536 { 00537 return KCalendarSystem::dayStringToInteger( sNum, iLength ); 00538 } 00539 00540 QString KCalendarSystemHijri::formatDate( const QDate &date, KLocale::DateFormat format ) const 00541 { 00542 return KCalendarSystem::formatDate( date, format ); 00543 } 00544 00545 QDate KCalendarSystemHijri::readDate( const QString &str, bool *ok ) const 00546 { 00547 return KCalendarSystem::readDate( str, ok ); 00548 } 00549 00550 QDate KCalendarSystemHijri::readDate( const QString &intstr, const QString &fmt, bool *ok ) const 00551 { 00552 return KCalendarSystem::readDate( intstr, fmt, ok ); 00553 } 00554 00555 QDate KCalendarSystemHijri::readDate( const QString &str, KLocale::ReadDateFlags flags, bool *ok ) const 00556 { 00557 return KCalendarSystem::readDate( str, flags, ok ); 00558 } 00559 00560 int KCalendarSystemHijri::weekStartDay() const 00561 { 00562 return KCalendarSystem::weekStartDay(); 00563 } 00564 00565 int KCalendarSystemHijri::weekDayOfPray() const 00566 { 00567 return 5; // Friday 00568 } 00569 00570 bool KCalendarSystemHijri::isLunar() const 00571 { 00572 return true; 00573 } 00574 00575 bool KCalendarSystemHijri::isLunisolar() const 00576 { 00577 return false; 00578 } 00579 00580 bool KCalendarSystemHijri::isSolar() const 00581 { 00582 return false; 00583 } 00584 00585 bool KCalendarSystemHijri::isProleptic() const 00586 { 00587 return false; 00588 } 00589 00590 bool KCalendarSystemHijri::julianDayToDate( int jd, int &year, int &month, int &day ) const 00591 { 00592 Q_D( const KCalendarSystemHijri ); 00593 00594 /* 00595 The following C++ code is translated from the Lisp code 00596 in ``Calendrical Calculations'' by Nachum Dershowitz and 00597 Edward M. Reingold, Software---Practice & Experience, 00598 vol. 20, no. 9 (September, 1990), pp. 899--928. 00599 00600 This code is in the public domain, but any use of it 00601 should publically acknowledge its source. 00602 */ 00603 00604 // Search forward year by year from approximate year 00605 year = ( jd - epoch().toJulianDay() ) / 355; 00606 int testJd; 00607 dateToJulianDay( year, 12, d->daysInMonth( year, 12 ), testJd ); 00608 while ( jd > testJd ) { 00609 year++; 00610 dateToJulianDay( year, 12, d->daysInMonth( year, 12 ), testJd ); 00611 } 00612 00613 // Search forward month by month from Muharram 00614 month = 1; 00615 dateToJulianDay( year, month, d->daysInMonth( year, month ), testJd ); 00616 while ( jd > testJd ) { 00617 month++; 00618 dateToJulianDay( year, month, d->daysInMonth( year, month ), testJd ); 00619 } 00620 00621 dateToJulianDay( year, month, 1, testJd ); 00622 day = jd - testJd + 1; 00623 00624 return true; 00625 00626 // Alternative implementations 00627 00628 // More recent editions of "Calendrical Calculations" by Dershowitz & Reingold have a more 00629 // efficient direct calculation without recusrion, but this cannot be used due to licensing 00630 00631 /* 00632 Formula from "Explanatory Supplement to the Astronomical Almanac" 2006, derived from Fliegel & Van Flandern 1968 00633 int L = jd - epoch().toJulianDay() + 10632; 00634 int N = ( L - 1 ) / 10631; 00635 L = L - 10631 * N + 354; 00636 int J = ( ( 10985 - L ) / 5316 ) x ( ( 50* L ) / 17719 ) + ( L / 5670 ) * ( ( 43 * L ) / 15238 ); 00637 L = L - ( ( 30 - J ) / 15 ) * ( ( 17719 * J ) / 50 ) - ( J / 16 ) * ( ( 15238 * J ) / 43 ) + 29; 00638 year = ( 30 * N ) + J - 30; 00639 month = ( 24 * L ) / 709; 00640 day = L - ( ( 709 * month ) / 24 ); 00641 */ 00642 00643 /* 00644 Formula from Fourmilab website 00645 jd = Math.floor(jd) + 0.5; 00646 year = Math.floor(((30 * (jd - epoch().toJulianDay())) + 10646) / 10631); 00647 month = qMin(12, Math.ceil((jd - (29 + islamic_to_jd(year, 1, 1))) / 29.5) + 1); 00648 day = (jd - islamic_to_jd(year, month, 1)) + 1; 00649 */ 00650 } 00651 00652 bool KCalendarSystemHijri::dateToJulianDay( int year, int month, int day, int &jd ) const 00653 { 00654 /* 00655 The following C++ code is translated from the Lisp code 00656 in ``Calendrical Calculations'' by Nachum Dershowitz and 00657 Edward M. Reingold, Software---Practice & Experience, 00658 vol. 20, no. 9 (September, 1990), pp. 899--928. 00659 00660 This code is in the public domain, but any use of it 00661 should publically acknowledge its source. 00662 */ 00663 00664 jd = epoch().toJulianDay() - 1 + // days before start of calendar 00665 ( year - 1 ) * 354 + // non-leap days in prior years 00666 ( 3 + ( 11 * year ) ) / 30 + // leap days in prior years 00667 29 * ( month - 1 ) + // days so far... 00668 month / 2 + // ...this year 00669 day; // days so far this month 00670 00671 return true; 00672 00673 // Alternative implementations 00674 00675 /* 00676 Formula from "Explanatory Supplement to the Astronomical Almanac" 2006, derived from Fliegel & Van Flandern 1968 00677 jd = ( 3 + ( 11 * year ) ) / 30 + 354 * year + 30 * month - ( month - 1 ) / 2 + day + epoch().toJulianDay() - 385; 00678 */ 00679 }
KDE 4.6 API Reference