File indexing completed on 2024-12-01 03:39:59

0001 /*
0002     This file is part of the kholidays library.
0003 
0004     SPDX-FileCopyrightText: 2014 John Layt <john@layt.net>
0005 
0006     SPDX-License-Identifier: LGPL-2.0-or-later
0007 */
0008 
0009 #ifndef QCALENDARSYSTEM_H
0010 #define QCALENDARSYSTEM_H
0011 
0012 #include <QDate>
0013 #include <QSharedPointer>
0014 
0015 class QCalendarSystemPrivate;
0016 
0017 class QCalendarSystem
0018 {
0019 public:
0020     enum CalendarSystem {
0021         DefaultCalendar = 0,
0022         GregorianCalendar = 1,
0023         ChineseCalendar = 2,
0024         CopticCalendar = 3,
0025         EthiopicCalendar = 4,
0026         EthiopicAmeteAlemCalendar = 5,
0027         HebrewCalendar = 6,
0028         IndianNationalCalendar = 7,
0029         IslamicCalendar = 8,
0030         IslamicCivilCalendar = 9,
0031         ISO8601Calendar = 10,
0032         JapaneseCalendar = 11,
0033         JulianCalendar = 12,
0034         PersianCalendar = 13,
0035         ROCCalendar = 14,
0036         ThaiCalendar = 15,
0037         LastCalendar = ThaiCalendar,
0038     };
0039 
0040     explicit QCalendarSystem(QCalendarSystem::CalendarSystem calendar = QCalendarSystem::DefaultCalendar);
0041     ~QCalendarSystem();
0042 
0043     QCalendarSystem &operator=(const QCalendarSystem &other);
0044 
0045     QCalendarSystem::CalendarSystem calendarSystem() const;
0046 
0047     QDate epoch() const;
0048     QDate earliestValidDate() const;
0049     QDate latestValidDate() const;
0050     int maximumMonthsInYear() const;
0051     int maximumDaysInYear() const;
0052     int maximumDaysInMonth() const;
0053 
0054     bool isValid(const QDate &date) const;
0055     bool isValid(int year, int month, int day) const;
0056     bool isValid(int year, int dayOfYear) const;
0057 
0058     QDate date(int year, int month, int day) const;
0059     QDate date(int year, int dayOfYear) const;
0060 
0061     void getDate(const QDate &date, int *year, int *month, int *day) const;
0062 
0063     int year(const QDate &date) const;
0064     int month(const QDate &date) const;
0065     int day(const QDate &date) const;
0066 
0067     int quarter(const QDate &date) const;
0068     int quarter(int year, int month, int day) const;
0069 
0070     int dayOfYear(const QDate &date) const;
0071     int dayOfYear(int year, int month, int day) const;
0072 
0073     int dayOfWeek(const QDate &date) const;
0074     int dayOfWeek(int year, int month, int day) const;
0075 
0076     int weekNumber(const QDate &date, int *yearNum = nullptr) const;
0077     int weekNumber(int year, int month, int day, int *yearNum = nullptr) const;
0078 
0079     int monthsInYear(const QDate &date) const;
0080     int monthsInYear(int year) const;
0081 
0082     int weeksInYear(const QDate &date) const;
0083     int weeksInYear(int year) const;
0084 
0085     int daysInYear(const QDate &date) const;
0086     int daysInYear(int year) const;
0087 
0088     int daysInMonth(const QDate &date) const;
0089     int daysInMonth(int year, int month) const;
0090 
0091     int daysInWeek() const;
0092 
0093     bool isLeapYear(const QDate &date) const;
0094     bool isLeapYear(int year) const;
0095 
0096     QDate addYears(const QDate &date, int years) const;
0097     QDate addMonths(const QDate &date, int months) const;
0098     QDate addDays(const QDate &date, int days) const;
0099 
0100     int yearsDifference(const QDate &fromDate, const QDate &toDate) const;
0101     int monthsDifference(const QDate &fromDate, const QDate &toDate) const;
0102     qint64 daysDifference(const QDate &fromDate, const QDate &toDate) const;
0103 
0104     void dateDifference(const QDate &fromDate, const QDate &toDate, int *years, int *months, int *days, int *direction) const;
0105 
0106     QDate firstDayOfYear(const QDate &date) const;
0107     QDate firstDayOfYear(int year) const;
0108     QDate lastDayOfYear(const QDate &date) const;
0109     QDate lastDayOfYear(int year) const;
0110 
0111     QDate firstDayOfMonth(const QDate &date) const;
0112     QDate firstDayOfMonth(int year, int month) const;
0113     QDate lastDayOfMonth(const QDate &date) const;
0114     QDate lastDayOfMonth(int year, int month) const;
0115 
0116 private:
0117     QSharedDataPointer<QCalendarSystemPrivate> d;
0118 };
0119 
0120 #endif // QCALENDARSYSTEM_H