KDECore
klocalizeddate.h
Go to the documentation of this file.
00001 /* 00002 Copyright 2010 John Layt <john@layt.net> 00003 00004 This library is free software; you can redistribute it and/or 00005 modify it under the terms of the GNU Library General Public 00006 License as published by the Free Software Foundation; either 00007 version 2 of the License, or (at your option) any later version. 00008 00009 This library is distributed in the hope that it will be useful, 00010 but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00012 Library General Public License for more details. 00013 00014 You should have received a copy of the GNU Library General Public License 00015 along with this library; see the file COPYING.LIB. If not, write to 00016 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00017 Boston, MA 02110-1301, USA. 00018 */ 00019 00020 #ifndef KDATE_H 00021 #define KDATE_H 00022 00023 #include <QtCore/QString> 00024 #include <QtCore/QDate> 00025 00026 #include <kdecore_export.h> 00027 #include "kcalendarsystem.h" 00028 #include "klocale.h" 00029 00030 class KLocalizedDatePrivate; 00138 class KDECORE_EXPORT KLocalizedDate 00139 { 00140 public: 00141 00156 explicit KLocalizedDate(const QDate &date = QDate(), const KCalendarSystem *calendar = 0); 00157 00173 KLocalizedDate(int year, int month, int day, const KCalendarSystem *calendar = 0); 00174 00180 KLocalizedDate(const KLocalizedDate &rhs); 00181 00187 KLocalizedDate &operator=(const KLocalizedDate &rhs); 00188 00194 KLocalizedDate &operator=(const QDate &rhs); 00195 00199 ~KLocalizedDate(); 00200 00219 void setCalendarSystem(KLocale::CalendarSystem calendarSystem); 00220 00228 KLocale::CalendarSystem calendarSystem(); 00229 00244 const KCalendarSystem *calendar() const; 00245 00252 bool isNull() const; 00253 00260 bool isValid() const; 00261 00268 bool setDate(const QDate &date); 00269 00282 bool setDate(int year, int month, int day); 00283 00292 bool setDate(int year, int dayOfYear); 00293 00305 bool setDate(QString eraName, int yearInEra, int month, int day); 00306 00320 bool setDate(KLocale::WeekNumberSystem weekNumberSystem, int year, int weekOfYear, int dayOfWeek); 00321 00328 bool setCurrentDate(); 00329 00337 static KLocalizedDate currentDate(); 00338 00346 static KLocalizedDate fromDate(const QDate &date); 00347 00356 static KLocalizedDate fromJulianDay(int jd); 00357 00364 int toJulianDay() const; 00365 00371 QDate date() const; 00372 00385 void getDate(int *year, int *month, int *day) const; 00386 00395 int year() const; 00396 00405 int month() const; 00406 00415 int day() const; 00416 00427 QString eraName() const; 00428 00439 QString eraYear() const; 00440 00451 int yearInEra() const; 00452 00463 int dayOfYear() const; 00464 00477 int dayOfWeek() const; 00478 00502 int week(int *yearNum = 0) const; 00503 00525 int week(KLocale::WeekNumberSystem weekNumberSystem, int *yearNum = 0) const; 00526 00535 int monthsInYear() const; 00536 00552 int weeksInYear() const; 00553 00568 int weeksInYear(KLocale::WeekNumberSystem weekNumberSystem) const; 00569 00581 int daysInYear() const; 00582 00591 int daysInMonth() const; 00592 00601 int daysInWeek() const; 00602 00609 bool isLeapYear() const; 00610 00622 QString formatDate(KLocale::DateFormat dateFormat = KLocale::LongDate) const; 00623 00735 QString formatDate(const QString &formatString, 00736 KLocale::DateTimeFormatStandard formatStandard = KLocale::KdeFormat) const; 00737 00760 QString formatDate(KLocale::DateTimeComponent component, 00761 KLocale::DateTimeComponentFormat format = KLocale::DefaultComponentFormat, 00762 KLocale::WeekNumberSystem weekNumberSystem = KLocale::DefaultWeekNumber) const; 00763 00782 static KLocalizedDate readDate(const QString &dateString, 00783 KLocale::DateTimeParseMode parseMode = KLocale::LiberalParsing, 00784 const KCalendarSystem *calendar = 0); 00785 00804 static KLocalizedDate readDate(const QString &dateString, 00805 KLocale::ReadDateFlags formatFlags, 00806 KLocale::DateTimeParseMode parseMode = KLocale::LiberalParsing, 00807 const KCalendarSystem *calendar = 0); 00808 00828 static KLocalizedDate readDate(const QString &dateString, 00829 const QString &dateFormat, 00830 KLocale::DateTimeParseMode parseMode = KLocale::LiberalParsing, 00831 KLocale::DateTimeFormatStandard formatStandard = KLocale::KdeFormat, 00832 const KCalendarSystem *calendar = 0); 00833 00843 KLocalizedDate addYears(int years) const; 00844 00857 bool addYearsTo(int years); 00858 00868 KLocalizedDate addMonths(int months) const; 00869 00882 bool addMonthsTo(int months); 00883 00893 KLocalizedDate addDays(int days) const; 00894 00907 bool addDaysTo(int days); 00908 00932 void dateDifference(const KLocalizedDate &toDate, 00933 int *yearsDiff, int *monthsDiff, int *daysDiff, int *direction) const; 00934 00958 void dateDifference(const QDate &toDate, 00959 int *yearsDiff, int *monthsDiff, int *daysDiff, int *direction) const; 00960 00974 int yearsDifference(const KLocalizedDate &toDate) const; 00975 00989 int yearsDifference(const QDate &toDate) const; 00990 01006 int monthsDifference(const KLocalizedDate &toDate) const; 01007 01023 int monthsDifference(const QDate &toDate) const; 01024 01034 int daysDifference(const KLocalizedDate &toDate) const; 01035 01045 int daysDifference(const QDate &toDate) const; 01046 01053 KLocalizedDate firstDayOfYear() const; 01054 01061 KLocalizedDate lastDayOfYear() const; 01062 01069 KLocalizedDate firstDayOfMonth() const; 01070 01077 KLocalizedDate lastDayOfMonth() const; 01078 01084 bool operator==(const KLocalizedDate &other) const; 01085 01091 bool operator==(const QDate &other) const; 01092 01098 bool operator!=(const KLocalizedDate &other) const; 01099 01105 bool operator!=(const QDate &other) const; 01106 01112 bool operator<(const KLocalizedDate &other) const; 01113 01119 bool operator<(const QDate &other) const; 01120 01126 bool operator<=(const KLocalizedDate &other) const; 01127 01133 bool operator<=(const QDate &other) const; 01134 01140 bool operator>(const KLocalizedDate &other) const; 01141 01147 bool operator>(const QDate &other) const; 01148 01154 bool operator>=(const KLocalizedDate &other) const; 01155 01161 bool operator>=(const QDate &other) const; 01162 01163 private: 01164 01165 friend QDataStream KDECORE_EXPORT &operator<<(QDataStream &out, const KLocalizedDate &date); 01166 friend QDataStream KDECORE_EXPORT &operator>>(QDataStream &in, KLocalizedDate &date); 01167 friend QDebug KDECORE_EXPORT operator<<(QDebug, const KLocalizedDate &); 01168 01169 QSharedDataPointer<KLocalizedDatePrivate> d; 01170 }; 01171 01172 Q_DECLARE_METATYPE(KLocalizedDate) 01173 01174 01179 QDataStream KDECORE_EXPORT &operator<<(QDataStream &out, const KLocalizedDate &date); 01180 01186 QDataStream KDECORE_EXPORT &operator>>(QDataStream &in, KLocalizedDate &date); 01187 01193 QDebug KDECORE_EXPORT operator<<(QDebug, const KLocalizedDate &); 01194 01195 #endif // KDATE_H
KDE 4.6 API Reference