KDECore
kcalendarsystemcoptic.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 "kcalendarsystemcoptic_p.h" 00021 #include "kcalendarsystemprivate_p.h" 00022 #include "kcalendarsystemcopticprivate_p.h" 00023 00024 #include "kdebug.h" 00025 #include "klocale.h" 00026 00027 #include <QtCore/QDate> 00028 #include <QtCore/QCharRef> 00029 00030 // Shared d pointer implementations 00031 00032 KCalendarSystemCopticPrivate::KCalendarSystemCopticPrivate(KCalendarSystemCoptic *q) 00033 : KCalendarSystemPrivate(q) 00034 { 00035 } 00036 00037 KCalendarSystemCopticPrivate::~KCalendarSystemCopticPrivate() 00038 { 00039 } 00040 00041 KLocale::CalendarSystem KCalendarSystemCopticPrivate::calendarSystem() const 00042 { 00043 return KLocale::CopticCalendar; 00044 } 00045 00046 void KCalendarSystemCopticPrivate::loadDefaultEraList() 00047 { 00048 QString name, shortName, format; 00049 // AM for Anno Martyrum or "Year of the Martyrs" 00050 name = i18nc("Calendar Era: Coptic Era of Martyrs, years > 0, LongFormat", "Anno Martyrum"); 00051 shortName = i18nc("Calendar Era: Coptic Era of Martyrs, years > 0, ShortFormat", "AM"); 00052 format = i18nc("(kdedt-format) Coptic, AM, full era year format used for %EY, e.g. 2000 AM", "%Ey %EC"); 00053 addEra('+', 1, q->epoch(), 1, q->latestValidDate(), name, shortName, format); 00054 } 00055 00056 int KCalendarSystemCopticPrivate::monthsInYear(int year) const 00057 { 00058 Q_UNUSED(year) 00059 return 13; 00060 } 00061 00062 int KCalendarSystemCopticPrivate::daysInMonth(int year, int month) const 00063 { 00064 if (month == 13) { 00065 if (isLeapYear(year)) { 00066 return 6; 00067 } else { 00068 return 5; 00069 } 00070 } 00071 00072 return 30; 00073 } 00074 00075 int KCalendarSystemCopticPrivate::daysInYear(int year) const 00076 { 00077 if (isLeapYear(year)) { 00078 return 366; 00079 } else { 00080 return 365; 00081 } 00082 } 00083 00084 int KCalendarSystemCopticPrivate::daysInWeek() const 00085 { 00086 return 7; 00087 } 00088 00089 bool KCalendarSystemCopticPrivate::isLeapYear(int year) const 00090 { 00091 //Uses same rule as Julian but offset by 1 year with year 3 being first leap year 00092 if (year < 1) { 00093 year = year + 2; 00094 } else { 00095 year = year + 1; 00096 } 00097 00098 if (year % 4 == 0) { 00099 return true; 00100 } 00101 return false; 00102 } 00103 00104 bool KCalendarSystemCopticPrivate::hasLeapMonths() const 00105 { 00106 return false; 00107 } 00108 00109 bool KCalendarSystemCopticPrivate::hasYearZero() const 00110 { 00111 return false; 00112 } 00113 00114 int KCalendarSystemCopticPrivate::maxDaysInWeek() const 00115 { 00116 return 7; 00117 } 00118 00119 int KCalendarSystemCopticPrivate::maxMonthsInYear() const 00120 { 00121 return 13; 00122 } 00123 00124 int KCalendarSystemCopticPrivate::earliestValidYear() const 00125 { 00126 return 1; 00127 } 00128 00129 int KCalendarSystemCopticPrivate::latestValidYear() const 00130 { 00131 return 9999; 00132 } 00133 00134 // Names taken from Bohairic dialect transliterations in http://www.copticheritage.org/parameters/copticheritage/calendar/The_Coptic_Calendar.pdf 00135 // These differ from the transliterations found on Wikipedia http://en.wikipedia.org/wiki/Coptic_calendar 00136 // These differ from the Sahidic dialect transliterations used in Dershowitz & Reingold which went out of use in the 11th centuary 00137 // These differ from the Arabic transliterations found on Wikipedia 00138 // These differ from the transliterations used in Mac OSX 10.6 Snow Leopard 00139 // The Boharic was initially chosen as this is the dialect apparantly in 'common' use in the Coptic Church. 00140 // But it could be argued the Arabic forms should be used as they are in 'common' usage in Eqypt 00141 // And where did the rest come from? 00142 // 00143 // Boharic Wikipedia Copt D&R Sahidic Wikipedia Arab Mac OSX 00144 // -------------- --------------- -------------- -------------- -------------- 00145 // * Thoout Thout Thoout Tout Tout 00146 // * Paope Paopi Paope Baba Baba 00147 // * Hathor Hathor Athōr Hatour Hatour 00148 // * Kiahk Koiak Koiak Kiahk Kiahk 00149 // * Tobe Tobi Tōbe Touba Toba 00150 // * Meshir Meshir Meshir Amshir Amshir 00151 // * Paremhotep Paremhat Paremotep Baramhat Baramhat 00152 // * Parmoute Paremoude Paremoute Baramouda Baramouda 00153 // * Pashons Pashons Pashons Bashans Bashans 00154 // * Paone Paoni Paōne Ba'ouna Paona 00155 // * Epep Epip Epēp Abib Epep 00156 // * Mesore Mesori Mesorē Mesra Mesra 00157 // * Kouji nabot Pi Kogi Enavot Epagomenē Nasie 00158 // * 00159 QString KCalendarSystemCopticPrivate::monthName(int month, int year, KLocale::DateTimeComponentFormat format, bool possessive) const 00160 { 00161 Q_UNUSED(year); 00162 00163 if (format == KLocale::NarrowName) { 00164 switch (month) { 00165 case 1: 00166 return ki18nc("Coptic month 1 - KLocale::NarrowName", "T").toString(locale()); 00167 case 2: 00168 return ki18nc("Coptic month 2 - KLocale::NarrowName", "P").toString(locale()); 00169 case 3: 00170 return ki18nc("Coptic month 3 - KLocale::NarrowName", "H").toString(locale()); 00171 case 4: 00172 return ki18nc("Coptic month 4 - KLocale::NarrowName", "K").toString(locale()); 00173 case 5: 00174 return ki18nc("Coptic month 5 - KLocale::NarrowName", "T").toString(locale()); 00175 case 6: 00176 return ki18nc("Coptic month 6 - KLocale::NarrowName", "M").toString(locale()); 00177 case 7: 00178 return ki18nc("Coptic month 7 - KLocale::NarrowName", "P").toString(locale()); 00179 case 8: 00180 return ki18nc("Coptic month 8 - KLocale::NarrowName", "P").toString(locale()); 00181 case 9: 00182 return ki18nc("Coptic month 9 - KLocale::NarrowName", "P").toString(locale()); 00183 case 10: 00184 return ki18nc("Coptic month 10 - KLocale::NarrowName", "P").toString(locale()); 00185 case 11: 00186 return ki18nc("Coptic month 11 - KLocale::NarrowName", "E").toString(locale()); 00187 case 12: 00188 return ki18nc("Coptic month 12 - KLocale::NarrowName", "M").toString(locale()); 00189 case 13: 00190 return ki18nc("Coptic month 13 - KLocale::NarrowName", "K").toString(locale()); 00191 default: 00192 return QString(); 00193 } 00194 } 00195 00196 if (format == KLocale::ShortName && possessive) { 00197 switch (month) { 00198 case 1: 00199 return ki18nc("Coptic month 1 - KLocale::ShortName Possessive", "of Tho").toString(locale()); 00200 case 2: 00201 return ki18nc("Coptic month 2 - KLocale::ShortName Possessive", "of Pao").toString(locale()); 00202 case 3: 00203 return ki18nc("Coptic month 3 - KLocale::ShortName Possessive", "of Hat").toString(locale()); 00204 case 4: 00205 return ki18nc("Coptic month 4 - KLocale::ShortName Possessive", "of Kia").toString(locale()); 00206 case 5: 00207 return ki18nc("Coptic month 5 - KLocale::ShortName Possessive", "of Tob").toString(locale()); 00208 case 6: 00209 return ki18nc("Coptic month 6 - KLocale::ShortName Possessive", "of Mes").toString(locale()); 00210 case 7: 00211 return ki18nc("Coptic month 7 - KLocale::ShortName Possessive", "of Par").toString(locale()); 00212 case 8: 00213 return ki18nc("Coptic month 8 - KLocale::ShortName Possessive", "of Pam").toString(locale()); 00214 case 9: 00215 return ki18nc("Coptic month 9 - KLocale::ShortName Possessive", "of Pas").toString(locale()); 00216 case 10: 00217 return ki18nc("Coptic month 10 - KLocale::ShortName Possessive", "of Pan").toString(locale()); 00218 case 11: 00219 return ki18nc("Coptic month 11 - KLocale::ShortName Possessive", "of Epe").toString(locale()); 00220 case 12: 00221 return ki18nc("Coptic month 12 - KLocale::ShortName Possessive", "of Meo").toString(locale()); 00222 case 13: 00223 return ki18nc("Coptic month 13 - KLocale::ShortName Possessive", "of Kou").toString(locale()); 00224 default: 00225 return QString(); 00226 } 00227 } 00228 00229 if (format == KLocale::ShortName && !possessive) { 00230 switch (month) { 00231 case 1: 00232 return ki18nc("Coptic month 1 - KLocale::ShortName", "Tho").toString(locale()); 00233 case 2: 00234 return ki18nc("Coptic month 2 - KLocale::ShortName", "Pao").toString(locale()); 00235 case 3: 00236 return ki18nc("Coptic month 3 - KLocale::ShortName", "Hat").toString(locale()); 00237 case 4: 00238 return ki18nc("Coptic month 4 - KLocale::ShortName", "Kia").toString(locale()); 00239 case 5: 00240 return ki18nc("Coptic month 5 - KLocale::ShortName", "Tob").toString(locale()); 00241 case 6: 00242 return ki18nc("Coptic month 6 - KLocale::ShortName", "Mes").toString(locale()); 00243 case 7: 00244 return ki18nc("Coptic month 7 - KLocale::ShortName", "Par").toString(locale()); 00245 case 8: 00246 return ki18nc("Coptic month 8 - KLocale::ShortName", "Pam").toString(locale()); 00247 case 9: 00248 return ki18nc("Coptic month 9 - KLocale::ShortName", "Pas").toString(locale()); 00249 case 10: 00250 return ki18nc("Coptic month 10 - KLocale::ShortName", "Pan").toString(locale()); 00251 case 11: 00252 return ki18nc("Coptic month 11 - KLocale::ShortName", "Epe").toString(locale()); 00253 case 12: 00254 return ki18nc("Coptic month 12 - KLocale::ShortName", "Meo").toString(locale()); 00255 case 13: 00256 return ki18nc("Coptic month 12 - KLocale::ShortName", "Kou").toString(locale()); 00257 default: 00258 return QString(); 00259 } 00260 } 00261 00262 if (format == KLocale::LongName && possessive) { 00263 switch (month) { 00264 case 1: 00265 return ki18nc("Coptic month 1 - KLocale::LongName Possessive", "of Thoout").toString(locale()); 00266 case 2: 00267 return ki18nc("Coptic month 2 - KLocale::LongName Possessive", "of Paope").toString(locale()); 00268 case 3: 00269 return ki18nc("Coptic month 3 - KLocale::LongName Possessive", "of Hathor").toString(locale()); 00270 case 4: 00271 return ki18nc("Coptic month 4 - KLocale::LongName Possessive", "of Kiahk").toString(locale()); 00272 case 5: 00273 return ki18nc("Coptic month 5 - KLocale::LongName Possessive", "of Tobe").toString(locale()); 00274 case 6: 00275 return ki18nc("Coptic month 6 - KLocale::LongName Possessive", "of Meshir").toString(locale()); 00276 case 7: 00277 return ki18nc("Coptic month 7 - KLocale::LongName Possessive", "of Paremhotep").toString(locale()); 00278 case 8: 00279 return ki18nc("Coptic month 8 - KLocale::LongName Possessive", "of Parmoute").toString(locale()); 00280 case 9: 00281 return ki18nc("Coptic month 9 - KLocale::LongName Possessive", "of Pashons").toString(locale()); 00282 case 10: 00283 return ki18nc("Coptic month 10 - KLocale::LongName Possessive", "of Paone").toString(locale()); 00284 case 11: 00285 return ki18nc("Coptic month 11 - KLocale::LongName Possessive", "of Epep").toString(locale()); 00286 case 12: 00287 return ki18nc("Coptic month 12 - KLocale::LongName Possessive", "of Mesore").toString(locale()); 00288 case 13: 00289 return ki18nc("Coptic month 12 - KLocale::LongName Possessive", "of Kouji nabot").toString(locale()); 00290 default: 00291 return QString(); 00292 } 00293 } 00294 00295 // Default to LongName 00296 switch (month) { 00297 case 1: 00298 return ki18nc("Coptic month 1 - KLocale::LongName", "Thoout").toString(locale()); 00299 case 2: 00300 return ki18nc("Coptic month 2 - KLocale::LongName", "Paope").toString(locale()); 00301 case 3: 00302 return ki18nc("Coptic month 3 - KLocale::LongName", "Hathor").toString(locale()); 00303 case 4: 00304 return ki18nc("Coptic month 4 - KLocale::LongName", "Kiahk").toString(locale()); 00305 case 5: 00306 return ki18nc("Coptic month 5 - KLocale::LongName", "Tobe").toString(locale()); 00307 case 6: 00308 return ki18nc("Coptic month 6 - KLocale::LongName", "Meshir").toString(locale()); 00309 case 7: 00310 return ki18nc("Coptic month 7 - KLocale::LongName", "Paremhotep").toString(locale()); 00311 case 8: 00312 return ki18nc("Coptic month 8 - KLocale::LongName", "Parmoute").toString(locale()); 00313 case 9: 00314 return ki18nc("Coptic month 9 - KLocale::LongName", "Pashons").toString(locale()); 00315 case 10: 00316 return ki18nc("Coptic month 10 - KLocale::LongName", "Paone").toString(locale()); 00317 case 11: 00318 return ki18nc("Coptic month 11 - KLocale::LongName", "Epep").toString(locale()); 00319 case 12: 00320 return ki18nc("Coptic month 12 - KLocale::LongName", "Mesore").toString(locale()); 00321 case 13: 00322 return ki18nc("Coptic month 12 - KLocale::LongName", "Kouji nabot").toString(locale()); 00323 default: 00324 return QString(); 00325 } 00326 } 00327 00328 // Names taken from from the Sahidic dialect transliterations used in Dershowitz & Reingold which went out of use in the 11th centuary 00329 // Boharic or Arabic transliterations would be preferred but none could be found 00330 QString KCalendarSystemCopticPrivate::weekDayName(int weekDay, KLocale::DateTimeComponentFormat format) const 00331 { 00332 if (format == KLocale::NarrowName) { 00333 switch (weekDay) { 00334 case 1: 00335 return ki18nc("Coptic weekday 1 - KLocale::NarrowName", "P").toString(locale()); 00336 case 2: 00337 return ki18nc("Coptic weekday 2 - KLocale::NarrowName", "P").toString(locale()); 00338 case 3: 00339 return ki18nc("Coptic weekday 3 - KLocale::NarrowName", "P").toString(locale()); 00340 case 4: 00341 return ki18nc("Coptic weekday 4 - KLocale::NarrowName", "P").toString(locale()); 00342 case 5: 00343 return ki18nc("Coptic weekday 5 - KLocale::NarrowName", "P").toString(locale()); 00344 case 6: 00345 return ki18nc("Coptic weekday 6 - KLocale::NarrowName", "P").toString(locale()); 00346 case 7: 00347 return ki18nc("Coptic weekday 7 - KLocale::NarrowName", "T").toString(locale()); 00348 default: 00349 return QString(); 00350 } 00351 } 00352 00353 if (format == KLocale::ShortName || format == KLocale:: ShortNumber) { 00354 switch (weekDay) { 00355 case 1: 00356 return ki18nc("Coptic weekday 1 - KLocale::ShortName", "Pes").toString(locale()); 00357 case 2: 00358 return ki18nc("Coptic weekday 2 - KLocale::ShortName", "Psh").toString(locale()); 00359 case 3: 00360 return ki18nc("Coptic weekday 3 - KLocale::ShortName", "Pef").toString(locale()); 00361 case 4: 00362 return ki18nc("Coptic weekday 4 - KLocale::ShortName", "Pti").toString(locale()); 00363 case 5: 00364 return ki18nc("Coptic weekday 5 - KLocale::ShortName", "Pso").toString(locale()); 00365 case 6: 00366 return ki18nc("Coptic weekday 6 - KLocale::ShortName", "Psa").toString(locale()); 00367 case 7: 00368 return ki18nc("Coptic weekday 7 - KLocale::ShortName", "Tky").toString(locale()); 00369 default: 00370 return QString(); 00371 } 00372 } 00373 00374 switch (weekDay) { 00375 case 1: 00376 return ki18nc("Coptic weekday 1 - KLocale::LongName", "Pesnau").toString(locale()); 00377 case 2: 00378 return ki18nc("Coptic weekday 2 - KLocale::LongName", "Pshoment").toString(locale()); 00379 case 3: 00380 return ki18nc("Coptic weekday 3 - KLocale::LongName", "Peftoou").toString(locale()); 00381 case 4: 00382 return ki18nc("Coptic weekday 4 - KLocale::LongName", "Ptiou").toString(locale()); 00383 case 5: 00384 return ki18nc("Coptic weekday 5 - KLocale::LongName", "Psoou").toString(locale()); 00385 case 6: 00386 return ki18nc("Coptic weekday 6 - KLocale::LongName", "Psabbaton").toString(locale()); 00387 case 7: 00388 return ki18nc("Coptic weekday 7 - KLocale::LongName", "Tkyriakē").toString(locale()); 00389 default: 00390 return QString(); 00391 } 00392 } 00393 00394 00395 KCalendarSystemCoptic::KCalendarSystemCoptic(const KLocale *locale) 00396 : KCalendarSystem(*new KCalendarSystemCopticPrivate(this), KSharedConfig::Ptr(), locale) 00397 { 00398 d_ptr->loadConfig(calendarType()); 00399 } 00400 00401 KCalendarSystemCoptic::KCalendarSystemCoptic(const KSharedConfig::Ptr config, const KLocale *locale) 00402 : KCalendarSystem(*new KCalendarSystemCopticPrivate(this), config, locale) 00403 { 00404 d_ptr->loadConfig(calendarType()); 00405 } 00406 00407 KCalendarSystemCoptic::KCalendarSystemCoptic(KCalendarSystemCopticPrivate &dd, 00408 const KSharedConfig::Ptr config, const KLocale *locale) 00409 : KCalendarSystem(dd, config, locale) 00410 { 00411 d_ptr->loadConfig(calendarType()); 00412 } 00413 00414 KCalendarSystemCoptic::~KCalendarSystemCoptic() 00415 { 00416 } 00417 00418 QString KCalendarSystemCoptic::calendarType() const 00419 { 00420 return QLatin1String("coptic"); 00421 } 00422 00423 QDate KCalendarSystemCoptic::epoch() const 00424 { 00425 //0001-01-01, no Year 0. 00426 //0284-08-29 AD Julian 00427 return QDate::fromJulianDay(1825030); 00428 } 00429 00430 QDate KCalendarSystemCoptic::earliestValidDate() const 00431 { 00432 //0001-01-01, no Year 0. 00433 //0284-08-29 AD Julian 00434 return QDate::fromJulianDay(1825030); 00435 } 00436 00437 QDate KCalendarSystemCoptic::latestValidDate() const 00438 { 00439 // Set to last day of year 9999 until confirm date formats & widgets support > 9999 00440 //9999-12-30 00441 //10283-08-29 AD Julian 00442 return QDate::fromJulianDay(5477164); 00443 } 00444 00445 bool KCalendarSystemCoptic::isValid(int year, int month, int day) const 00446 { 00447 return KCalendarSystem::isValid(year, month, day); 00448 } 00449 00450 bool KCalendarSystemCoptic::isValid(const QDate &date) const 00451 { 00452 return KCalendarSystem::isValid(date); 00453 } 00454 00455 bool KCalendarSystemCoptic::isLeapYear(int year) const 00456 { 00457 return KCalendarSystem::isLeapYear(year); 00458 } 00459 00460 bool KCalendarSystemCoptic::isLeapYear(const QDate &date) const 00461 { 00462 return KCalendarSystem::isLeapYear(date); 00463 } 00464 00465 QString KCalendarSystemCoptic::monthName(int month, int year, MonthNameFormat format) const 00466 { 00467 return KCalendarSystem::monthName(month, year, format); 00468 } 00469 00470 QString KCalendarSystemCoptic::monthName(const QDate &date, MonthNameFormat format) const 00471 { 00472 return KCalendarSystem::monthName(date, format); 00473 } 00474 00475 QString KCalendarSystemCoptic::weekDayName(int weekDay, WeekDayNameFormat format) const 00476 { 00477 return KCalendarSystem::weekDayName(weekDay, format); 00478 } 00479 00480 QString KCalendarSystemCoptic::weekDayName(const QDate &date, WeekDayNameFormat format) const 00481 { 00482 return KCalendarSystem::weekDayName(date, format); 00483 } 00484 00485 int KCalendarSystemCoptic::weekDayOfPray() const 00486 { 00487 return 7; 00488 } 00489 00490 bool KCalendarSystemCoptic::isLunar() const 00491 { 00492 return false; 00493 } 00494 00495 bool KCalendarSystemCoptic::isLunisolar() const 00496 { 00497 return false; 00498 } 00499 00500 bool KCalendarSystemCoptic::isSolar() const 00501 { 00502 return true; 00503 } 00504 00505 bool KCalendarSystemCoptic::isProleptic() const 00506 { 00507 return false; 00508 } 00509 00510 bool KCalendarSystemCoptic::julianDayToDate(int jd, int &year, int &month, int &day) const 00511 { 00512 //The Coptic calendar has 12 months of 30 days, a 13th month of 5 or 6 days, 00513 //and a leap year every 4th year without fail that falls on the last day of 00514 //the year, starting from year 3. 00515 00516 //Use a fake year 0 for our epoch instead of the real epoch in year 1. This is because year 3 00517 //is the first leap year and a pattern of 365/365/366/365 is hard to calculate, instead a 00518 //pattern of 365/365/365/366 with the leap day the very last day makes the maths easier. 00519 00520 //Day number in the fake epoch, 0 indexed 00521 int dayInEpoch = jd - (epoch().toJulianDay() - 365); 00522 //How many full 4 year leap cycles have been completed, 1461 = (365*3)+366 00523 int leapCyclesCompleted = dayInEpoch / 1461; 00524 //Which year are we in the current 4 year leap cycle, 0 indexed 00525 //Need the qMin as day 366 of 4th year of cycle returns following year (max 3 as 0 index) 00526 int yearInCurrentLeapCycle = qMin(3, (dayInEpoch % 1461) / 365); 00527 //Calculate the year 00528 year = (leapCyclesCompleted * 4) + yearInCurrentLeapCycle; 00529 //Days since the fake epoch up to 1st day of this year 00530 int daysBeforeThisYear = (year * 365) + (year / 4); 00531 //Gives the day number in this year, 0 indexed 00532 int dayOfThisYear = dayInEpoch - daysBeforeThisYear; 00533 //Then just calculate month and day from that based on regular 30 day months 00534 month = ((dayOfThisYear) / 30) + 1; 00535 day = dayOfThisYear - ((month - 1) * 30) + 1; 00536 00537 // If year is -ve then is BC. In Coptic there is no year 0, but the maths 00538 // is easier if we pretend there is, so internally year of 0 = 1BC = -1 outside 00539 if (year < 1) { 00540 year = year - 1; 00541 } 00542 00543 return true; 00544 } 00545 00546 bool KCalendarSystemCoptic::dateToJulianDay(int year, int month, int day, int &jd) const 00547 { 00548 //The Coptic calendar has 12 months of 30 days, a 13th month of 5 or 6 days, 00549 //and a leap year every 4th year without fail that falls on the last day of 00550 //the year, starting from year 3. This simple repeating pattern makes calculating 00551 // a jd the simple process taking the epoch jd and adding on the years months and 00552 //days required. 00553 00554 // If year is -ve then is 'BC'. In Coptic there is no year 0, but the maths 00555 // is easier if we pretend there is, so internally year of -1 = 1BC = 0 internally 00556 int y; 00557 if (year < 1) { 00558 y = year + 1; 00559 } else { 00560 y = year; 00561 } 00562 00563 jd = epoch().toJulianDay() - 1 // jd of day before Epoch 00564 + ((y - 1) * 365) // Add all normal days in years preceding 00565 + (y / 4) // Add all leap days in years preceding 00566 + ((month - 1) * 30) // Add days this year in months preceding 00567 + day; // Add days in this month 00568 00569 return true; 00570 }
KDE 4.7 API Reference