KDECore
kcalendarsystemislamiccivil.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 "kcalendarsystemislamiccivil_p.h" 00023 #include "kcalendarsystemprivate_p.h" 00024 00025 #include <QtCore/QDate> 00026 00027 class KCalendarSystemIslamicCivilPrivate : public KCalendarSystemPrivate 00028 { 00029 public: 00030 explicit KCalendarSystemIslamicCivilPrivate(KCalendarSystemIslamicCivil *q); 00031 00032 virtual ~KCalendarSystemIslamicCivilPrivate(); 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 virtual QString monthName(int month, int year, KLocale::DateTimeComponentFormat format, bool possessive) const; 00049 virtual QString weekDayName(int weekDay, KLocale::DateTimeComponentFormat format) const; 00050 }; 00051 00052 // Shared d pointer base class definitions 00053 00054 KCalendarSystemIslamicCivilPrivate::KCalendarSystemIslamicCivilPrivate(KCalendarSystemIslamicCivil *q) 00055 : KCalendarSystemPrivate(q) 00056 { 00057 } 00058 00059 KCalendarSystemIslamicCivilPrivate::~KCalendarSystemIslamicCivilPrivate() 00060 { 00061 } 00062 00063 KLocale::CalendarSystem KCalendarSystemIslamicCivilPrivate::calendarSystem() const 00064 { 00065 return KLocale::IslamicCivilCalendar; 00066 } 00067 00068 void KCalendarSystemIslamicCivilPrivate::loadDefaultEraList() 00069 { 00070 QString name, shortName, format; 00071 // Islamic Era, Anno Hegirae, "Year of the Hijra". 00072 name = i18nc("Calendar Era: Hijri Islamic Era, years > 0, LongFormat", "Anno Hegirae"); 00073 shortName = i18nc("Calendar Era: Hijri Islamic Era, years > 0, ShortFormat", "AH"); 00074 format = i18nc("(kdedt-format) Hijri, AH, full era year format used for %EY, e.g. 2000 AH", "%Ey %EC"); 00075 addEra('+', 1, q->epoch(), 1, q->latestValidDate(), name, shortName, format); 00076 } 00077 00078 int KCalendarSystemIslamicCivilPrivate::monthsInYear(int year) const 00079 { 00080 Q_UNUSED(year) 00081 return 12; 00082 } 00083 00084 int KCalendarSystemIslamicCivilPrivate::daysInMonth(int year, int month) const 00085 { 00086 if (month == 12 && isLeapYear(year)) { 00087 return 30; 00088 } 00089 00090 if (month % 2 == 0) { // Even number months have 29 days 00091 return 29; 00092 } else { // Odd number months have 30 days 00093 return 30; 00094 } 00095 } 00096 00097 int KCalendarSystemIslamicCivilPrivate::daysInYear(int year) const 00098 { 00099 if (isLeapYear(year)) { 00100 return 355; 00101 } else { 00102 return 354; 00103 } 00104 } 00105 00106 int KCalendarSystemIslamicCivilPrivate::daysInWeek() const 00107 { 00108 return 7; 00109 } 00110 00111 bool KCalendarSystemIslamicCivilPrivate::isLeapYear(int year) const 00112 { 00113 // Years 2, 5, 7, 10, 13, 16, 18, 21, 24, 26, 29 of the 30 year cycle 00114 00115 /* 00116 The following C++ code is translated from the Lisp code 00117 in ``Calendrical Calculations'' by Nachum Dershowitz and 00118 Edward M. Reingold, Software---Practice & Experience, 00119 vol. 20, no. 9 (September, 1990), pp. 899--928. 00120 00121 This code is in the public domain, but any use of it 00122 should publically acknowledge its source. 00123 */ 00124 00125 if ((((11 * year) + 14) % 30) < 11) { 00126 return true; 00127 } else { 00128 return false; 00129 } 00130 00131 // The following variations will be implemented in separate classes in 4.5 00132 // May be cleaner to formally define using a case statement switch on (year % 30) 00133 00134 // Variation used by Bar Habraeus / Graves / Birashk / Some Microsoft products 00135 // Years 2, 5, 7, 10, 13, 15, 18, 21, 24, 26, 29 of the 30 year cycle 00136 // if ( ( ( ( 11 * year ) + 15 ) % 30 ) < 11 ) { 00137 00138 // Variation used by Bohras / Sahifa with epoch 15 July 622 jd = 1948440 00139 // Years 2, 5, 8, 10, 13, 16, 19, 21, 24, 27, 29 of the 30 year cycle 00140 // if ( ( ( ( 11 * year ) + 1 ) % 30 ) < 11 ) { 00141 } 00142 00143 bool KCalendarSystemIslamicCivilPrivate::hasLeapMonths() const 00144 { 00145 return false; 00146 } 00147 00148 bool KCalendarSystemIslamicCivilPrivate::hasYearZero() const 00149 { 00150 return false; 00151 } 00152 00153 int KCalendarSystemIslamicCivilPrivate::maxDaysInWeek() const 00154 { 00155 return 7; 00156 } 00157 00158 int KCalendarSystemIslamicCivilPrivate::maxMonthsInYear() const 00159 { 00160 return 12; 00161 } 00162 00163 int KCalendarSystemIslamicCivilPrivate::earliestValidYear() const 00164 { 00165 return 1; 00166 } 00167 00168 int KCalendarSystemIslamicCivilPrivate::latestValidYear() const 00169 { 00170 return 9999; 00171 } 00172 00173 QString KCalendarSystemIslamicCivilPrivate::monthName(int month, int year, KLocale::DateTimeComponentFormat format, bool possessive) const 00174 { 00175 Q_UNUSED(year); 00176 00177 if (format == KLocale::NarrowName) { 00178 switch (month) { 00179 case 1: 00180 return ki18nc("Hijri month 1 - KLocale::NarrowName", "M").toString(locale()); 00181 case 2: 00182 return ki18nc("Hijri month 2 - KLocale::NarrowName", "S").toString(locale()); 00183 case 3: 00184 return ki18nc("Hijri month 3 - KLocale::NarrowName", "A").toString(locale()); 00185 case 4: 00186 return ki18nc("Hijri month 4 - KLocale::NarrowName", "T").toString(locale()); 00187 case 5: 00188 return ki18nc("Hijri month 5 - KLocale::NarrowName", "A").toString(locale()); 00189 case 6: 00190 return ki18nc("Hijri month 6 - KLocale::NarrowName", "T").toString(locale()); 00191 case 7: 00192 return ki18nc("Hijri month 7 - KLocale::NarrowName", "R").toString(locale()); 00193 case 8: 00194 return ki18nc("Hijri month 8 - KLocale::NarrowName", "S").toString(locale()); 00195 case 9: 00196 return ki18nc("Hijri month 9 - KLocale::NarrowName", "R").toString(locale()); 00197 case 10: 00198 return ki18nc("Hijri month 10 - KLocale::NarrowName", "S").toString(locale()); 00199 case 11: 00200 return ki18nc("Hijri month 11 - KLocale::NarrowName", "Q").toString(locale()); 00201 case 12: 00202 return ki18nc("Hijri month 12 - KLocale::NarrowName", "H").toString(locale()); 00203 default: 00204 return QString(); 00205 } 00206 } 00207 00208 if (format == KLocale::ShortName && possessive) { 00209 switch (month) { 00210 case 1: 00211 return ki18nc("Hijri month 1 - KLocale::ShortName Possessive", "of Muh").toString(locale()); 00212 case 2: 00213 return ki18nc("Hijri month 2 - KLocale::ShortName Possessive", "of Saf").toString(locale()); 00214 case 3: 00215 return ki18nc("Hijri month 3 - KLocale::ShortName Possessive", "of R.A").toString(locale()); 00216 case 4: 00217 return ki18nc("Hijri month 4 - KLocale::ShortName Possessive", "of R.T").toString(locale()); 00218 case 5: 00219 return ki18nc("Hijri month 5 - KLocale::ShortName Possessive", "of J.A").toString(locale()); 00220 case 6: 00221 return ki18nc("Hijri month 6 - KLocale::ShortName Possessive", "of J.T").toString(locale()); 00222 case 7: 00223 return ki18nc("Hijri month 7 - KLocale::ShortName Possessive", "of Raj").toString(locale()); 00224 case 8: 00225 return ki18nc("Hijri month 8 - KLocale::ShortName Possessive", "of Sha").toString(locale()); 00226 case 9: 00227 return ki18nc("Hijri month 9 - KLocale::ShortName Possessive", "of Ram").toString(locale()); 00228 case 10: 00229 return ki18nc("Hijri month 10 - KLocale::ShortName Possessive", "of Shw").toString(locale()); 00230 case 11: 00231 return ki18nc("Hijri month 11 - KLocale::ShortName Possessive", "of Qid").toString(locale()); 00232 case 12: 00233 return ki18nc("Hijri month 12 - KLocale::ShortName Possessive", "of Hij").toString(locale()); 00234 default: 00235 return QString(); 00236 } 00237 } 00238 00239 if (format == KLocale::ShortName && !possessive) { 00240 switch (month) { 00241 case 1: 00242 return ki18nc("Hijri month 1 - KLocale::ShortName", "Muh").toString(locale()); 00243 case 2: 00244 return ki18nc("Hijri month 2 - KLocale::ShortName", "Saf").toString(locale()); 00245 case 3: 00246 return ki18nc("Hijri month 3 - KLocale::ShortName", "R.A").toString(locale()); 00247 case 4: 00248 return ki18nc("Hijri month 4 - KLocale::ShortName", "R.T").toString(locale()); 00249 case 5: 00250 return ki18nc("Hijri month 5 - KLocale::ShortName", "J.A").toString(locale()); 00251 case 6: 00252 return ki18nc("Hijri month 6 - KLocale::ShortName", "J.T").toString(locale()); 00253 case 7: 00254 return ki18nc("Hijri month 7 - KLocale::ShortName", "Raj").toString(locale()); 00255 case 8: 00256 return ki18nc("Hijri month 8 - KLocale::ShortName", "Sha").toString(locale()); 00257 case 9: 00258 return ki18nc("Hijri month 9 - KLocale::ShortName", "Ram").toString(locale()); 00259 case 10: 00260 return ki18nc("Hijri month 10 - KLocale::ShortName", "Shw").toString(locale()); 00261 case 11: 00262 return ki18nc("Hijri month 11 - KLocale::ShortName", "Qid").toString(locale()); 00263 case 12: 00264 return ki18nc("Hijri month 12 - KLocale::ShortName", "Hij").toString(locale()); 00265 default: 00266 return QString(); 00267 } 00268 } 00269 00270 if (format == KLocale::LongName && possessive) { 00271 switch (month) { 00272 case 1: 00273 return ki18nc("Hijri month 1 - KLocale::LongName Possessive", "of Muharram").toString(locale()); 00274 case 2: 00275 return ki18nc("Hijri month 2 - KLocale::LongName Possessive", "of Safar").toString(locale()); 00276 case 3: 00277 return ki18nc("Hijri month 3 - KLocale::LongName Possessive", "of Rabi` al-Awal").toString(locale()); 00278 case 4: 00279 return ki18nc("Hijri month 4 - KLocale::LongName Possessive", "of Rabi` al-Thaani").toString(locale()); 00280 case 5: 00281 return ki18nc("Hijri month 5 - KLocale::LongName Possessive", "of Jumaada al-Awal").toString(locale()); 00282 case 6: 00283 return ki18nc("Hijri month 6 - KLocale::LongName Possessive", "of Jumaada al-Thaani").toString(locale()); 00284 case 7: 00285 return ki18nc("Hijri month 7 - KLocale::LongName Possessive", "of Rajab").toString(locale()); 00286 case 8: 00287 return ki18nc("Hijri month 8 - KLocale::LongName Possessive", "of Sha`ban").toString(locale()); 00288 case 9: 00289 return ki18nc("Hijri month 9 - KLocale::LongName Possessive", "of Ramadan").toString(locale()); 00290 case 10: 00291 return ki18nc("Hijri month 10 - KLocale::LongName Possessive", "of Shawwal").toString(locale()); 00292 case 11: 00293 return ki18nc("Hijri month 11 - KLocale::LongName Possessive", "of Thu al-Qi`dah").toString(locale()); 00294 case 12: 00295 return ki18nc("Hijri month 12 - KLocale::LongName Possessive", "of Thu al-Hijjah").toString(locale()); 00296 default: 00297 return QString(); 00298 } 00299 } 00300 00301 // Default to LongName 00302 switch (month) { 00303 case 1: 00304 return ki18nc("Hijri month 1 - KLocale::LongName", "Muharram").toString(locale()); 00305 case 2: 00306 return ki18nc("Hijri month 2 - KLocale::LongName", "Safar").toString(locale()); 00307 case 3: 00308 return ki18nc("Hijri month 3 - KLocale::LongName", "Rabi` al-Awal").toString(locale()); 00309 case 4: 00310 return ki18nc("Hijri month 4 - KLocale::LongName", "Rabi` al-Thaani").toString(locale()); 00311 case 5: 00312 return ki18nc("Hijri month 5 - KLocale::LongName", "Jumaada al-Awal").toString(locale()); 00313 case 6: 00314 return ki18nc("Hijri month 6 - KLocale::LongName", "Jumaada al-Thaani").toString(locale()); 00315 case 7: 00316 return ki18nc("Hijri month 7 - KLocale::LongName", "Rajab").toString(locale()); 00317 case 8: 00318 return ki18nc("Hijri month 8 - KLocale::LongName", "Sha`ban").toString(locale()); 00319 case 9: 00320 return ki18nc("Hijri month 9 - KLocale::LongName", "Ramadan").toString(locale()); 00321 case 10: 00322 return ki18nc("Hijri month 10 - KLocale::LongName", "Shawwal").toString(locale()); 00323 case 11: 00324 return ki18nc("Hijri month 11 - KLocale::LongName", "Thu al-Qi`dah").toString(locale()); 00325 case 12: 00326 return ki18nc("Hijri month 12 - KLocale::LongName", "Thu al-Hijjah").toString(locale()); 00327 default: 00328 return QString(); 00329 } 00330 } 00331 00332 QString KCalendarSystemIslamicCivilPrivate::weekDayName(int weekDay, KLocale::DateTimeComponentFormat format) const 00333 { 00334 if (format == KLocale::NarrowName) { 00335 switch (weekDay) { 00336 case 1: 00337 return ki18nc("Hijri weekday 1 - KLocale::NarrowName ", "I").toString(locale()); 00338 case 2: 00339 return ki18nc("Hijri weekday 2 - KLocale::NarrowName ", "T").toString(locale()); 00340 case 3: 00341 return ki18nc("Hijri weekday 3 - KLocale::NarrowName ", "A").toString(locale()); 00342 case 4: 00343 return ki18nc("Hijri weekday 4 - KLocale::NarrowName ", "K").toString(locale()); 00344 case 5: 00345 return ki18nc("Hijri weekday 5 - KLocale::NarrowName ", "J").toString(locale()); 00346 case 6: 00347 return ki18nc("Hijri weekday 6 - KLocale::NarrowName ", "S").toString(locale()); 00348 case 7: 00349 return ki18nc("Hijri weekday 7 - KLocale::NarrowName ", "A").toString(locale()); 00350 default: 00351 return QString(); 00352 } 00353 } 00354 00355 if (format == KLocale::ShortName || format == KLocale:: ShortNumber) { 00356 switch (weekDay) { 00357 case 1: 00358 return ki18nc("Hijri weekday 1 - KLocale::ShortName", "Ith").toString(locale()); 00359 case 2: 00360 return ki18nc("Hijri weekday 2 - KLocale::ShortName", "Thl").toString(locale()); 00361 case 3: 00362 return ki18nc("Hijri weekday 3 - KLocale::ShortName", "Arb").toString(locale()); 00363 case 4: 00364 return ki18nc("Hijri weekday 4 - KLocale::ShortName", "Kha").toString(locale()); 00365 case 5: 00366 return ki18nc("Hijri weekday 5 - KLocale::ShortName", "Jum").toString(locale()); 00367 case 6: 00368 return ki18nc("Hijri weekday 6 - KLocale::ShortName", "Sab").toString(locale()); 00369 case 7: 00370 return ki18nc("Hijri weekday 7 - KLocale::ShortName", "Ahd").toString(locale()); 00371 default: return QString(); 00372 } 00373 } 00374 00375 switch (weekDay) { 00376 case 1: 00377 return ki18nc("Hijri weekday 1 - KLocale::LongName", "Yaum al-Ithnain").toString(locale()); 00378 case 2: 00379 return ki18nc("Hijri weekday 2 - KLocale::LongName", "Yau al-Thulatha").toString(locale()); 00380 case 3: 00381 return ki18nc("Hijri weekday 3 - KLocale::LongName", "Yaum al-Arbi'a").toString(locale()); 00382 case 4: 00383 return ki18nc("Hijri weekday 4 - KLocale::LongName", "Yaum al-Khamees").toString(locale()); 00384 case 5: 00385 return ki18nc("Hijri weekday 5 - KLocale::LongName", "Yaum al-Jumma").toString(locale()); 00386 case 6: 00387 return ki18nc("Hijri weekday 6 - KLocale::LongName", "Yaum al-Sabt").toString(locale()); 00388 case 7: 00389 return ki18nc("Hijri weekday 7 - KLocale::LongName", "Yaum al-Ahad").toString(locale()); 00390 default: 00391 return QString(); 00392 } 00393 } 00394 00395 00396 KCalendarSystemIslamicCivil::KCalendarSystemIslamicCivil(const KLocale *locale) 00397 : KCalendarSystem(*new KCalendarSystemIslamicCivilPrivate(this), KSharedConfig::Ptr(), locale) 00398 { 00399 d_ptr->loadConfig(calendarType()); 00400 } 00401 00402 KCalendarSystemIslamicCivil::KCalendarSystemIslamicCivil(const KSharedConfig::Ptr config, const KLocale *locale) 00403 : KCalendarSystem(*new KCalendarSystemIslamicCivilPrivate(this), config, locale) 00404 { 00405 d_ptr->loadConfig(calendarType()); 00406 } 00407 00408 KCalendarSystemIslamicCivil::KCalendarSystemIslamicCivil(KCalendarSystemIslamicCivilPrivate &dd, 00409 const KSharedConfig::Ptr config, const KLocale *locale) 00410 : KCalendarSystem(dd, config, locale) 00411 { 00412 d_ptr->loadConfig(calendarType()); 00413 } 00414 00415 KCalendarSystemIslamicCivil::~KCalendarSystemIslamicCivil() 00416 { 00417 } 00418 00419 QString KCalendarSystemIslamicCivil::calendarType() const 00420 { 00421 return QLatin1String("hijri"); 00422 } 00423 00424 QDate KCalendarSystemIslamicCivil::epoch() const 00425 { 00426 // 16 July 622 in the Julian calendar 00427 return QDate::fromJulianDay(1948440); 00428 } 00429 00430 QDate KCalendarSystemIslamicCivil::earliestValidDate() const 00431 { 00432 return epoch(); 00433 } 00434 00435 QDate KCalendarSystemIslamicCivil::latestValidDate() const 00436 { 00437 // Set to last day of year 9999 00438 // Last day of Islamic Civil year 9999 is 9999-12-29 00439 return QDate::fromJulianDay(5491751); 00440 } 00441 00442 bool KCalendarSystemIslamicCivil::isValid(int year, int month, int day) const 00443 { 00444 return KCalendarSystem::isValid(year, month, day); 00445 } 00446 00447 bool KCalendarSystemIslamicCivil::isValid(const QDate &date) const 00448 { 00449 return KCalendarSystem::isValid(date); 00450 } 00451 00452 bool KCalendarSystemIslamicCivil::isLeapYear(int year) const 00453 { 00454 return KCalendarSystem::isLeapYear(year); 00455 } 00456 00457 bool KCalendarSystemIslamicCivil::isLeapYear(const QDate &date) const 00458 { 00459 return KCalendarSystem::isLeapYear(date); 00460 } 00461 00462 QString KCalendarSystemIslamicCivil::monthName(int month, int year, MonthNameFormat format) const 00463 { 00464 return KCalendarSystem::monthName(month, year, format); 00465 } 00466 00467 QString KCalendarSystemIslamicCivil::monthName(const QDate &date, MonthNameFormat format) const 00468 { 00469 return KCalendarSystem::monthName(date, format); 00470 } 00471 00472 QString KCalendarSystemIslamicCivil::weekDayName(int weekDay, WeekDayNameFormat format) const 00473 { 00474 return KCalendarSystem::weekDayName(weekDay, format); 00475 } 00476 00477 QString KCalendarSystemIslamicCivil::weekDayName(const QDate &date, WeekDayNameFormat format) const 00478 { 00479 return KCalendarSystem::weekDayName(date, format); 00480 } 00481 00482 int KCalendarSystemIslamicCivil::weekDayOfPray() const 00483 { 00484 return 5; // Friday 00485 } 00486 00487 bool KCalendarSystemIslamicCivil::isLunar() const 00488 { 00489 return true; 00490 } 00491 00492 bool KCalendarSystemIslamicCivil::isLunisolar() const 00493 { 00494 return false; 00495 } 00496 00497 bool KCalendarSystemIslamicCivil::isSolar() const 00498 { 00499 return false; 00500 } 00501 00502 bool KCalendarSystemIslamicCivil::isProleptic() const 00503 { 00504 return false; 00505 } 00506 00507 bool KCalendarSystemIslamicCivil::julianDayToDate(int jd, int &year, int &month, int &day) const 00508 { 00509 Q_D(const KCalendarSystemIslamicCivil); 00510 00511 /* 00512 The following C++ code is translated from the Lisp code 00513 in ``Calendrical Calculations'' by Nachum Dershowitz and 00514 Edward M. Reingold, Software---Practice & Experience, 00515 vol. 20, no. 9 (September, 1990), pp. 899--928. 00516 00517 This code is in the public domain, but any use of it 00518 should publically acknowledge its source. 00519 */ 00520 00521 // Search forward year by year from approximate year 00522 year = (jd - epoch().toJulianDay()) / 355; 00523 int testJd; 00524 dateToJulianDay(year, 12, d->daysInMonth(year, 12), testJd); 00525 while (jd > testJd) { 00526 year++; 00527 dateToJulianDay(year, 12, d->daysInMonth(year, 12), testJd); 00528 } 00529 00530 // Search forward month by month from Muharram 00531 month = 1; 00532 dateToJulianDay(year, month, d->daysInMonth(year, month), testJd); 00533 while (jd > testJd) { 00534 month++; 00535 dateToJulianDay(year, month, d->daysInMonth(year, month), testJd); 00536 } 00537 00538 dateToJulianDay(year, month, 1, testJd); 00539 day = jd - testJd + 1; 00540 00541 return true; 00542 00543 // Alternative implementations 00544 00545 // More recent editions of "Calendrical Calculations" by Dershowitz & Reingold have a more 00546 // efficient direct calculation without recusrion, but this cannot be used due to licensing 00547 00548 /* 00549 Formula from "Explanatory Supplement to the Astronomical Almanac" 2006, derived from Fliegel & Van Flandern 1968 00550 int L = jd - epoch().toJulianDay() + 10632; 00551 int N = ( L - 1 ) / 10631; 00552 L = L - 10631 * N + 354; 00553 int J = ( ( 10985 - L ) / 5316 ) x ( ( 50* L ) / 17719 ) + ( L / 5670 ) * ( ( 43 * L ) / 15238 ); 00554 L = L - ( ( 30 - J ) / 15 ) * ( ( 17719 * J ) / 50 ) - ( J / 16 ) * ( ( 15238 * J ) / 43 ) + 29; 00555 year = ( 30 * N ) + J - 30; 00556 month = ( 24 * L ) / 709; 00557 day = L - ( ( 709 * month ) / 24 ); 00558 */ 00559 00560 /* 00561 Formula from Fourmilab website 00562 jd = Math.floor(jd) + 0.5; 00563 year = Math.floor(((30 * (jd - epoch().toJulianDay())) + 10646) / 10631); 00564 month = qMin(12, Math.ceil((jd - (29 + islamic_to_jd(year, 1, 1))) / 29.5) + 1); 00565 day = (jd - islamic_to_jd(year, month, 1)) + 1; 00566 */ 00567 } 00568 00569 bool KCalendarSystemIslamicCivil::dateToJulianDay(int year, int month, int day, int &jd) const 00570 { 00571 /* 00572 The following C++ code is translated from the Lisp code 00573 in ``Calendrical Calculations'' by Nachum Dershowitz and 00574 Edward M. Reingold, Software---Practice & Experience, 00575 vol. 20, no. 9 (September, 1990), pp. 899--928. 00576 00577 This code is in the public domain, but any use of it 00578 should publically acknowledge its source. 00579 */ 00580 00581 jd = epoch().toJulianDay() - 1 + // days before start of calendar 00582 (year - 1) * 354 + // non-leap days in prior years 00583 (3 + (11 * year)) / 30 + // leap days in prior years 00584 29 * (month - 1) + // days so far... 00585 month / 2 + // ...this year 00586 day; // days so far this month 00587 00588 return true; 00589 00590 // Alternative implementations 00591 00592 /* 00593 Formula from "Explanatory Supplement to the Astronomical Almanac" 2006, derived from Fliegel & Van Flandern 1968 00594 jd = ( 3 + ( 11 * year ) ) / 30 + 354 * year + 30 * month - ( month - 1 ) / 2 + day + epoch().toJulianDay() - 385; 00595 */ 00596 }
KDE 4.7 API Reference