From 4bf016c646476b8f211e2bc36783c81f4e715887 Mon Sep 17 00:00:00 2001 From: Giorgos Tsiapaliwkas Date: Wed, 1 Feb 2012 14:02:43 +0200 Subject: [PATCH] Add KCalendar *m_calendar and replace the method's contents with "m_calendar->foo();" --- declarativeimports/locale/calendarsystem.cpp | 2059 +----------------- 1 file changed, 83 insertions(+), 1976 deletions(-) diff --git a/declarativeimports/locale/calendarsystem.cpp b/declarativeimports/locale/calendarsystem.cpp index e57dfe557..a7ca3d660 100644 --- a/declarativeimports/locale/calendarsystem.cpp +++ b/declarativeimports/locale/calendarsystem.cpp @@ -99,968 +99,29 @@ KCalendarSystem *CalendarSystem::create(Locale::CalendarSystem calendarSystem, QList CalendarSystem::calendarSystemsList() { - return m_calendarSystem->calendarSystemList(); -} + QList list; -QString CalendarSystem::calendarLabel(Locale::CalendarSystem calendarSystem, const KLocale *locale) -{ - switch (calendarSystem) { - case Locale::QDateCalendar: - return ki18nc("@item Calendar system", "Gregorian").toString(locale); - case Locale::CopticCalendar: - return ki18nc("@item Calendar system", "Coptic").toString(locale); - case Locale::EthiopianCalendar: - return ki18nc("@item Calendar system", "Ethiopian").toString(locale); - case Locale::GregorianCalendar: - return ki18nc("@item Calendar system", "Gregorian (Proleptic)").toString(locale); - case Locale::HebrewCalendar: - return ki18nc("@item Calendar system", "Hebrew").toString(locale); - case Locale::IslamicCivilCalendar: - return ki18nc("@item Calendar system", "Islamic / Hijri (Civil)").toString(locale); - case Locale::IndianNationalCalendar: - return ki18nc("@item Calendar system", "Indian National").toString(locale); - case Locale::JalaliCalendar: - return ki18nc("@item Calendar system", "Jalali").toString(locale); - case Locale::JapaneseCalendar: - return ki18nc("@item Calendar system", "Japanese").toString(locale); - case Locale::JulianCalendar: - return ki18nc("@item Calendar system", "Julian").toString(locale); - case Locale::MinguoCalendar: - return ki18nc("@item Calendar system", "Taiwanese").toString(locale); - case Locale::ThaiCalendar: - return ki18nc("@item Calendar system", "Thai").toString(locale); + foreach(KLocale::CalendarSystem calendarSystem, m_calendarSystem->calendarSystemList()) { + list.append((Locale::CalendarSystem)calendarSystem); } - return ki18nc("@item Calendar system", "Invalid Calendar Type").toString(locale); + return list; } -Locale::CalendarSystem CalendarSystem::calendarSystemForCalendarType(const QString &calendarType ) +QString CalendarSystem::calendarLabel(Locale::CalendarSystem calendarSystem, const Locale *locale) { - return calendarSystem( calendarType ); + return m_calendarSystem->calendarLabel((KLocale::CalendarSystem)calendarSystem, (KLocale)locale); } Locale::CalendarSystem CalendarSystem::calendarSystem(const QString &calendarType ) { - if (calendarType == QLatin1String("coptic")) { - return Locale::CopticCalendar; - } else if (calendarType == QLatin1String("ethiopian")) { - return Locale::EthiopianCalendar; - } else if (calendarType == QLatin1String("gregorian")) { - return Locale::QDateCalendar; - } else if (calendarType == QLatin1String("gregorian-proleptic")) { - return Locale::GregorianCalendar; - } else if (calendarType == QLatin1String("hebrew")) { - return Locale::HebrewCalendar; - } else if (calendarType == QLatin1String("hijri")) { - return Locale::IslamicCivilCalendar; - } else if (calendarType == QLatin1String("indian-national")) { - return Locale::IndianNationalCalendar; - } else if (calendarType == QLatin1String("jalali")) { - return Locale::JalaliCalendar; - } else if (calendarType == QLatin1String("japanese")) { - return Locale::JapaneseCalendar; - } else if (calendarType == QLatin1String("julian")) { - return Locale::JulianCalendar; - } else if (calendarType == QLatin1String("minguo")) { - return Locale::MinguoCalendar; - } else if (calendarType == QLatin1String("thai")) { - return Locale::ThaiCalendar; - } else { - return Locale::QDateCalendar; - } -} - -QString CalendarSystem::calendarType(Locale::CalendarSystem calendarSystem) -{ - if (calendarSystem == Locale::QDateCalendar) { - return QLatin1String("gregorian"); - } else if (calendarSystem == Locale::CopticCalendar) { - return QLatin1String("coptic"); - } else if (calendarSystem == Locale::EthiopianCalendar) { - return QLatin1String("ethiopian"); - } else if (calendarSystem == Locale::GregorianCalendar) { - return QLatin1String("gregorian-proleptic"); - } else if (calendarSystem == Locale::HebrewCalendar) { - return QLatin1String("hebrew"); - } else if (calendarSystem == Locale::IndianNationalCalendar) { - return QLatin1String("indian-national"); - } else if (calendarSystem == Locale::IslamicCivilCalendar) { - return QLatin1String("hijri"); - } else if (calendarSystem == Locale::JalaliCalendar) { - return QLatin1String("jalali"); - } else if (calendarSystem == Locale::JapaneseCalendar) { - return QLatin1String("japanese"); - } else if (calendarSystem == Locale::JulianCalendar) { - return QLatin1String("julian"); - } else if (calendarSystem == Locale::MinguoCalendar) { - return QLatin1String("minguo"); - } else if (calendarSystem == Locale::ThaiCalendar) { - return QLatin1String("thai"); - } else { - return QLatin1String("gregorian"); - } -} - -// Shared d pointer base class definitions - -KCalendarSystemPrivate::KCalendarSystemPrivate(KCalendarSystem *q_ptr) - : q(q_ptr), - m_eraList(0), - m_shortYearWindowStartYear(2000) -{ -} - -KCalendarSystemPrivate::~KCalendarSystemPrivate() -{ - delete m_eraList; -} - -// Dummy version using Gregorian as an example -// This method MUST be re-implemented in any new Calendar System -Locale::CalendarSystem KCalendarSystemPrivate::calendarSystem() const -{ - return Locale::QDateCalendar; -} - -// Dummy version as an example, remember to translate (see Gregorian for example) -// Add the Era's in chronological order, from earliest to latest -// This method MUST be re-implemented in any new Calendar System -void KCalendarSystemPrivate::loadDefaultEraList() -{ - addEra('-', 1, q->epoch().addDays(-1), -1, q->earliestValidDate(), QLatin1String("Before KDE"), QLatin1String("BK"), QLatin1String("%Ey %EC")); - addEra('+', 1, q->epoch(), 1, q->latestValidDate(), QLatin1String("Anno KDE"), QLatin1String("AK"), QLatin1String("%Ey %EC")); -} - -// Dummy version using Gregorian as an example -// This method MUST be re-implemented in any new Calendar System -int KCalendarSystemPrivate::monthsInYear(int year) const -{ - Q_UNUSED(year) - return 12; -} - -// Dummy version using Gregorian as an example -// This method MUST be re-implemented in any new Calendar System -int KCalendarSystemPrivate::daysInMonth(int year, int month) const -{ - if (month == 2) { - if (isLeapYear(year)) { - return 29; - } else { - return 28; - } - } - - if (month == 4 || month == 6 || month == 9 || month == 11) { - return 30; - } - - return 31; -} - -// Dummy version using Gregorian as an example -// This method MUST be re-implemented in any new Calendar System -int KCalendarSystemPrivate::daysInYear(int year) const -{ - if (isLeapYear(year)) { - return 366; - } else { - return 365; - } -} - -// Dummy version using Gregorian as an example -// This method MUST be re-implemented in any new Calendar System -int KCalendarSystemPrivate::daysInWeek() const -{ - return 7; -} - -// Dummy version using Gregorian as an example -// This method MUST be re-implemented in any new Calendar System -bool KCalendarSystemPrivate::isLeapYear(int year) const -{ - if (year < 1) { - year = year + 1; - } - - if (year % 4 == 0) { - if (year % 100 != 0) { - return true; - } else if (year % 400 == 0) { - return true; - } - } - - return false; -} - -// Dummy version using Gregorian as an example -// This method MUST be re-implemented in any new Calendar System -bool KCalendarSystemPrivate::hasLeapMonths() const -{ - return false; -} - -// Dummy version using Gregorian as an example -// This method MUST be re-implemented in any new Calendar System -bool KCalendarSystemPrivate::hasYearZero() const -{ - return false; -} - -// Dummy version using Gregorian as an example -// This method MUST be re-implemented in any new Calendar System -int KCalendarSystemPrivate::maxDaysInWeek() const -{ - return 7; -} - -// Dummy version using Gregorian as an example -// This method MUST be re-implemented in any new Calendar System -int KCalendarSystemPrivate::maxMonthsInYear() const -{ - return 12; -} - -// Convenince, faster than calling year( ealiestValidDate() ), -// needed in fake-virtual functions so don't remove -// Dummy version using Gregorian as an example -// This method MUST be re-implemented in any new Calendar System -int KCalendarSystemPrivate::earliestValidYear() const -{ - return -4712; -} - -// Convenince, faster than calling year( latestValidDate() ), -// needed in fake-virtual functions so don't remove -// Dummy version using Gregorian as an example -// This method MUST be re-implemented in any new Calendar System -int KCalendarSystemPrivate::latestValidYear() const -{ - return 9999; -} - -// Dummy version -// This method MUST be re-implemented in any new Calendar System -QString KCalendarSystemPrivate::monthName(int month, int year, Locale::DateTimeComponentFormat format, bool possessive) const -{ - Q_UNUSED(month); - Q_UNUSED(year); - Q_UNUSED(format); - Q_UNUSED(possessive); - return QString(); -} - -// Dummy version -// This method MUST be re-implemented in any new Calendar System -QString KCalendarSystemPrivate::weekDayName(int weekDay, Locale::DateTimeComponentFormat format) const -{ - Q_UNUSED(weekDay); - Q_UNUSED(format); - return QString(); -} - -// Reimplement if special maths handling required, e.g. Hebrew. -int KCalendarSystemPrivate::week(const QDate &date, Locale::WeekNumberSystem weekNumberSystem, int *yearNum) const -{ - int y, m, d; - q->julianDayToDate(date.toJulianDay(), y, m, d); - - switch (weekNumberSystem) { - case Locale::IsoWeekNumber: - return isoWeekNumber(date, yearNum); - case Locale::FirstFullWeek: - return regularWeekNumber(date, locale()->weekStartDay(), 0, yearNum); - case Locale::FirstPartialWeek: - return regularWeekNumber(date, locale()->weekStartDay(), 1, yearNum); - case Locale::SimpleWeek: - return simpleWeekNumber(date, yearNum); - case Locale::DefaultWeekNumber: - default: - return week(date, locale()->weekNumberSystem(), yearNum); - } -} - -// Reimplement if special maths handling required, e.g. Hebrew. -int KCalendarSystemPrivate::isoWeekNumber(const QDate &date, int *yearNum) const -{ - int y, m, d; - q->julianDayToDate(date.toJulianDay(), y, m, d); - - QDate firstDayWeek1, lastDay; - int week; - int weekDay1, dayOfWeek1InYear; - - // let's guess 1st day of 1st week - firstDayWeek1 = firstDayOfYear(y); - weekDay1 = dayOfWeek(firstDayWeek1); - - // iso 8601: week 1 is the first containing thursday and week starts on monday - if (weekDay1 > 4 /*Thursday*/) { - firstDayWeek1 = q->addDays(firstDayWeek1 , daysInWeek() - weekDay1 + 1); // next monday - } - - dayOfWeek1InYear = dayOfYear(firstDayWeek1); - - // our date in prev year's week - if (dayOfYear(date) < dayOfWeek1InYear) { - if (yearNum) { - *yearNum = addYears(y, - 1); - } - return isoWeeksInYear(addYears(y, - 1)); - } - - // let's check if its last week belongs to next year - lastDay = lastDayOfYear(y); - - // if our date is in last week && 1st week in next year has thursday - if ((dayOfYear(date) >= daysInYear(y) - dayOfWeek(lastDay) + 1) - && dayOfWeek(lastDay) < 4) { - if (yearNum) { - * yearNum = addYears(y, 1); - } - week = 1; - } else { - // To calculate properly the number of weeks from day a to x let's make a day 1 of week - if (weekDay1 < 5) { - firstDayWeek1 = q->addDays(firstDayWeek1, -(weekDay1 - 1)); - } - - if (yearNum) { - * yearNum = y; - } - - week = firstDayWeek1.daysTo(date) / daysInWeek() + 1; - } - - return week; -} - -// Reimplement if special maths handling required, e.g. Hebrew. -int KCalendarSystemPrivate::regularWeekNumber(const QDate &date, int weekStartDay, int firstWeekNumber, int *weekYear) const -{ - int y, m, d; - q->julianDayToDate(date.toJulianDay(), y, m, d); - - int firstWeekDayOffset = (dayOfWeek(date) - weekStartDay + daysInWeek()) % daysInWeek(); - int dayInYear = date.toJulianDay() - firstDayOfYear(y).toJulianDay(); // 0 indexed - int week = ((dayInYear - firstWeekDayOffset + daysInWeek()) / daysInWeek()); - - if (dayOfWeek(firstDayOfYear(y)) != weekStartDay) { - week = week + firstWeekNumber; - } - - if (week < 1) { - y = y - 1; - week = regularWeeksInYear(y, weekStartDay, firstWeekNumber); - } - - if (weekYear) { - *weekYear = y; - } - - return week; -} - -// Reimplement if special maths handling required, e.g. Hebrew. -int KCalendarSystemPrivate::simpleWeekNumber(const QDate &date, int *yearNum) const -{ - int y, m, d; - q->julianDayToDate(date.toJulianDay(), y, m, d); - if (yearNum) { - *yearNum = y; - } - return ((date.toJulianDay() - firstDayOfYear(y).toJulianDay()) / daysInWeek()) + 1; -} - -// Reimplement if special maths handling required, e.g. Hebrew. -int KCalendarSystemPrivate::weeksInYear(int year, Locale::WeekNumberSystem weekNumberSystem) const -{ - switch (weekNumberSystem) { - case Locale::IsoWeekNumber: - return isoWeeksInYear(year); - case Locale::FirstFullWeek: - return regularWeeksInYear(year, locale()->weekStartDay(), 0); - case Locale::FirstPartialWeek: - return regularWeeksInYear(year, locale()->weekStartDay(), 1); - case Locale::SimpleWeek: - return simpleWeeksInYear(year); - case Locale::DefaultWeekNumber: - default: - return weeksInYear(year, locale()->weekNumberSystem()); - } -} - -// Reimplement if special maths handling required, e.g. Hebrew. -int KCalendarSystemPrivate::isoWeeksInYear(int year) const -{ - QDate lastDayOfThisYear = lastDayOfYear(year); - - int weekYear = year; - int lastWeekInThisYear = isoWeekNumber(lastDayOfThisYear, &weekYear); - - // If error, or the last day of the year is in the first week of next year use the week before - if (lastWeekInThisYear < 1 || weekYear != year) { - lastWeekInThisYear = isoWeekNumber(q->addDays(lastDayOfThisYear, -7), &weekYear); - } - - return lastWeekInThisYear; -} - -// Reimplement if special maths handling required, e.g. Hebrew. -int KCalendarSystemPrivate::regularWeeksInYear(int year, int weekStartDay, int firstWeekNumber) const -{ - return regularWeekNumber(lastDayOfYear(year), weekStartDay, firstWeekNumber, 0); -} - -// Reimplement if special maths handling required, e.g. Hebrew. -int KCalendarSystemPrivate::simpleWeeksInYear(int year) const -{ - return simpleWeekNumber(lastDayOfYear(year), 0); -} - -// Reimplement if special maths handling required, e.g. Hebrew. -// Works for calendars with constant number of months, or where leap month is last month of year -// Will not work for Hebrew or others where leap month is inserted in middle of year -void KCalendarSystemPrivate::dateDifference(const QDate &fromDate, const QDate &toDate, - int *yearsDiff, int *monthsDiff, int *daysDiff, int *direction) const -{ - // This could be optimised a little but is left in full as it's easier to understand - int dy = 0; - int dm = 0; - int dd = 0; - int dir = 1; - - if (toDate < fromDate) { - dateDifference(toDate, fromDate, &dy, &dm, &dd, 0); - dir = -1; - } else if (toDate > fromDate) { - - int fromYear = q->year(fromDate); - int toYear = q->year(toDate); - int fromMonth = q->month(fromDate); - int toMonth = q->month(toDate); - int fromDay = q->day(fromDate); - int toDay = q->day(toDate); - - int monthsInPrevYear = monthsInYear(addYears(toYear, -1)); - int daysInPrevMonth = q->daysInMonth(q->addMonths(toDate, -1)); - int daysInFromMonth = daysInMonth(fromYear, fromMonth); - int daysInToMonth = daysInMonth(toYear, toMonth); - - // Calculate years difference - if (toYear == fromYear) { - dy = 0; - } else if (toMonth > fromMonth) { - dy = differenceYearNumbers(fromYear, toYear); - } else if (toMonth < fromMonth) { - dy = differenceYearNumbers(fromYear, toYear) - 1; - } else { // toMonth == fromMonth - // Allow for last day of month to last day of month and leap days - // e.g. 2000-02-29 to 2001-02-28 is 1 year not 0 years - if ((toDay >= fromDay) || (fromDay == daysInFromMonth && toDay == daysInToMonth)) { - dy = differenceYearNumbers(fromYear, toYear); - } else { - dy = differenceYearNumbers(fromYear, toYear) - 1; - } - } - - // Calculate months and days difference - if (toDay >= fromDay) { - dm = (monthsInPrevYear + toMonth - fromMonth) % monthsInPrevYear; - dd = toDay - fromDay; - } else { // toDay < fromDay - // Allow for last day of month to last day of month and leap days - // e.g. 2010-03-31 to 2010-04-30 is 1 month - // 2000-02-29 to 2001-02-28 is 1 year - // 2000-02-29 to 2001-03-01 is 1 year 1 day - int prevMonth = q->month(q->addMonths(toDate, -1)); - if (fromDay == daysInFromMonth && toDay == daysInToMonth) { - dm = (monthsInPrevYear + toMonth - fromMonth) % monthsInPrevYear; - dd = 0; - } else if (prevMonth == fromMonth && daysInPrevMonth < daysInFromMonth) { - // Special case where fromDate = leap day and toDate in month following but non-leap year - // e.g. 2000-02-29 to 2001-03-01 needs to use 29 to calculate day number not 28 - dm = (monthsInPrevYear + toMonth - fromMonth - 1) % monthsInPrevYear; - dd = (daysInFromMonth + toDay - fromDay) % daysInFromMonth; - } else { - dm = (monthsInPrevYear + toMonth - fromMonth - 1) % monthsInPrevYear; - dd = (daysInPrevMonth + toDay - fromDay) % daysInPrevMonth; - } - } - - } - - // Only return values if we have a valid pointer - if (yearsDiff) { - *yearsDiff = dy; - } - if (monthsDiff) { - *monthsDiff = dm; - } - if (daysDiff) { - *daysDiff = dd; - } - if (direction) { - *direction = dir; - } -} - -// Reimplement if special maths handling required, e.g. Hebrew -// Allows for calendars with leap months at end of year but not during year -int KCalendarSystemPrivate::yearsDifference(const QDate &fromDate, const QDate &toDate) const -{ - // This could be optimised a little but is left in full as it's easier to understand - // Alternatively could just call dateDifference(), but this is slightly more efficient - - if (toDate < fromDate) { - return 0 - yearsDifference(toDate, fromDate); - } - - if (toDate == fromDate) { - return 0; - } - - int fromYear = q->year(fromDate); - int toYear = q->year(toDate); - - if (toYear == fromYear) { - return 0; - } - - int fromMonth = q->month(fromDate); - int toMonth = q->month(toDate); - - if (toMonth > fromMonth) { - return differenceYearNumbers(fromYear, toYear); - } - - if (toMonth < fromMonth) { - return differenceYearNumbers(fromYear, toYear) - 1; - } - - // toMonth == fromMonth - int fromDay = q->day(fromDate); - int toDay = q->day(toDate); - - // Adjust for month numbers in from and to year - // Allow for last day of month to last day of month and leap days - // e.g. 2000-02-29 to 2001-02-28 is 1 year not 0 years - if ((toDay >= fromDay) || - (fromDay == daysInMonth(fromYear, fromMonth) && - toDay == daysInMonth(toYear, toMonth))) { - return differenceYearNumbers(fromYear, toYear); - } else { - return differenceYearNumbers(fromYear, toYear) - 1; - } - -} - -// Reimplement if special maths handling required, e.g. maybe Hebrew? -// Allows for calendars with leap months -int KCalendarSystemPrivate::monthsDifference(const QDate &fromDate, const QDate &toDate) const -{ - if (toDate < fromDate) { - return 0 - monthsDifference(toDate, fromDate); - } - - if (toDate == fromDate) { - return 0; - } - - int fromYear = q->year(fromDate); - int toYear = q->year(toDate); - int fromMonth = q->month(fromDate); - int toMonth = q->month(toDate); - int fromDay = q->day(fromDate); - int toDay = q->day(toDate); - - int monthsInPreceedingYears; - - // Calculate number of months in full years preceding toYear - if (toYear == fromYear) { - monthsInPreceedingYears = 0; - } else if (hasLeapMonths()) { - monthsInPreceedingYears = 0; - for (int y = fromYear; y < toYear; y = addYears(y, 1)) { - monthsInPreceedingYears = monthsInPreceedingYears + monthsInYear(y); - } - } else { - monthsInPreceedingYears = differenceYearNumbers(fromYear, toYear) * monthsInYear(toYear); - } - - // Adjust for months in from and to year - // Allow for last day of month to last day of month and leap days - // e.g. 2010-03-31 to 2010-04-30 is 1 month not 0 months - // also 2000-02-29 to 2001-02-28 is 12 months not 11 months - if ((toDay >= fromDay) || - (fromDay == daysInMonth(fromYear, fromMonth) && - toDay == daysInMonth(toYear, toMonth))) { - return monthsInPreceedingYears + toMonth - fromMonth; - } else { - return monthsInPreceedingYears + toMonth - fromMonth - 1; - } -} - -// Reimplement if special string to integer handling required, e.g. Hebrew. -// Peel a number off the front of a string which may have other trailing chars after the number -// Stop either at either maxLength, eos, or first non-digit char -int KCalendarSystemPrivate::integerFromString(const QString &string, int maxLength, int &readLength) const -{ - int value = -1; - int position = 0; - readLength = 0; - bool ok = false; - - if (maxLength < 0) { - maxLength = string.length(); - } - - while (position < string.length() && - position < maxLength && - string.at(position).isDigit()) { - position++; - } - - if (position > 0) { - value = string.left(position).toInt(&ok); - if (ok) { - readLength = position; - } else { - value = -1; - } - } - - return value; -} - -// Reimplement if special integer to string handling required, e.g. Hebrew. -// Utility to convert an integer into the correct display string form -QString KCalendarSystemPrivate::stringFromInteger(int number, int padWidth, QChar padChar) const -{ - return stringFromInteger(number, padWidth, padChar, q->locale()->dateTimeDigitSet()); -} - -// Reimplement if special integer to string handling required, e.g. Hebrew. -// Utility to convert an integer into the correct display string form -QString KCalendarSystemPrivate::stringFromInteger(int number, int padWidth, QChar padChar, Locale::DigitSet digitSet) const -{ - if (padChar == QLatin1Char('\0') || padWidth == 0) { - return q->locale()->convertDigits(QString::number(number), digitSet); - } else { - return q->locale()->convertDigits(QString::number(number).rightJustified(padWidth, padChar), digitSet); - } -} - -// Allows us to set dates outside publically valid range, USE WITH CARE!!!! -bool KCalendarSystemPrivate::setAnyDate(QDate &date, int year, int month, int day) const -{ - int jd; - q->dateToJulianDay(year, month, day, jd); - date = QDate::fromJulianDay(jd); - return true; -} - -// Utility to correctly add years to a year number because some systems such as -// Julian and Gregorian calendars don't have a year 0 -int KCalendarSystemPrivate::addYears(int originalYear, int addYears) const -{ - int newYear = originalYear + addYears; - - if (!hasYearZero()) { - if (originalYear > 0 && newYear <= 0) { - newYear = newYear - 1; - } else if (originalYear < 0 && newYear >= 0) { - newYear = newYear + 1; - } - } - - return newYear; -} - -// Utility to correctly return number of years between two year numbers because some systems such as -// Julian and Gregorian calendars don't have a year 0 -int KCalendarSystemPrivate::differenceYearNumbers(int fromYear, int toYear) const -{ - int dy = toYear - fromYear; - - if (!hasYearZero()) { - if (toYear > 0 && fromYear < 0) { - dy = dy - 1; - } else if (toYear < 0 && fromYear > 0) { - dy = dy + 1; - } - } - - return dy; -} - -QDate KCalendarSystemPrivate::invalidDate() const -{ - //Is QDate's way of saying is invalid - return QDate(); -} - -QString KCalendarSystemPrivate::simpleDateString(const QString &str) const -{ - QString newStr; - for (int i = 0; i < str.length(); i++) { - if (str.at(i).isLetterOrNumber()) { - newStr.append(str.at(i)); - } else { - newStr.append(QLatin1Char(' ')); - } - } - newStr.simplified(); - return newStr; -} - -int KCalendarSystemPrivate::dayOfYear(const QDate &date) const -{ - int y, m, d, jdFirstDayOfYear; - q->julianDayToDate(date.toJulianDay(), y, m, d); - q->dateToJulianDay(y, 1, 1, jdFirstDayOfYear); - //Take the jd of the given date, and subtract the jd of the first day of that year - return (date.toJulianDay() - jdFirstDayOfYear + 1); -} - -int KCalendarSystemPrivate::dayOfWeek(const QDate &date) const -{ - // Makes assumption that Julian Day 0 was day 1 of week - // This is true for Julian/Gregorian calendar with jd 0 being Monday - // We add 1 for ISO compliant numbering for 7 day week - // Assumes we've never skipped weekdays - return ((date.toJulianDay() % daysInWeek()) + 1); -} - -QDate KCalendarSystemPrivate::firstDayOfYear(int year) const -{ - int jd; - q->dateToJulianDay(year, 1, 1, jd); - return QDate::fromJulianDay(jd); -} - -QDate KCalendarSystemPrivate::lastDayOfYear(int year) const -{ - int jd; - q->dateToJulianDay(year, 1, 1, jd); - jd = jd + daysInYear(year) - 1; - return QDate::fromJulianDay(jd); -} - -QDate KCalendarSystemPrivate::firstDayOfMonth(int year, int month) const -{ - int jd; - q->dateToJulianDay(year, month, 1, jd); - return QDate::fromJulianDay(jd); -} - -QDate KCalendarSystemPrivate::lastDayOfMonth(int year, int month) const -{ - int jd; - q->dateToJulianDay(year, month, 1, jd); - jd = jd + daysInMonth(year, month) - 1; - return QDate::fromJulianDay(jd); -} - -const KLocale * KCalendarSystemPrivate::locale() const -{ - if (m_locale) { - return m_locale; - } else { - return KGlobal::locale(); - } -} - -QList *KCalendarSystemPrivate::eraList() const -{ - return m_eraList; -} - -KCalendarEra KCalendarSystemPrivate::era(const QDate &eraDate) const -{ - for (int i = m_eraList->count() - 1; i >= 0; --i) { - if (m_eraList->at(i).isInEra(eraDate)) { - return m_eraList->at(i); - } - } - return KCalendarEra(); -} - -KCalendarEra KCalendarSystemPrivate::era(const QString &eraName, int yearInEra) const -{ - Q_UNUSED(yearInEra) - - for (int i = m_eraList->count() - 1; i >= 0; --i) { - KCalendarEra era = m_eraList->at(i); - if (era.name(Locale::LongName).toLower() == eraName.toLower() || - era.name(Locale::ShortName).toLower() == eraName.toLower()) { - return era; - } - } - return KCalendarEra(); -} - -void KCalendarSystemPrivate::loadEraList(const KConfigGroup & cg) -{ - delete m_eraList; - m_eraList = new QList; - QString eraKey = QString::fromLatin1("Era1"); - int i = 1; - while (cg.hasKey(eraKey)) { - QString eraEntry = cg.readEntry(eraKey, QString()); - if (!eraEntry.isEmpty()) { - // Based on LC_TIME, but different! - // Includes long and short names, uses ISO fomat dates - // e.g. +:1:0001-01-01:9999-12-31:Anno Domini:AD:%EC %Ey - QChar direction = eraEntry.section(QLatin1Char(':'), 0, 0).at(0); - QDate startDate, endDate; - int startYear; - QString buffer = eraEntry.section(QLatin1Char(':'), 2, 2); - if (buffer.isEmpty()) { - if (direction == QLatin1Char('-')) { - startDate = q->latestValidDate(); - } else { - startDate = q->earliestValidDate(); - } - } else { - startDate = q->readDate(buffer, Locale::IsoFormat); - } - if (q->isValid(startDate)) { - startYear = q->year(startDate); - } else { - startYear = eraEntry.section(QLatin1Char(':'), 1, 1).toInt(); //Use offset - } - - buffer = eraEntry.section(QLatin1Char(':'), 3, 3); - if (buffer.isEmpty()) { - if (direction == QLatin1Char('-')) { - endDate = q->earliestValidDate(); - } else { - endDate = q->latestValidDate(); - } - } else { - endDate = q->readDate(buffer, Locale::IsoFormat); - } - addEra(direction.toLatin1(), eraEntry.section(QLatin1Char(':'), 1, 1).toInt(), - startDate, startYear, endDate, eraEntry.section(QLatin1Char(':'), 4, 4), - eraEntry.section(QLatin1Char(':'), 5, 5), eraEntry.section(QLatin1Char(':'), 6)); - } - ++i; - eraKey = QString::fromLatin1("Era%1").arg(i); - } - - if (m_eraList->isEmpty()) { - loadDefaultEraList(); - } -} - -void KCalendarSystemPrivate::addEra(char direction, int offset, - const QDate &startDate, int startYear, const QDate &endDate, - const QString &name, const QString &shortName, - const QString &format) -{ - KCalendarEra newEra; - - newEra.m_sequence = m_eraList->count() + 1; - if (direction == '-') { - newEra.m_direction = -1; - } else { - newEra.m_direction = 1; - } - newEra.m_offset = offset; - newEra.m_startDate = startDate; - newEra.m_startYear = startYear; - newEra.m_endDate = endDate; - newEra.m_longName = name; - newEra.m_shortName = shortName; - newEra.m_format = format; - - m_eraList->append(newEra); -} - -int KCalendarSystemPrivate::shortYearWindowStartYear() const -{ - return m_shortYearWindowStartYear; -} - -int KCalendarSystemPrivate::applyShortYearWindow(int inputYear) const -{ - if (inputYear >= 0 && inputYear <= 99) { - int shortStartYear = m_shortYearWindowStartYear % 100; - int yearOffset = m_shortYearWindowStartYear - shortStartYear; - if (inputYear >= shortStartYear) { - return inputYear + yearOffset; - } else { - return inputYear + yearOffset + 100; - } - } else { - return inputYear; - } -} - -void KCalendarSystemPrivate::loadShortYearWindowStartYear(const KConfigGroup & cg) -{ - // Default to 2000 for backwards compatibility - // as that's the old readDate() default value - int startYear = 2000; - if (cg.exists()) { - startYear = cg.readEntry("ShortYearWindowStartYear", 2000); - } - m_shortYearWindowStartYear = startYear; -} - -KSharedConfig::Ptr KCalendarSystemPrivate::config() -{ - if (m_config == KSharedConfig::Ptr()) { - return KGlobal::config(); - } else { - return m_config; - } -} - -void KCalendarSystemPrivate::loadConfig(const QString & calendarType) -{ - KConfigGroup localeGroup(config(), QString::fromLatin1("Locale")); - KConfigGroup calendarGroup = localeGroup.group(QString::fromLatin1("KCalendarSystem %1").arg(calendarType)); - loadEraList(calendarGroup); - loadShortYearWindowStartYear(calendarGroup); -} - - -CalendarSystem::KCalendarSystem(const KLocale *locale) - : d_ptr(new KCalendarSystemPrivate(this)) -{ - d_ptr->m_config = KSharedConfig::Ptr(); - d_ptr->m_locale = locale; -} - -CalendarSystem::KCalendarSystem(const KSharedConfig::Ptr config, const KLocale *locale) - : d_ptr(new KCalendarSystemPrivate(this)) -{ - d_ptr->m_config = config; - d_ptr->m_locale = locale; -} - -CalendarSystem::KCalendarSystem(KCalendarSystemPrivate &dd, const KSharedConfig::Ptr config, const KLocale *locale) - : d_ptr(&dd) -{ - d_ptr->m_config = config; - d_ptr->m_locale = locale; -} - -CalendarSystem::~KCalendarSystem() -{ - delete d_ptr; + return (Locale::CalendarSystem)m_calendarSystem->calendarSystem(calendarType); } // NOT VIRTUAL - If override needed use shared-d Locale::CalendarSystem CalendarSystem::calendarSystem() const { - Q_D(const KCalendarSystem); - - return d->calendarSystem(); + return (Locale::CalendarSystem)m_calendarSystem->calendarSystem(); } // NOT VIRTUAL - If override needed use shared-d @@ -1073,7 +134,7 @@ QString CalendarSystem::calendarLabel() const // This method MUST be re-implemented in any new Calendar System QDate CalendarSystem::epoch() const { - return QDate::fromJulianDay(38); + return m_calendarSystem->epoch(); } QDate CalendarSystem::earliestValidDate() const @@ -1086,296 +147,110 @@ QDate CalendarSystem::earliestValidDate() const QDate CalendarSystem::latestValidDate() const { // Default to Gregorian 9999-12-31 - return QDate::fromJulianDay(5373484); + return m_calendarSystem->latestValidDate(); } bool CalendarSystem::isValid(int year, int month, int day) const { - Q_D(const KCalendarSystem); - - if (year < d->earliestValidYear() || year > d->latestValidYear() || - (!d->hasYearZero() && year == 0)) { - return false; - } - - if (month < 1 || month > d->monthsInYear(year)) { - return false; - } - - if (day < 1 || day > d->daysInMonth(year, month)) { - return false; - } - - return true; + return m_calendarSystem->isValid(year, month, day); } // NOT VIRTUAL - If override needed use shared-d bool CalendarSystem::isValid(int year, int dayOfYear) const { - Q_D(const KCalendarSystem); - - return (isValid(year, 1, 1) && dayOfYear > 0 && dayOfYear <= d->daysInYear(year)); + return m_calendarSystem->isValid(year, dayOfYear); } // NOT VIRTUAL - If override needed use shared-d bool CalendarSystem::isValid(const QString &eraName, int yearInEra, int month, int day) const { - Q_D(const KCalendarSystem); - - KCalendarEra era = d->era(eraName, yearInEra); - return (era.isValid() && isValid(era.year(yearInEra), month, day)); + return m_calendarSystem->isValid(eraName, yearInEra, month, day); } // NOT VIRTUAL - If override needed use shared-d bool CalendarSystem::isValidIsoWeekDate(int year, int isoWeekNumber, int dayOfIsoWeek) const { - Q_D(const KCalendarSystem); - - //Tests Year value in standard YMD isValid() - if (!isValid(year, 1, 1)) { - return false; - } - - //Test Week Number falls in valid range for this year - int weeksInThisYear = weeksInYear(year); - if (isoWeekNumber < 1 || isoWeekNumber > weeksInThisYear) { - return false; - } - - //Test Day of Week Number falls in valid range - if (dayOfIsoWeek < 1 || dayOfIsoWeek > d->daysInWeek()) { - return false; - } - - //If not in earliest or latest years then all OK - //Otherwise need to check don't fall into previous or next year that would be invalid - if (year == d->earliestValidYear() && isoWeekNumber == 1) { - //If firstDayOfYear falls on or before Thursday then firstDayOfYear falls in week 1 this - //year and if wanted dayOfIsoWeek falls before firstDayOfYear then falls in previous year - //and so in invalid year - int dowFirstDay = dayOfWeek(d->firstDayOfYear(year)); - if (dowFirstDay <= 4 && dayOfIsoWeek < dowFirstDay) { - return false; - } - } else if (year == d->latestValidYear() && isoWeekNumber == weeksInThisYear) { - //If lastDayOfYear falls on or after Thursday then lastDayOfYear falls in last week this - //year and if wanted dayOfIsoWeek falls after lastDayOfYear then falls in next year - //and so in invalid year - int dowLastDay = dayOfWeek(d->lastDayOfYear(year)); - if (dowLastDay >= 4 && dayOfIsoWeek > dowLastDay) { - return false; - } - } - - return true; + return m_calendarSystem->isValidIsoWeekDate(year, isoWeekNumber, dayOfIsoWeek); } bool CalendarSystem::isValid(const QDate &date) const { - if (date.isNull() || date < earliestValidDate() || date > latestValidDate()) { - return false; - } - return true; + return m_calendarSystem->isValid(date); } bool CalendarSystem::setDate(QDate &date, int year, int month, int day) const { - Q_D(const KCalendarSystem); - - date = d->invalidDate(); - - if (isValid(year, month, day)) { - int jd; - dateToJulianDay(year, month, day, jd); - QDate calcDate = QDate::fromJulianDay(jd); - - if (isValid(calcDate)) { - date = calcDate; - return true; - } - } - - return false; + return m_calendarSystem->setDate(date, year, month, day); } // NOT VIRTUAL - If override needed use shared-d bool CalendarSystem::setDate(QDate &date, int year, int dayOfYear) const { - Q_D(const KCalendarSystem); - - date = d->invalidDate(); - - if (isValid(year, dayOfYear)) { - int jd; - dateToJulianDay(year, 1, 1, jd); - QDate calcDate = QDate::fromJulianDay(jd + dayOfYear - 1); - if (isValid(calcDate)) { - date = calcDate; - return true; - } - } - - return false; + return m_calendarSystem->setDate(date, year, dayOfYear); } // NOT VIRTUAL - If override needed use shared-d bool CalendarSystem::setDate(QDate &date, QString eraName, int yearInEra, int month, int day) const { - Q_D(const KCalendarSystem); - - KCalendarEra era = d->era(eraName, yearInEra); - return (era.isValid() && setDate(date, era.year(yearInEra), month, day)); + return m_calendarSystem->setDate(date, eraName, yearInEra, month, day); } // NOT VIRTUAL - If override needed use shared-d bool CalendarSystem::setDateIsoWeek(QDate &date, int year, int isoWeekNumber, int dayOfIsoWeek) const { - Q_D(const KCalendarSystem); - - date = d->invalidDate(); - - if (isValidIsoWeekDate(year, isoWeekNumber, dayOfIsoWeek)) { - - QDate calcDate = d->firstDayOfYear(year); - int dowFirstDayOfYear = dayOfWeek(calcDate); - - int daysToAdd = (d->daysInWeek() * (isoWeekNumber - 1)) + dayOfIsoWeek; - - if (dowFirstDayOfYear <= 4) { - calcDate = calcDate.addDays(daysToAdd - dowFirstDayOfYear); - } else { - calcDate = calcDate.addDays(daysInWeek(calcDate) + daysToAdd - dowFirstDayOfYear); - } - - if (isValid(calcDate)) { - date = calcDate; - return true; - } - } - - return false; -} - -// Deprecated -bool CalendarSystem::setYMD(QDate &date, int year, int month, int day) const -{ - return setDate(date, year, month, day); + m_calendarSystem->setDateIsoWeek(date, year, isoWeekNumber, dayOfIsoWeek); } // NOT VIRTUAL - If override needed use shared-d void CalendarSystem::getDate(const QDate date, int *year, int *month, int *day) const { - int y, m, d; - - if (isValid(date)) { - julianDayToDate(date.toJulianDay(), y, m, d); - } else { - y = 0; // How do you denote invalid year when we support -ve years? - m = 0; - d = 0; - } - - if (year) { - *year = y; - } - if (month) { - *month = m; - } - if (day) { - *day = d; - } - + return m_calendarSystem->getDate(date, year, month, day); } int CalendarSystem::year(const QDate &date) const { - if (isValid(date)) { - int year, month, day; - - julianDayToDate(date.toJulianDay(), year, month, day); - - return year; - } - - return 0; // How do you denote invalid year when we support -ve years? + return m_calendarSystem->year(date); } int CalendarSystem::month(const QDate &date) const { - if (isValid(date)) { - int year, month, day; - - julianDayToDate(date.toJulianDay(), year, month, day); - - return month; - } - - return 0; + return m_calendarSystem->month(date); } int CalendarSystem::day(const QDate &date) const { - if (isValid(date)) { - int year, month, day; - - julianDayToDate(date.toJulianDay(), year, month, day); - - return day; - } - - return 0; + return m_calendarSystem->day(date); } // NOT VIRTUAL - If override needed use shared-d QString CalendarSystem::eraName(const QDate &date, StringFormat format) const { - Q_D(const KCalendarSystem); - - if (isValid(date)) { - if (format == LongFormat) { - return d->era(date).name(Locale::LongName); - } else { - return d->era(date).name(Locale::ShortName); - } - } - - return QString(); + return m_calendarSystem->eraName(date, format); } // NOT VIRTUAL - If override needed use shared-d QString CalendarSystem::eraYear(const QDate &date, StringFormat format) const { - Q_UNUSED(format) - Q_D(const KCalendarSystem); - - if (isValid(date)) { - return formatDate(date, d->era(date).format()); - } - - return QString(); + return m_calendarSystem->eraYear(date, format); } // NOT VIRTUAL - If override needed use shared-d int CalendarSystem::yearInEra(const QDate &date) const { - Q_D(const KCalendarSystem); - - if (isValid(date)) { - return d->era(date).yearInEra(year(date)); - } - - return -1; + return m_calendarSystem->yearInEra(date); } // NOT VIRTUAL - If override needed use shared-d -QList *CalendarSystem::eraList() const +//FIXME we need a wrapper for KCalendarEra!! +/*QList *CalendarSystem::eraList() const { Q_D(const KCalendarSystem); return d->eraList(); -} +}*/ // NOT VIRTUAL - If override needed use shared-d +/*FIXME we don't need the above.Correct? KCalendarEra CalendarSystem::era(const QDate &eraDate) const { Q_D(const KCalendarSystem); @@ -1390,156 +265,56 @@ KCalendarEra CalendarSystem::era(const QString &eraName, int yearInEra) const return d->era(eraName, yearInEra); } - +*/ QDate CalendarSystem::addYears(const QDate &date, int numYears) const { - Q_D(const KCalendarSystem); - - if (isValid(date)) { - - int originalYear, originalMonth, originalDay; - julianDayToDate(date.toJulianDay(), originalYear, originalMonth, originalDay); - - int newYear = d->addYears(originalYear, numYears); - int newMonth = originalMonth; - int newDay = originalDay; - - //Adjust day number if new month has fewer days than old month - int daysInNewMonth = d->daysInMonth(newYear, newMonth); - if (daysInNewMonth < originalDay) { - newDay = daysInNewMonth; - } - - QDate newDate; - setDate(newDate, newYear, newMonth, newDay); - return newDate; - - } - - return d->invalidDate(); + return m_calendarSystem->addYears(date, numYears); } QDate CalendarSystem::addMonths(const QDate &date, int numMonths) const { - Q_D(const KCalendarSystem); - - if (isValid(date)) { - - int originalYear, originalMonth, originalDay; - julianDayToDate(date.toJulianDay(), originalYear, originalMonth, originalDay); - - int monthsInOriginalYear = d->monthsInYear(originalYear); - - int newYear = d->addYears(originalYear, (originalMonth + numMonths) / monthsInOriginalYear); - int newMonth = (originalMonth + numMonths) % monthsInOriginalYear; - int newDay = originalDay; - - if (newMonth == 0) { - newYear = d->addYears(newYear, - 1); - newMonth = monthsInOriginalYear; - } - if (newMonth < 0) { - newYear = d->addYears(newYear, - 1); - newMonth = newMonth + monthsInOriginalYear; - } - - //Adjust day number if new month has fewer days than old month - int daysInNewMonth = d->daysInMonth(newYear, newMonth); - if (daysInNewMonth < originalDay) { - newDay = daysInNewMonth; - } - - QDate newDate; - setDate(newDate, newYear, newMonth, newDay); - return newDate; - - } - - return d->invalidDate(); + return m_calendarSystem->addMonths(date, numMonths); } QDate CalendarSystem::addDays(const QDate &date, int numDays) const { - Q_D(const KCalendarSystem); - - // QDate only holds a uint and has no boundary checking in addDays(), so we need to check - if (isValid(date) && (long) date.toJulianDay() + (long) numDays > 0) { - // QDate adds straight to jd - QDate temp = date.addDays(numDays); - if (isValid(temp)) { - return temp; - } - } - - return d->invalidDate(); + return m_calendarSystem->addDays(date, numDays); } // NOT VIRTUAL - Uses shared-d instead void CalendarSystem::dateDifference(const QDate &fromDate, const QDate &toDate, int *yearsDiff, int *monthsDiff, int *daysDiff, int *direction) const { - Q_D(const KCalendarSystem); - - if (isValid(fromDate) && isValid(toDate)) { - d->dateDifference(fromDate, toDate, yearsDiff, monthsDiff, daysDiff, direction); - } + return m_calendarSystem->dateDifference(fromDate, toDate, yearsDiff, monthsDiff, daysDiff, direction); } // NOT VIRTUAL - Uses shared-d instead int CalendarSystem::yearsDifference(const QDate &fromDate, const QDate &toDate) const { - Q_D(const KCalendarSystem); - - if (isValid(fromDate) && isValid(toDate)) { - return d->yearsDifference(fromDate, toDate); - } - - return 0; + return m_calendarSystem->yearsDifference(fromDate, toDate); } // NOT VIRTUAL - Uses shared-d instead int CalendarSystem::monthsDifference(const QDate &fromDate, const QDate &toDate) const { - Q_D(const KCalendarSystem); - - if (isValid(fromDate) && isValid(toDate)) { - return d->monthsDifference(fromDate, toDate); - } - - return 0; + return m_calendarSystem->monthsDifference(fromDate, toDate); } // NOT VIRTUAL - Uses shared-d instead int CalendarSystem::daysDifference(const QDate &fromDate, const QDate &toDate) const { - if (isValid(fromDate) && isValid(toDate)) { - return toDate.toJulianDay() - fromDate.toJulianDay(); - } - - return 0; + return m_calendarSystem->daysDifference(fromDate, toDate); } int CalendarSystem::monthsInYear(const QDate &date) const { - Q_D(const KCalendarSystem); - - if (isValid(date)) { - return d->monthsInYear(year(date)); - } - - return -1; + return m_calendarSystem->monthsInYear(date); } // NOT VIRTUAL - Uses shared-d instead int CalendarSystem::monthsInYear(int year) const { - Q_D(const KCalendarSystem); - - if (isValid(year, 1, 1)) { - return d->monthsInYear(year); - } - - return -1; + return m_calendarSystem->monthsInYear(year); } int CalendarSystem::weeksInYear(const QDate &date) const @@ -1555,102 +330,50 @@ int CalendarSystem::weeksInYear(int year) const // NOT VIRTUAL - Uses shared-d instead int CalendarSystem::weeksInYear(const QDate &date, Locale::WeekNumberSystem weekNumberSystem) const { - Q_D(const KCalendarSystem); - - if (isValid(date)) { - return d->weeksInYear(year(date), weekNumberSystem); - } - - return -1; + return m_calendarSystem->weeksInYear(date, (KLocale::WeekNumberSystem)weekNumberSystem); } // NOT VIRTUAL - Uses shared-d instead int CalendarSystem::weeksInYear(int year, Locale::WeekNumberSystem weekNumberSystem) const { - Q_D(const KCalendarSystem); - - if (isValid(year, 1, 1)) { - return d->weeksInYear(year, weekNumberSystem); - } - - return -1; + return m_calendarSystem->weeksInYear(year, (KLocale::WeekNumberSystem)weekNumberSystem); } int CalendarSystem::daysInYear(const QDate &date) const { - Q_D(const KCalendarSystem); - - if (isValid(date)) { - return d->daysInYear(year(date)); - } - - return -1; + return m_calendarSystem->daysInYear(date); } // NOT VIRTUAL - Uses shared-d instead int CalendarSystem::daysInYear(int year) const { - Q_D(const KCalendarSystem); - - if (isValid(year, 1, 1)) { - return d->daysInYear(year); - } - - return -1; + return m_calendarSystem->daysInYear(year); } int CalendarSystem::daysInMonth(const QDate &date) const { - Q_D(const KCalendarSystem); - - if (isValid(date)) { - int year, month; - getDate(date, &year, &month, 0); - return d->daysInMonth(year, month); - } - - return -1; + return m_calendarSystem->daysInMonth(date); } // NOT VIRTUAL - Uses shared-d instead int CalendarSystem::daysInMonth(int year, int month) const { - Q_D(const KCalendarSystem); - - if (isValid(year, 1, 1)) { - return d->daysInMonth(year, month); - } - - return -1; + return m_calendarSystem->daysInMonth(year, month); } int CalendarSystem::daysInWeek(const QDate &date) const { - Q_UNUSED(date) - Q_D(const KCalendarSystem); - return d->daysInWeek(); + return m_calendarSystem->daysInWeek(); } int CalendarSystem::dayOfYear(const QDate &date) const { - Q_D(const KCalendarSystem); - - if (isValid(date)) { - return d->dayOfYear(date); - } - - return -1; + return m_calendarSystem->dayOfYear(date); } int CalendarSystem::dayOfWeek(const QDate &date) const { - Q_D(const KCalendarSystem); - - if (isValid(date)) { - return d->dayOfWeek(date); - } - - return -1; + return m_calendarSystem->dayOfWeek(date); } int CalendarSystem::weekNumber(const QDate &date, int *yearNum) const @@ -1667,407 +390,105 @@ int CalendarSystem::week(const QDate &date, int *yearNum) const // NOT VIRTUAL - Uses shared-d instead int CalendarSystem::week(const QDate &date, Locale::WeekNumberSystem weekNumberSystem, int *yearNum) const { - Q_D(const KCalendarSystem); - - if (isValid(date)) { - return d->week(date, weekNumberSystem, yearNum); - } - - return -1; + return m_calendarSystem->week(date, (KLocale::WeekNumberSystem)weekNumberSystem, yearNum); } bool CalendarSystem::isLeapYear(int year) const { - Q_D(const KCalendarSystem); - - if (isValid(year, 1, 1)) { - return d->isLeapYear(year); - } - - return false; + return m_calendarSystem->isLeapYear(year); } bool CalendarSystem::isLeapYear(const QDate &date) const { - Q_D(const KCalendarSystem); - - if (isValid(date)) { - return d->isLeapYear(year(date)); - } - - return false; + return m_calendarSystem->isLeapYear(date); } // NOT VIRTUAL - If override needed use shared-d QDate CalendarSystem::firstDayOfYear(int year) const { - Q_D(const KCalendarSystem); - - if (isValid(year, 1, 1)) { - return d->firstDayOfYear(year); - } - - return QDate(); + return m_calendarSystem->firstDayOfYear(year); } // NOT VIRTUAL - If override needed use shared-d QDate CalendarSystem::lastDayOfYear(int year) const { - Q_D(const KCalendarSystem); - - if (isValid(year, 1, 1)) { - return d->lastDayOfYear(year); - } - - return QDate(); + return m_calendarSystem->lastDayOfYear(year); } // NOT VIRTUAL - If override needed use shared-d QDate CalendarSystem::firstDayOfYear(const QDate &date) const { - Q_D(const KCalendarSystem); - - if (isValid(date)) { - return d->firstDayOfYear(year(date)); - } - - return QDate(); + return m_calendarSystem->firstDayOfYear(date); } // NOT VIRTUAL - If override needed use shared-d QDate CalendarSystem::lastDayOfYear(const QDate &date) const { - Q_D(const KCalendarSystem); - - if (isValid(date)) { - return d->lastDayOfYear(year(date)); - } - - return QDate(); + return m_calendarSystem->lastDayOfYear(date); } // NOT VIRTUAL - If override needed use shared-d QDate CalendarSystem::firstDayOfMonth(int year, int month) const { - Q_D(const KCalendarSystem); - - if (isValid(year, month, 1)) { - return d->firstDayOfMonth(year, month); - } - - return QDate(); + return m_calendarSystem->firstDayOfMonth(year, month); } // NOT VIRTUAL - If override needed use shared-d QDate CalendarSystem::lastDayOfMonth(int year, int month) const { - Q_D(const KCalendarSystem); - - if (isValid(year, month, 1)) { - return d->lastDayOfMonth(year, month); - } - - return QDate(); + return m_calendarSystem->lastDayOfMonth(year, month); } // NOT VIRTUAL - If override needed use shared-d QDate CalendarSystem::firstDayOfMonth(const QDate &date) const { - Q_D(const KCalendarSystem); - - if (isValid(date)) { - int year, month; - getDate(date, &year, &month, 0); - return d->firstDayOfMonth(year, month); - } - - return QDate(); + return m_calendarSystem->firstDayOfMonth(date); } // NOT VIRTUAL - If override needed use shared-d QDate CalendarSystem::lastDayOfMonth(const QDate &date) const { - Q_D(const KCalendarSystem); - - if (isValid(date)) { - int year, month; - getDate(date, &year, &month, 0); - return d->lastDayOfMonth(year, month); - } - - return QDate(); + return m_calendarSystem->lastDayOfMonth(date); } QString CalendarSystem::monthName(int month, int year, CalendarSystem::MonthNameFormat format) const { - Q_D(const KCalendarSystem); - - if (!isValid(year, month, 1)) { - return QString(); - } - - if (format == CalendarSystem::NarrowName) { - return d->monthName(month, year, Locale::NarrowName, false); - } - - if (format == CalendarSystem::ShortNamePossessive) { - return d->monthName(month, year, Locale::ShortName, true); - } - - if (format == CalendarSystem::ShortName) { - return d->monthName(month, year, Locale::ShortName, false); - } - - if (format == CalendarSystem::LongNamePossessive) { - return d->monthName(month, year, Locale::LongName, true); - } - - // CalendarSystem::LongName or any other - return d->monthName(month, year, Locale::LongName, false); + return m_calendarSystem->monthName(month, year, (KCalendarSystem::MonthNameFormat)format); } QString CalendarSystem::monthName(const QDate &date, MonthNameFormat format) const { - if (isValid(date)) { - int year, month; - getDate(date, &year, &month, 0); - return monthName(month, year, format); - } - - return QString(); + return m_calendarSystem->monthName(date, (KCalendarSystem::MonthNameFormat)format); } QString CalendarSystem::weekDayName(int weekDay, CalendarSystem::WeekDayNameFormat format) const { - Q_D(const KCalendarSystem); - - if (weekDay < 1 || weekDay > d->daysInWeek()) { - return QString(); - } - - if (format == CalendarSystem::NarrowDayName) { - return d->weekDayName(weekDay, Locale::NarrowName); - } - - if (format == CalendarSystem::ShortDayName) { - return d->weekDayName(weekDay, Locale::ShortName); - } - - if (format == CalendarSystem::ShortDayName) { - return d->weekDayName(weekDay, Locale::ShortName); - } - - return d->weekDayName(weekDay, Locale::LongName); + return m_calendarSystem->weekDayName(weekDay, (KCalendarSystem::WeekDayNameFormat)format); } QString CalendarSystem::weekDayName(const QDate &date, WeekDayNameFormat format) const { - if (isValid(date)) { - return weekDayName(dayOfWeek(date), format); - } - - return QString(); -} - -QString CalendarSystem::yearString(const QDate &date, StringFormat format) const -{ - if (format == ShortFormat) { - return formatDate(date, Locale::Year, Locale::ShortNumber); - } else { - return formatDate(date, Locale::Year, Locale::LongNumber); - } -} - -QString CalendarSystem::monthString(const QDate &date, StringFormat format) const -{ - if (format == ShortFormat) { - return formatDate(date, Locale::Month, Locale::ShortNumber); - } else { - return formatDate(date, Locale::Month, Locale::LongNumber); - } -} - -QString CalendarSystem::dayString(const QDate &date, StringFormat format) const -{ - if (format == ShortFormat) { - return formatDate(date, Locale::Day, Locale::ShortNumber); - } else { - return formatDate(date, Locale::Day, Locale::LongNumber); - } -} - -// NOT VIRTUAL - If override needed use shared-d -QString CalendarSystem::yearInEraString(const QDate &date, StringFormat format) const -{ - if (format == ShortFormat) { - return formatDate(date, Locale::YearInEra, Locale::ShortNumber); - } else { - return formatDate(date, Locale::YearInEra, Locale::LongNumber); - } -} - -// NOT VIRTUAL - If override needed use shared-d -QString CalendarSystem::dayOfYearString(const QDate &date, StringFormat format) const -{ - if (format == ShortFormat) { - return formatDate(date, Locale::DayOfYear, Locale::ShortNumber); - } else { - return formatDate(date, Locale::DayOfYear, Locale::LongNumber); - } -} - -// NOT VIRTUAL - If override needed use shared-d -QString CalendarSystem::dayOfWeekString(const QDate &date) const -{ - return formatDate(date, Locale::DayOfWeek, Locale::ShortNumber); -} - -// NOT VIRTUAL - If override needed use shared-d -QString CalendarSystem::weekNumberString(const QDate &date, StringFormat format) const -{ - if (format == ShortFormat) { - return formatDate(date, Locale::Week, Locale::ShortNumber); - } else { - return formatDate(date, Locale::Week, Locale::LongNumber); - } -} - -// NOT VIRTUAL - If override needed use shared-d -QString CalendarSystem::monthsInYearString(const QDate &date, StringFormat format) const -{ - if (format == ShortFormat) { - return formatDate(date, Locale::MonthsInYear, Locale::ShortNumber); - } else { - return formatDate(date, Locale::MonthsInYear, Locale::LongNumber); - } -} - -// NOT VIRTUAL - If override needed use shared-d -QString CalendarSystem::weeksInYearString(const QDate &date, StringFormat format) const -{ - if (format == ShortFormat) { - return formatDate(date, Locale::WeeksInYear, Locale::ShortNumber); - } else { - return formatDate(date, Locale::WeeksInYear, Locale::LongNumber); - } -} - -// NOT VIRTUAL - If override needed use shared-d -QString CalendarSystem::daysInYearString(const QDate &date, StringFormat format) const -{ - if (format == ShortFormat) { - return formatDate(date, Locale::DaysInYear, Locale::ShortNumber); - } else { - return formatDate(date, Locale::DaysInYear, Locale::LongNumber); - } -} - -// NOT VIRTUAL - If override needed use shared-d -QString CalendarSystem::daysInMonthString(const QDate &date, StringFormat format) const -{ - if (format == ShortFormat) { - return formatDate(date, Locale::DaysInMonth, Locale::ShortNumber); - } else { - return formatDate(date, Locale::DaysInMonth, Locale::LongNumber); - } -} - -// NOT VIRTUAL - If override needed use shared-d -QString CalendarSystem::daysInWeekString(const QDate &date) const -{ - return formatDate(date, Locale::DaysInWeek, Locale::ShortNumber); -} - -int CalendarSystem::yearStringToInteger(const QString &yearString, int &readLength) const -{ - Q_D(const KCalendarSystem); - - QString minus = i18nc("Negative symbol as used for year numbers, e.g. -5 = 5 BC", "-"); - if (yearString.startsWith(minus)) { - int value = d->integerFromString(yearString.mid(minus.length()), 4, readLength); - if (readLength > 0 && value >= 0) { - readLength = readLength + minus.length(); - return value * -1; - } else { - return value; - } - } - - return d->integerFromString(yearString, 4, readLength); -} - -int CalendarSystem::monthStringToInteger(const QString &monthString, int &readLength) const -{ - Q_D(const KCalendarSystem); - return d->integerFromString(monthString, 2, readLength); -} - -int CalendarSystem::dayStringToInteger(const QString &dayString, int &readLength) const -{ - Q_D(const KCalendarSystem); - return d->integerFromString(dayString, 2, readLength); + return m_calendarSystem->weekDayName(date, (KCalendarSystem::WeekDayNameFormat)format); } QString CalendarSystem::formatDate(const QDate &fromDate, Locale::DateFormat toFormat) const { - if (!fromDate.isValid()) { - return QString(); - } - - if (toFormat == Locale::FancyShortDate || toFormat == Locale::FancyLongDate) { - QDate now = KDateTime::currentLocalDate(); - int daysToNow = fromDate.daysTo(now); - switch (daysToNow) { - case 0: - return i18n("Today"); - case 1: - return i18n("Yesterday"); - case 2: - case 3: - case 4: - case 5: - case 6: - return weekDayName(fromDate); - default: - break; - } - } - - switch (toFormat) { - case Locale::LongDate: - case Locale::FancyLongDate: - return formatDate(fromDate, locale()->dateFormat()); - case Locale::IsoDate: - return formatDate(fromDate, QLatin1String("%Y-%m-%d")); - case Locale::IsoWeekDate: - return formatDate(fromDate, QLatin1String("%Y-W%V-%u")); - case Locale::IsoOrdinalDate: - return formatDate(fromDate, QLatin1String("%Y-%j")); - case Locale::ShortDate: - case Locale::FancyShortDate: - default: - return formatDate(fromDate, locale()->dateFormatShort()); - } - + return m_calendarSystem->formatDate(fromDate, (KLocale::DateFormat)toFormat); } // NOT VIRTUAL - If override needed use shared-d QString CalendarSystem::formatDate(const QDate &fromDate, const QString &toFormat, Locale::DateTimeFormatStandard standard) const { - return formatDate(fromDate, toFormat, locale()->dateTimeDigitSet(), standard); + return m_calendarSystem->formatDate(fromDate, toFormat, (KLocale::DateTimeFormatStandard)standar); } // NOT VIRTUAL - If override needed use shared-d QString CalendarSystem::formatDate(const QDate &fromDate, const QString &toFormat, Locale::DigitSet digitSet, Locale::DateTimeFormatStandard formatStandard) const { - if (!isValid(fromDate) || toFormat.isEmpty()) { - return QString(); - } - - KDateTimeFormatter formatter; - return formatter.formatDate(fromDate, toFormat, this, locale(), digitSet, formatStandard); + return m_calendarSystem->formatDate(fromDate, toFormat, (KLocale::DigitSet)digitSet, + (KLocale::DateTimeFormatStandard)formatStandard); } // NOT VIRTUAL - If override needed use shared-d @@ -2075,261 +496,19 @@ QString CalendarSystem::formatDate(const QDate &date, Locale::DateTimeComponent Locale::DateTimeComponentFormat format, Locale::WeekNumberSystem weekNumberSystem) const { - Q_D(const KCalendarSystem); - - switch (component) { - case Locale::Year: - case Locale::YearName: - switch (format) { - case Locale::ShortName: - case Locale::NarrowName: - case Locale::ShortNumber: - return formatDate(date, QLatin1String("%y")); - case Locale::LongNumber: - case Locale::LongName: - case Locale::DefaultComponentFormat: - default: - return formatDate(date, QLatin1String("%Y")); - } - case Locale::Month: - switch (format) { - case Locale::LongName: - return monthName(date, CalendarSystem::LongName); - case Locale::ShortName: - return monthName(date, CalendarSystem::ShortName); - case Locale::NarrowName: - return monthName(date, CalendarSystem::NarrowName); - case Locale::LongNumber: - return formatDate(date, QLatin1String("%m")); - case Locale::ShortNumber: - case Locale::DefaultComponentFormat: - default: - return formatDate(date, QLatin1String("%n")); - } - case Locale::MonthName: - switch (format) { - case Locale::NarrowName: - return monthName(date, CalendarSystem::NarrowName); - case Locale::ShortName: - case Locale::ShortNumber: - return monthName(date, CalendarSystem::ShortName); - case Locale::LongName: - case Locale::LongNumber: - case Locale::DefaultComponentFormat: - default: - return monthName(date, CalendarSystem::LongName); - } - case Locale::Day: - case Locale::DayName: - switch (format) { - case Locale::LongNumber: - case Locale::LongName: - return formatDate(date, QLatin1String("%d")); - case Locale::ShortName: - case Locale::NarrowName: - case Locale::ShortNumber: - case Locale::DefaultComponentFormat: - default: - return formatDate(date, QLatin1String("%e")); - } - case Locale::JulianDay: - return d->stringFromInteger(date.toJulianDay(), 0); - case Locale::EraName: - switch (format) { - case Locale::LongNumber: - case Locale::LongName: - return eraName(date, CalendarSystem::LongFormat); - case Locale::ShortName: - case Locale::NarrowName: - case Locale::ShortNumber: - case Locale::DefaultComponentFormat: - default: - return eraName(date, CalendarSystem::ShortFormat); - } - case Locale::EraYear: - switch (format) { - case Locale::LongNumber: - case Locale::LongName: - return eraYear(date, CalendarSystem::LongFormat); - case Locale::ShortName: - case Locale::NarrowName: - case Locale::ShortNumber: - case Locale::DefaultComponentFormat: - default: - return eraYear(date, CalendarSystem::ShortFormat); - } - case Locale::YearInEra: - switch (format) { - case Locale::LongNumber: - case Locale::LongName: - return formatDate(date, QLatin1String("%4Ey")); - case Locale::ShortName: - case Locale::NarrowName: - case Locale::ShortNumber: - case Locale::DefaultComponentFormat: - default: - return formatDate(date, QLatin1String("%Ey")); - } - case Locale::DayOfYear: - case Locale::DayOfYearName: - switch (format) { - case Locale::LongNumber: - case Locale::LongName: - return formatDate(date, QLatin1String("%j")); - case Locale::ShortName: - case Locale::NarrowName: - case Locale::ShortNumber: - case Locale::DefaultComponentFormat: - default: - return formatDate(date, QLatin1String("%-j")); - } - case Locale::DayOfWeek: - switch (format) { - case Locale::LongName: - return weekDayName(date, CalendarSystem::LongDayName); - case Locale::ShortName: - return weekDayName(date, CalendarSystem::ShortDayName); - case Locale::NarrowName: - return weekDayName(date, CalendarSystem::NarrowDayName); - case Locale::LongNumber: - case Locale::ShortNumber: - case Locale::DefaultComponentFormat: - default: - return formatDate(date, QLatin1String("%-u")); - } - case Locale::DayOfWeekName: - switch (format) { - case Locale::NarrowName: - return weekDayName(date, CalendarSystem::NarrowDayName); - case Locale::ShortName: - case Locale::ShortNumber: - return weekDayName(date, CalendarSystem::ShortDayName); - case Locale::LongName: - case Locale::LongNumber: - case Locale::DefaultComponentFormat: - default: - return weekDayName(date, CalendarSystem::LongDayName); - } - case Locale::Week: - switch (format) { - case Locale::LongNumber: - case Locale::LongName: - return d->stringFromInteger(week(date, weekNumberSystem, 0), 2, QLatin1Char('0')); - case Locale::ShortName: - case Locale::NarrowName: - case Locale::ShortNumber: - case Locale::DefaultComponentFormat: - default: - return d->stringFromInteger(week(date, weekNumberSystem, 0), 0, QLatin1Char('0')); - } - case Locale::WeekYear: { - int weekYear; - QDate yearDate; - week(date, weekNumberSystem, &weekYear); - setDate(yearDate, weekYear, 1, 1); - return formatDate(yearDate, Locale::Year, format); - } - case Locale::MonthsInYear: - switch (format) { - case Locale::LongNumber: - case Locale::LongName: - return d->stringFromInteger(monthsInYear(date), 2, QLatin1Char('0')); - case Locale::ShortName: - case Locale::NarrowName: - case Locale::ShortNumber: - case Locale::DefaultComponentFormat: - default: - return d->stringFromInteger(monthsInYear(date), 0, QLatin1Char('0')); - } - case Locale::WeeksInYear: - switch (format) { - case Locale::LongNumber: - case Locale::LongName: - return d->stringFromInteger(weeksInYear(date), 2, QLatin1Char('0')); - case Locale::ShortName: - case Locale::NarrowName: - case Locale::ShortNumber: - case Locale::DefaultComponentFormat: - default: - return d->stringFromInteger(weeksInYear(date), 0, QLatin1Char('0')); - } - case Locale::DaysInYear: - switch (format) { - case Locale::LongNumber: - case Locale::LongName: - return d->stringFromInteger(daysInYear(date), 3, QLatin1Char('0')); - case Locale::ShortName: - case Locale::NarrowName: - case Locale::ShortNumber: - case Locale::DefaultComponentFormat: - default: - return d->stringFromInteger(daysInYear(date), 0, QLatin1Char('0')); - } - case Locale::DaysInMonth: - switch (format) { - case Locale::LongNumber: - case Locale::LongName: - return d->stringFromInteger(daysInMonth(date), 2, QLatin1Char('0')); - case Locale::ShortName: - case Locale::NarrowName: - case Locale::ShortNumber: - case Locale::DefaultComponentFormat: - default: - return d->stringFromInteger(daysInMonth(date), 0, QLatin1Char('0')); - } - case Locale::DaysInWeek: - switch (format) { - case Locale::LongNumber: - case Locale::LongName: - case Locale::ShortName: - case Locale::NarrowName: - case Locale::ShortNumber: - case Locale::DefaultComponentFormat: - default: - return d->stringFromInteger(d->daysInWeek(), 0); - } - default: - return QString(); - } + return m_calendarSystem->formatDate(date, (KLocale::DateTimeComponent)component, + (KLocale::DateTimeComponentFormat)format, + (KLocale::WeekNumberSystem)weekNumberSystem); } QDate CalendarSystem::readDate(const QString &str, bool *ok) const { - //Try each standard format in turn, start with the locale ones, - //then the well defined standards - QDate date = readDate(str, Locale::ShortFormat, ok); - if (!isValid(date)) { - date = readDate(str, Locale::NormalFormat, ok); - if (!isValid(date)) { - date = readDate(str, Locale::IsoFormat, ok); - if (!isValid(date)) { - date = readDate(str, Locale::IsoWeekFormat, ok); - if (!isValid(date)) { - date = readDate(str, Locale::IsoOrdinalFormat, ok); - } - } - } - } - - return date; + return m_calendarSystem->readDate(str, ok); } QDate CalendarSystem::readDate(const QString &str, Locale::ReadDateFlags flags, bool *ok) const { - Q_D(const KCalendarSystem); - - if (flags & Locale::ShortFormat) { - return readDate(str, locale()->dateFormatShort(), ok); - } else if (flags & Locale::NormalFormat) { - return readDate(str, locale()->dateFormat(), ok); - } else if (flags & Locale::IsoFormat) { - return readDate(str, QLatin1String("%Y-%m-%d"), ok); - } else if (flags & Locale::IsoWeekFormat) { - return readDate(str, QLatin1String("%Y-W%V-%u"), ok); - } else if (flags & Locale::IsoOrdinalFormat) { - return readDate(str, QLatin1String("%Y-%j"), ok); - } - return d->invalidDate(); + return m_calendarSystem->readDate(str, (KLocale::ReadDateFlags)flags, ok); } QDate CalendarSystem::readDate(const QString &inputString, const QString &formatString, bool *ok) const @@ -2341,33 +520,25 @@ QDate CalendarSystem::readDate(const QString &inputString, const QString &format QDate CalendarSystem::readDate(const QString &inputString, const QString &formatString, bool *ok, Locale::DateTimeFormatStandard formatStandard) const { - KDateTimeParser parser; - QDate resultDate = parser.parseDate(inputString, formatString, this, locale(), locale()->dateTimeDigitSet(), formatStandard); - if (ok) { - *ok = resultDate.isValid(); - } - return resultDate; + return m_calendarSystem->readDate(inputString, formatString, ok, + (KLocale::DateTimeFormatStandard)formatStandard); } // NOT VIRTUAL - If override needed use shared-d int CalendarSystem::shortYearWindowStartYear() const { - Q_D(const KCalendarSystem); - - return d->shortYearWindowStartYear(); + return m_calendarSystem->shortYearWindowStartYear(); } // NOT VIRTUAL - If override needed use shared-d int CalendarSystem::applyShortYearWindow(int inputYear) const { - Q_D(const KCalendarSystem); - - return d->applyShortYearWindow(inputYear); + return m_calendarSystem->applyShortYearWindow(inputYear); } int CalendarSystem::weekStartDay() const { - return locale()->weekStartDay(); + return m_calendarSystem->weekStartDay(); } // Dummy version using Gregorian as an example @@ -2378,28 +549,7 @@ int CalendarSystem::weekStartDay() const // are required for internal maths bool CalendarSystem::julianDayToDate(int jd, int &year, int &month, int &day) const { - // Formula from The Calendar FAQ by Claus Tondering - // http://www.tondering.dk/claus/cal/node3.html#SECTION003161000000000000000 - // NOTE: Coded from scratch from mathematical formulas, not copied from - // the Boost licensed source code - - int a = jd + 32044; - int b = ((4 * a) + 3) / 146097; - int c = a - ((146097 * b) / 4); - int d = ((4 * c) + 3) / 1461; - int e = c - ((1461 * d) / 4); - int m = ((5 * e) + 2) / 153; - day = e - (((153 * m) + 2) / 5) + 1; - month = m + 3 - (12 * (m / 10)); - year = (100 * b) + d - 4800 + (m / 10); - - // If year is -ve then is BC. In Gregorian there is no year 0, but the maths - // is easier if we pretend there is, so internally year of 0 = 1BC = -1 outside - if (year < 1) { - year = year - 1; - } - - return true; + return m_calendarSystem->julianDayToDate(jd, year, month, day); } // Dummy version using Gregorian as an example @@ -2410,56 +560,13 @@ bool CalendarSystem::julianDayToDate(int jd, int &year, int &month, int &day) co // are required for internal maths bool CalendarSystem::dateToJulianDay(int year, int month, int day, int &jd) const { - // Formula from The Calendar FAQ by Claus Tondering - // http://www.tondering.dk/claus/cal/node3.html#SECTION003161000000000000000 - // NOTE: Coded from scratch from mathematical formulas, not copied from - // the Boost licensed source code - - // If year is -ve then is BC. In Gregorian there is no year 0, but the maths - // is easier if we pretend there is, so internally year of -1 = 1BC = 0 internally - int y; - if (year < 1) { - y = year + 1; - } else { - y = year; - } - - int a = (14 - month) / 12; - y = y + 4800 - a; - int m = month + (12 * a) - 3; - - jd = day - + (((153 * m) + 2) / 5) - + (365 * y) - + (y / 4) - - (y / 100) - + (y / 400) - - 32045; - - return true; + return m_calendarSystem->dateToJulianDay(year, month, day, jd); } -const KLocale * CalendarSystem::locale() const +//FIXME what should I do with the above one? +/*const KLocale * CalendarSystem::locale() const { Q_D(const KCalendarSystem); return d->locale(); -} - -// Deprecated -void CalendarSystem::setMaxMonthsInYear(int maxMonths) -{ - Q_UNUSED(maxMonths) -} - -// Deprecated -void CalendarSystem::setMaxDaysInWeek(int maxDays) -{ - Q_UNUSED(maxDays) -} - -// Deprecated -void CalendarSystem::setHasYear0(bool hasYear0) -{ - Q_UNUSED(hasYear0) -} +}*/