File indexing completed on 2025-01-05 03:52:00

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