File indexing completed on 2023-09-24 04:04:45
0001 /* 0002 Copyright 2010 John Layt <john@layt.net> 0003 0004 This library is free software; you can redistribute it and/or 0005 modify it under the terms of the GNU Library General Public 0006 License as published by the Free Software Foundation; either 0007 version 2 of the License, or (at your option) any later version. 0008 0009 This library is distributed in the hope that it will be useful, 0010 but WITHOUT ANY WARRANTY; without even the implied warranty of 0011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0012 Library General Public License for more details. 0013 0014 You should have received a copy of the GNU Library General Public License 0015 along with this library; see the file COPYING.LIB. If not, write to 0016 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0017 Boston, MA 02110-1301, USA. 0018 */ 0019 0020 #ifndef KCALENDARSYSTEMPRIVATE_H 0021 #define KCALENDARSYSTEMPRIVATE_H 0022 0023 class QChar; 0024 class QString; 0025 class QDate; 0026 0027 class KCalendarSystem; 0028 class KCalendarEra; 0029 class KLocale; 0030 0031 class KCalendarSystemPrivate 0032 { 0033 public: 0034 KDELIBS4SUPPORT_DEPRECATED explicit KCalendarSystemPrivate(KCalendarSystem *q); 0035 0036 virtual ~KCalendarSystemPrivate(); 0037 0038 // Virtual methods each calendar system must re-implement 0039 virtual void loadDefaultEraList() = 0; 0040 virtual int monthsInYear(int year) const = 0; 0041 virtual int daysInMonth(int year, int month) const = 0; 0042 virtual int daysInYear(int year) const = 0; 0043 virtual bool isLeapYear(int year) const = 0; 0044 virtual bool hasLeapMonths() const = 0; 0045 virtual bool hasYearZero() const = 0; 0046 virtual int maxMonthsInYear() const = 0; 0047 virtual int earliestValidYear() const = 0; 0048 virtual int latestValidYear() const = 0; 0049 virtual QString monthName(int month, int year, KLocale::DateTimeComponentFormat format, bool possessive = false) const = 0; 0050 virtual QString weekDayName(int weekDay, KLocale::DateTimeComponentFormat format) const = 0; 0051 0052 // Virtual methods to re-implement if special maths needed 0053 // Currently only Hebrew may need special conversion, rest should be OK 0054 virtual int yearsDifference(const QDate &fromDate, const QDate &toDate) const; 0055 virtual int monthsDifference(const QDate &fromDate, const QDate &toDate) const; 0056 virtual void dateDifference(const QDate &fromDate, const QDate &toDate, 0057 int *yearsDiff, int *monthsDiff, int *daysDiff, int *direction) const; 0058 0059 // Virtual methods to re-implement if special number/string conversion needed 0060 // Currently only Hebrew needs special conversion, rest use KLocale DigitSet 0061 virtual int integerFromString(const QString &string, int maxLength, int &readLength) const; 0062 virtual QString stringFromInteger(int number, int padWidth = 0, QChar padChar = QLatin1Char('0')) const; 0063 virtual QString stringFromInteger(int number, int padWidth, QChar padChar, KLocale::DigitSet digitSet) const; 0064 0065 // Utility functions 0066 int addYears(int startYear, int yearsToAdd) const; 0067 int differenceYearNumbers(int fromYear, int toYear) const; 0068 QString simpleDateString(const QString &str) const; 0069 int daysInWeek() const; 0070 int dayOfYear(const QDate &date) const; 0071 int dayOfWeek(const QDate &date) const; 0072 QDate firstDayOfYear(int year) const; 0073 QDate lastDayOfYear(int year) const; 0074 QDate firstDayOfMonth(int year, int month) const; 0075 QDate lastDayOfMonth(int year, int month) const; 0076 const KLocale *locale() const; 0077 void loadEraList(const KConfigGroup &cg); 0078 void addEra(char direction, int offset, const QDate &startDate, int startYear, const QDate &endDate, 0079 const QString &name, const QString &shortName, const QString &format); 0080 QList<KCalendarEra> *eraList() const; 0081 KCalendarEra era(const QDate &eraDate) const; 0082 KCalendarEra era(const QString &eraName, int yearInEra) const; 0083 int shortYearWindowStartYear() const; 0084 int applyShortYearWindow(int inputYear) const; 0085 void loadShortYearWindowStartYear(const KConfigGroup &cg); 0086 KSharedConfig::Ptr config(); 0087 void loadConfig(const QString &calendarType); 0088 0089 // Week utility functions 0090 int isoWeekNumber(const QDate &date, int *yearNum) const; 0091 int regularWeekNumber(const QDate &date, int weekStartDay, int firstWeekNumber, int *weekYear) const; 0092 int simpleWeekNumber(const QDate &date, int *yearNum) const; 0093 int isoWeeksInYear(int year) const; 0094 int regularWeeksInYear(int year, int weekStartDay, int firstWeekNumber) const; 0095 int simpleWeeksInYear(int year) const; 0096 0097 // Global variables each calendar system must initialise 0098 const KCalendarSystem *q; 0099 const KLocale *m_locale; 0100 KSharedConfig::Ptr m_config; 0101 QList<KCalendarEra> *m_eraList; 0102 int m_shortYearWindowStartYear; 0103 }; 0104 0105 #endif // KCALENDARSYSTEMPRIVATE_H