KDELibs4Support

klocalizeddate.h
1 /*
2  Copyright 2010 John Layt <[email protected]>
3 
4  This library is free software; you can redistribute it and/or
5  modify it under the terms of the GNU Library General Public
6  License as published by the Free Software Foundation; either
7  version 2 of the License, or (at your option) any later version.
8 
9  This library is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  Library General Public License for more details.
13 
14  You should have received a copy of the GNU Library General Public License
15  along with this library; see the file COPYING.LIB. If not, write to
16  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17  Boston, MA 02110-1301, USA.
18 */
19 
20 #ifndef KLOCALIZEDDATE_H
21 #define KLOCALIZEDDATE_H
22 
23 #include <QString>
24 #include <QDate>
25 
26 #include <kdelibs4support_export.h>
27 #include "klocale.h"
28 
29 class KLocalizedDatePrivate;
137 class KDELIBS4SUPPORT_EXPORT KLocalizedDate
138 {
139 public:
140 
155  KDELIBS4SUPPORT_DEPRECATED explicit KLocalizedDate(const QDate &date = QDate(), const KCalendarSystem *calendar = nullptr);
156 
173  KLocalizedDate(int year, int month, int day, const KCalendarSystem *calendar = nullptr);
174 
180  KLocalizedDate(const KLocalizedDate &rhs);
181 
187  KLocalizedDate &operator=(const KLocalizedDate &rhs);
188 
194  KLocalizedDate &operator=(const QDate &rhs);
195 
199  ~KLocalizedDate();
200 
219  void setCalendarSystem(KLocale::CalendarSystem calendarSystem);
220 
228  KLocale::CalendarSystem calendarSystem();
229 
244  const KCalendarSystem *calendar() const;
245 
252  bool isNull() const;
253 
260  bool isValid() const;
261 
268  bool setDate(const QDate &date);
269 
282  bool setDate(int year, int month, int day);
283 
292  bool setDate(int year, int dayOfYear);
293 
305  bool setDate(QString eraName, int yearInEra, int month, int day);
306 
320  bool setDate(KLocale::WeekNumberSystem weekNumberSystem, int year, int weekOfYear, int dayOfWeek);
321 
328  bool setCurrentDate();
329 
337  static KLocalizedDate currentDate();
338 
346  static KLocalizedDate fromDate(const QDate &date);
347 
356  static KLocalizedDate fromJulianDay(int jd);
357 
364  int toJulianDay() const;
365 
371  QDate date() const;
372 
385  void getDate(int *year, int *month, int *day) const;
386 
395  int year() const;
396 
405  int month() const;
406 
415  int day() const;
416 
426  QString eraName() const;
427 
437  QString eraYear() const;
438 
449  int yearInEra() const;
450 
461  int dayOfYear() const;
462 
475  int dayOfWeek() const;
476 
495  int week(int *yearNum = nullptr) const;
496 
518  int week(KLocale::WeekNumberSystem weekNumberSystem, int *yearNum = nullptr) const;
519 
528  int monthsInYear() const;
529 
542  int weeksInYear() const;
543 
558  int weeksInYear(KLocale::WeekNumberSystem weekNumberSystem) const;
559 
571  int daysInYear() const;
572 
581  int daysInMonth() const;
582 
591  int daysInWeek() const;
592 
599  bool isLeapYear() const;
600 
612  QString formatDate(KLocale::DateFormat dateFormat = KLocale::LongDate) const;
613 
725  QString formatDate(const QString &formatString,
726  KLocale::DateTimeFormatStandard formatStandard = KLocale::KdeFormat) const;
727 
750  QString formatDate(KLocale::DateTimeComponent component,
752  KLocale::WeekNumberSystem weekNumberSystem = KLocale::DefaultWeekNumber) const;
753 
772  static KLocalizedDate readDate(const QString &dateString,
774  const KCalendarSystem *calendar = nullptr);
775 
794  static KLocalizedDate readDate(const QString &dateString,
795  KLocale::ReadDateFlags formatFlags,
797  const KCalendarSystem *calendar = nullptr);
798 
818  static KLocalizedDate readDate(const QString &dateString,
819  const QString &dateFormat,
822  const KCalendarSystem *calendar = nullptr);
823 
833  KLocalizedDate addYears(int years) const;
834 
847  bool addYearsTo(int years);
848 
858  KLocalizedDate addMonths(int months) const;
859 
872  bool addMonthsTo(int months);
873 
883  KLocalizedDate addDays(int days) const;
884 
897  bool addDaysTo(int days);
898 
922  void dateDifference(const KLocalizedDate &toDate,
923  int *yearsDiff, int *monthsDiff, int *daysDiff, int *direction) const;
924 
948  void dateDifference(const QDate &toDate,
949  int *yearsDiff, int *monthsDiff, int *daysDiff, int *direction) const;
950 
964  int yearsDifference(const KLocalizedDate &toDate) const;
965 
979  int yearsDifference(const QDate &toDate) const;
980 
996  int monthsDifference(const KLocalizedDate &toDate) const;
997 
1013  int monthsDifference(const QDate &toDate) const;
1014 
1024  int daysDifference(const KLocalizedDate &toDate) const;
1025 
1035  int daysDifference(const QDate &toDate) const;
1036 
1043  KLocalizedDate firstDayOfYear() const;
1044 
1051  KLocalizedDate lastDayOfYear() const;
1052 
1059  KLocalizedDate firstDayOfMonth() const;
1060 
1067  KLocalizedDate lastDayOfMonth() const;
1068 
1074  bool operator==(const KLocalizedDate &other) const;
1075 
1081  bool operator==(const QDate &other) const;
1082 
1088  bool operator!=(const KLocalizedDate &other) const;
1089 
1095  bool operator!=(const QDate &other) const;
1096 
1102  bool operator<(const KLocalizedDate &other) const;
1103 
1109  bool operator<(const QDate &other) const;
1110 
1116  bool operator<=(const KLocalizedDate &other) const;
1117 
1123  bool operator<=(const QDate &other) const;
1124 
1130  bool operator>(const KLocalizedDate &other) const;
1131 
1137  bool operator>(const QDate &other) const;
1138 
1144  bool operator>=(const KLocalizedDate &other) const;
1145 
1151  bool operator>=(const QDate &other) const;
1152 
1153 private:
1154 
1155  friend QDataStream KDELIBS4SUPPORT_EXPORT &operator<<(QDataStream &out, const KLocalizedDate &date);
1156  friend QDataStream KDELIBS4SUPPORT_EXPORT &operator>>(QDataStream &in, KLocalizedDate &date);
1157  friend QDebug KDELIBS4SUPPORT_EXPORT operator<<(QDebug, const KLocalizedDate &);
1158 
1160 };
1161 
1162 Q_DECLARE_METATYPE(KLocalizedDate)
1163 
1164 
1170 QDataStream KDELIBS4SUPPORT_EXPORT &operator<<(QDataStream &out, const KLocalizedDate &date);
1171 
1178 QDataStream KDELIBS4SUPPORT_EXPORT &operator>>(QDataStream &in, KLocalizedDate &date);
1179 
1186 QDebug KDELIBS4SUPPORT_EXPORT operator<<(QDebug debug, const KLocalizedDate &date);
1187 
1188 #endif // KLOCALIZEDDATE_H
QDataStream & operator>>(QDataStream &in, KDateTime::Spec &spec)
Read a KDateTime::Spec object into spec from in, in binary format.
Definition: kdatetime.cpp:296
DateFormat
Format for date string.
Definition: klocale.h:783
Parse Date/Time liberally.
Definition: klocale.h:706
The system locale default for the componant.
Definition: klocale.h:771
KCalendarSystem abstract base class, provides support for local Calendar Systems in KDE...
DateTimeComponentFormat
Definition: klocale.h:770
CalendarSystem
Definition: klocale.h:646
A class representing a date localized using the local calendar system, language and formats...
WeekNumberSystem
Definition: klocale.h:681
ReadDateFlags
Flags for readDate()
Definition: klocale.h:1108
DateTimeComponent
Definition: klocale.h:728
KDE Standard.
Definition: klocale.h:695
The system locale default.
Definition: klocale.h:682
QDataStream & operator<<(QDataStream &out, const KDateTime::Spec &spec)
Write spec to the datastream out, in binary format.
Definition: kdatetime.cpp:271
DateTimeFormatStandard
Definition: klocale.h:694
Locale Long date format, e.g.
Definition: klocale.h:785
DateTimeParseMode
Definition: klocale.h:705
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Wed Jul 8 2020 22:57:11 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.