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 KLOCALIZEDDATE_H 00021 #define KLOCALIZEDDATE_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 00174 KLocalizedDate(int year, int month, int day, const KCalendarSystem *calendar = 0); 00175 00181 KLocalizedDate(const KLocalizedDate &rhs); 00182 00188 KLocalizedDate &operator=(const KLocalizedDate &rhs); 00189 00195 KLocalizedDate &operator=(const QDate &rhs); 00196 00200 ~KLocalizedDate(); 00201 00220 void setCalendarSystem(KLocale::CalendarSystem calendarSystem); 00221 00229 KLocale::CalendarSystem calendarSystem(); 00230 00245 const KCalendarSystem *calendar() const; 00246 00253 bool isNull() const; 00254 00261 bool isValid() const; 00262 00269 bool setDate(const QDate &date); 00270 00283 bool setDate(int year, int month, int day); 00284 00293 bool setDate(int year, int dayOfYear); 00294 00306 bool setDate(QString eraName, int yearInEra, int month, int day); 00307 00321 bool setDate(KLocale::WeekNumberSystem weekNumberSystem, int year, int weekOfYear, int dayOfWeek); 00322 00329 bool setCurrentDate(); 00330 00338 static KLocalizedDate currentDate(); 00339 00347 static KLocalizedDate fromDate(const QDate &date); 00348 00357 static KLocalizedDate fromJulianDay(int jd); 00358 00365 int toJulianDay() const; 00366 00372 QDate date() const; 00373 00386 void getDate(int *year, int *month, int *day) const; 00387 00396 int year() const; 00397 00406 int month() const; 00407 00416 int day() const; 00417 00427 QString eraName() const; 00428 00438 QString eraYear() const; 00439 00450 int yearInEra() const; 00451 00462 int dayOfYear() const; 00463 00476 int dayOfWeek() const; 00477 00496 int week(int *yearNum = 0) const; 00497 00519 int week(KLocale::WeekNumberSystem weekNumberSystem, int *yearNum = 0) const; 00520 00529 int monthsInYear() const; 00530 00543 int weeksInYear() const; 00544 00559 int weeksInYear(KLocale::WeekNumberSystem weekNumberSystem) const; 00560 00572 int daysInYear() const; 00573 00582 int daysInMonth() const; 00583 00592 int daysInWeek() const; 00593 00600 bool isLeapYear() const; 00601 00613 QString formatDate(KLocale::DateFormat dateFormat = KLocale::LongDate) const; 00614 00726 QString formatDate(const QString &formatString, 00727 KLocale::DateTimeFormatStandard formatStandard = KLocale::KdeFormat) const; 00728 00751 QString formatDate(KLocale::DateTimeComponent component, 00752 KLocale::DateTimeComponentFormat format = KLocale::DefaultComponentFormat, 00753 KLocale::WeekNumberSystem weekNumberSystem = KLocale::DefaultWeekNumber) const; 00754 00773 static KLocalizedDate readDate(const QString &dateString, 00774 KLocale::DateTimeParseMode parseMode = KLocale::LiberalParsing, 00775 const KCalendarSystem *calendar = 0); 00776 00795 static KLocalizedDate readDate(const QString &dateString, 00796 KLocale::ReadDateFlags formatFlags, 00797 KLocale::DateTimeParseMode parseMode = KLocale::LiberalParsing, 00798 const KCalendarSystem *calendar = 0); 00799 00819 static KLocalizedDate readDate(const QString &dateString, 00820 const QString &dateFormat, 00821 KLocale::DateTimeParseMode parseMode = KLocale::LiberalParsing, 00822 KLocale::DateTimeFormatStandard formatStandard = KLocale::KdeFormat, 00823 const KCalendarSystem *calendar = 0); 00824 00834 KLocalizedDate addYears(int years) const; 00835 00848 bool addYearsTo(int years); 00849 00859 KLocalizedDate addMonths(int months) const; 00860 00873 bool addMonthsTo(int months); 00874 00884 KLocalizedDate addDays(int days) const; 00885 00898 bool addDaysTo(int days); 00899 00923 void dateDifference(const KLocalizedDate &toDate, 00924 int *yearsDiff, int *monthsDiff, int *daysDiff, int *direction) const; 00925 00949 void dateDifference(const QDate &toDate, 00950 int *yearsDiff, int *monthsDiff, int *daysDiff, int *direction) const; 00951 00965 int yearsDifference(const KLocalizedDate &toDate) const; 00966 00980 int yearsDifference(const QDate &toDate) const; 00981 00997 int monthsDifference(const KLocalizedDate &toDate) const; 00998 01014 int monthsDifference(const QDate &toDate) const; 01015 01025 int daysDifference(const KLocalizedDate &toDate) const; 01026 01036 int daysDifference(const QDate &toDate) const; 01037 01044 KLocalizedDate firstDayOfYear() const; 01045 01052 KLocalizedDate lastDayOfYear() const; 01053 01060 KLocalizedDate firstDayOfMonth() const; 01061 01068 KLocalizedDate lastDayOfMonth() const; 01069 01075 bool operator==(const KLocalizedDate &other) const; 01076 01082 bool operator==(const QDate &other) const; 01083 01089 bool operator!=(const KLocalizedDate &other) const; 01090 01096 bool operator!=(const QDate &other) const; 01097 01103 bool operator<(const KLocalizedDate &other) const; 01104 01110 bool operator<(const QDate &other) const; 01111 01117 bool operator<=(const KLocalizedDate &other) const; 01118 01124 bool operator<=(const QDate &other) const; 01125 01131 bool operator>(const KLocalizedDate &other) const; 01132 01138 bool operator>(const QDate &other) const; 01139 01145 bool operator>=(const KLocalizedDate &other) const; 01146 01152 bool operator>=(const QDate &other) const; 01153 01154 private: 01155 01156 friend QDataStream KDECORE_EXPORT &operator<<(QDataStream &out, const KLocalizedDate &date); 01157 friend QDataStream KDECORE_EXPORT &operator>>(QDataStream &in, KLocalizedDate &date); 01158 friend QDebug KDECORE_EXPORT operator<<(QDebug, const KLocalizedDate &); 01159 01160 QSharedDataPointer<KLocalizedDatePrivate> d; 01161 }; 01162 01163 Q_DECLARE_METATYPE(KLocalizedDate) 01164 01165 01171 QDataStream KDECORE_EXPORT &operator<<(QDataStream &out, const KLocalizedDate &date); 01172 01179 QDataStream KDECORE_EXPORT &operator>>(QDataStream &in, KLocalizedDate &date); 01180 01187 QDebug KDECORE_EXPORT operator<<(QDebug debug, const KLocalizedDate &date); 01188 01189 #endif // KLOCALIZEDDATE_H
KDE 4.7 API Reference