digiKam
calsystem.h
Go to the documentation of this file.
1 /* ============================================================
2  *
3  * This file is a part of digiKam project
4  * https://www.digikam.org
5  *
6  * Date : 2014-11-03
7  * Description : calendar system.
8  *
9  * Copyright (C) 2014 by John Layt <john at layt dot net>
10  * Copyright (C) 2016-2022 by Gilles Caulier <caulier dot gilles at gmail dot com>
11  *
12  * This program is free software; you can redistribute it
13  * and/or modify it under the terms of the GNU General
14  * Public License as published by the Free Software Foundation;
15  * either version 2, or (at your option) any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20  * GNU General Public License for more details.
21  *
22  * ============================================================ */
23 
24 #ifndef DIGIKAM_CAL_SYSTEM_H
25 #define DIGIKAM_CAL_SYSTEM_H
26 
27 // Qt includes
28 
29 #include <QSharedPointer>
30 #include <QDate>
31 
33 {
34 
35 class CalSystemPrivate;
36 
37 class CalSystem
38 {
39 public:
40 
42  {
60  };
61 
62 public:
63 
65  ~CalSystem();
66 
67  CalSystem& operator=(const CalSystem& other);
68 
69 public:
70 
72 
73  QDate epoch() const;
74  QDate earliestValidDate() const;
75  QDate latestValidDate() const;
76  int maximumMonthsInYear() const;
77  int maximumDaysInYear() const;
78  int maximumDaysInMonth() const;
79 
80  bool isValid(const QDate& date) const;
81  bool isValid(int year, int month, int day) const;
82  bool isValid(int year, int dayOfYear) const;
83 
84  QDate date(int year, int month, int day) const;
85  QDate date(int year, int dayOfYear) const;
86 
87  void getDate(const QDate& date, int* year, int* month, int* day) const;
88 
89  int year(const QDate& date) const;
90  int month(const QDate& date) const;
91  int day(const QDate& date) const;
92 
93  int quarter(const QDate& date) const;
94  int quarter(int year, int month, int day) const;
95 
96  int dayOfYear(const QDate& date) const;
97  int dayOfYear(int year, int month, int day) const;
98 
99  int dayOfWeek(const QDate& date) const;
100  int dayOfWeek(int year, int month, int day) const;
101 
102  int weekNumber(const QDate& date, int* yearNum = nullptr) const;
103  int weekNumber(int year, int month, int day, int* yearNum = nullptr) const;
104 
105  int monthsInYear(const QDate& date) const;
106  int monthsInYear(int year) const;
107 
108  int weeksInYear(const QDate& date) const;
109  int weeksInYear(int year) const;
110 
111  int daysInYear(const QDate& date) const;
112  int daysInYear(int year) const;
113 
114  int daysInMonth(const QDate& date) const;
115  int daysInMonth(int year, int month) const;
116 
117  int daysInWeek() const;
118 
119  bool isLeapYear(const QDate& date) const;
120  bool isLeapYear(int year) const;
121 
122  QDate addYears(const QDate& date, int years) const;
123  QDate addMonths(const QDate& date, int months) const;
124  QDate addDays(const QDate& date, int days) const;
125 
126  int yearsDifference(const QDate& fromDate, const QDate& toDate) const;
127  int monthsDifference(const QDate& fromDate, const QDate& toDate) const;
128  qint64 daysDifference(const QDate& fromDate, const QDate& toDate) const;
129 
130  bool dateDifference(const QDate& fromDate, const QDate& toDate,
131  int* years, int* months, int* days, int* direction) const;
132 
133  QDate firstDayOfYear(const QDate& date) const;
134  QDate firstDayOfYear(int year) const;
135  QDate lastDayOfYear(const QDate& date) const;
136  QDate lastDayOfYear(int year) const;
137 
138  QDate firstDayOfMonth(const QDate& date) const;
139  QDate firstDayOfMonth(int year, int month) const;
140  QDate lastDayOfMonth(const QDate& date) const;
141  QDate lastDayOfMonth(int year, int month) const;
142 
143 private:
144 
145  QSharedDataPointer<CalSystemPrivate> d;
146 };
147 
148 } // Namespace Digikam
149 
150 #endif // DIGIKAM_CAL_SYSTEM_H
Definition: calsystem.h:38
int dayOfYear(const QDate &date) const
Definition: calsystem.cpp:987
QDate addDays(const QDate &date, int days) const
Definition: calsystem.cpp:1318
int weeksInYear(const QDate &date) const
Definition: calsystem.cpp:1139
QDate addMonths(const QDate &date, int months) const
Definition: calsystem.cpp:1271
bool isLeapYear(const QDate &date) const
Definition: calsystem.cpp:1230
QDate lastDayOfYear(const QDate &date) const
Definition: calsystem.cpp:1556
int daysInYear(const QDate &date) const
Definition: calsystem.cpp:1174
QDate lastDayOfMonth(const QDate &date) const
Definition: calsystem.cpp:1595
QDate firstDayOfYear(const QDate &date) const
Definition: calsystem.cpp:1539
int yearsDifference(const QDate &fromDate, const QDate &toDate) const
Definition: calsystem.cpp:1326
CalSystem::CalendarSystem calendarSystem() const
Definition: calsystem.cpp:813
QDate date(int year, int month, int day) const
Definition: calsystem.cpp:875
void getDate(const QDate &date, int *year, int *month, int *day) const
Definition: calsystem.cpp:899
CalSystem(CalSystem::CalendarSystem calendar=CalSystem::DefaultCalendar)
Definition: calsystem.cpp:797
int year(const QDate &date) const
Definition: calsystem.cpp:924
int weekNumber(const QDate &date, int *yearNum=nullptr) const
Definition: calsystem.cpp:1031
CalendarSystem
Definition: calsystem.h:42
@ GregorianCalendar
Definition: calsystem.h:44
@ CopticCalendar
Definition: calsystem.h:46
@ ISO8601Calendar
Definition: calsystem.h:53
@ HebrewCalendar
Definition: calsystem.h:49
@ JapaneseCalendar
Definition: calsystem.h:54
@ IslamicCalendar
Definition: calsystem.h:51
@ LastCalendar
Definition: calsystem.h:59
@ IndianNationalCalendar
Definition: calsystem.h:50
@ JulianCalendar
Definition: calsystem.h:55
@ PersianCalendar
Definition: calsystem.h:56
@ EthiopicCalendar
Definition: calsystem.h:47
@ ROCCalendar
Definition: calsystem.h:57
@ DefaultCalendar
Definition: calsystem.h:43
@ ChineseCalendar
Definition: calsystem.h:45
@ EthiopicAmeteAlemCalendar
Definition: calsystem.h:48
@ IslamicCivilCalendar
Definition: calsystem.h:52
@ ThaiCalendar
Definition: calsystem.h:58
QDate firstDayOfMonth(const QDate &date) const
Definition: calsystem.cpp:1582
QDate epoch() const
Definition: calsystem.cpp:818
int maximumDaysInMonth() const
Definition: calsystem.cpp:843
int monthsDifference(const QDate &fromDate, const QDate &toDate) const
Definition: calsystem.cpp:1374
bool dateDifference(const QDate &fromDate, const QDate &toDate, int *years, int *months, int *days, int *direction) const
Definition: calsystem.cpp:1439
int quarter(const QDate &date) const
Definition: calsystem.cpp:960
QDate addYears(const QDate &date, int years) const
Definition: calsystem.cpp:1254
int maximumDaysInYear() const
Definition: calsystem.cpp:838
CalSystem & operator=(const CalSystem &other)
Definition: calsystem.cpp:806
int daysInWeek() const
Definition: calsystem.cpp:1225
~CalSystem()
Definition: calsystem.cpp:802
QDate latestValidDate() const
Definition: calsystem.cpp:828
int monthsInYear(const QDate &date) const
Definition: calsystem.cpp:1115
int daysInMonth(const QDate &date) const
Definition: calsystem.cpp:1198
int dayOfWeek(const QDate &date) const
Definition: calsystem.cpp:1004
int day(const QDate &date) const
Definition: calsystem.cpp:948
QDate earliestValidDate() const
Definition: calsystem.cpp:823
bool isValid(const QDate &date) const
Definition: calsystem.cpp:848
int maximumMonthsInYear() const
Definition: calsystem.cpp:833
int month(const QDate &date) const
Definition: calsystem.cpp:936
qint64 daysDifference(const QDate &fromDate, const QDate &toDate) const
Definition: calsystem.cpp:1424
Definition: calendarplugin.cpp:38