• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdelibs-4.14.38 API Reference
  • KDE Home
  • Contact Us
 

KDECore

  • kdecore
  • date
klocalizeddate.h
Go to the documentation of this file.
1/*
2 Copyright 2010 John Layt <john@layt.net>
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 <QtCore/QString>
24#include <QtCore/QDate>
25
26#include <kdecore_export.h>
27#include "kcalendarsystem.h"
28#include "klocale.h"
29
30class KLocalizedDatePrivate;
137
138class KDECORE_EXPORT KLocalizedDate
139{
140public:
141
156 explicit KLocalizedDate(const QDate &date = QDate(), const KCalendarSystem *calendar = 0);
157
174 KLocalizedDate(int year, int month, int day, const KCalendarSystem *calendar = 0);
175
181 KLocalizedDate(const KLocalizedDate &rhs);
182
188 KLocalizedDate &operator=(const KLocalizedDate &rhs);
189
195 KLocalizedDate &operator=(const QDate &rhs);
196
200 ~KLocalizedDate();
201
220 void setCalendarSystem(KLocale::CalendarSystem calendarSystem);
221
229 KLocale::CalendarSystem calendarSystem();
230
245 const KCalendarSystem *calendar() const;
246
253 bool isNull() const;
254
261 bool isValid() const;
262
269 bool setDate(const QDate &date);
270
283 bool setDate(int year, int month, int day);
284
293 bool setDate(int year, int dayOfYear);
294
306 bool setDate(QString eraName, int yearInEra, int month, int day);
307
321 bool setDate(KLocale::WeekNumberSystem weekNumberSystem, int year, int weekOfYear, int dayOfWeek);
322
329 bool setCurrentDate();
330
338 static KLocalizedDate currentDate();
339
347 static KLocalizedDate fromDate(const QDate &date);
348
357 static KLocalizedDate fromJulianDay(int jd);
358
365 int toJulianDay() const;
366
372 QDate date() const;
373
386 void getDate(int *year, int *month, int *day) const;
387
396 int year() const;
397
406 int month() const;
407
416 int day() const;
417
427 QString eraName() const;
428
438 QString eraYear() const;
439
450 int yearInEra() const;
451
462 int dayOfYear() const;
463
476 int dayOfWeek() const;
477
496 int week(int *yearNum = 0) const;
497
519 int week(KLocale::WeekNumberSystem weekNumberSystem, int *yearNum = 0) const;
520
529 int monthsInYear() const;
530
543 int weeksInYear() const;
544
559 int weeksInYear(KLocale::WeekNumberSystem weekNumberSystem) const;
560
572 int daysInYear() const;
573
582 int daysInMonth() const;
583
592 int daysInWeek() const;
593
600 bool isLeapYear() const;
601
613 QString formatDate(KLocale::DateFormat dateFormat = KLocale::LongDate) const;
614
726 QString formatDate(const QString &formatString,
727 KLocale::DateTimeFormatStandard formatStandard = KLocale::KdeFormat) const;
728
751 QString formatDate(KLocale::DateTimeComponent component,
752 KLocale::DateTimeComponentFormat format = KLocale::DefaultComponentFormat,
753 KLocale::WeekNumberSystem weekNumberSystem = KLocale::DefaultWeekNumber) const;
754
773 static KLocalizedDate readDate(const QString &dateString,
774 KLocale::DateTimeParseMode parseMode = KLocale::LiberalParsing,
775 const KCalendarSystem *calendar = 0);
776
795 static KLocalizedDate readDate(const QString &dateString,
796 KLocale::ReadDateFlags formatFlags,
797 KLocale::DateTimeParseMode parseMode = KLocale::LiberalParsing,
798 const KCalendarSystem *calendar = 0);
799
819 static KLocalizedDate readDate(const QString &dateString,
820 const QString &dateFormat,
821 KLocale::DateTimeParseMode parseMode = KLocale::LiberalParsing,
822 KLocale::DateTimeFormatStandard formatStandard = KLocale::KdeFormat,
823 const KCalendarSystem *calendar = 0);
824
834 KLocalizedDate addYears(int years) const;
835
848 bool addYearsTo(int years);
849
859 KLocalizedDate addMonths(int months) const;
860
873 bool addMonthsTo(int months);
874
884 KLocalizedDate addDays(int days) const;
885
898 bool addDaysTo(int days);
899
923 void dateDifference(const KLocalizedDate &toDate,
924 int *yearsDiff, int *monthsDiff, int *daysDiff, int *direction) const;
925
949 void dateDifference(const QDate &toDate,
950 int *yearsDiff, int *monthsDiff, int *daysDiff, int *direction) const;
951
965 int yearsDifference(const KLocalizedDate &toDate) const;
966
980 int yearsDifference(const QDate &toDate) const;
981
997 int monthsDifference(const KLocalizedDate &toDate) const;
998
1014 int monthsDifference(const QDate &toDate) const;
1015
1025 int daysDifference(const KLocalizedDate &toDate) const;
1026
1036 int daysDifference(const QDate &toDate) const;
1037
1044 KLocalizedDate firstDayOfYear() const;
1045
1052 KLocalizedDate lastDayOfYear() const;
1053
1060 KLocalizedDate firstDayOfMonth() const;
1061
1068 KLocalizedDate lastDayOfMonth() const;
1069
1075 bool operator==(const KLocalizedDate &other) const;
1076
1082 bool operator==(const QDate &other) const;
1083
1089 bool operator!=(const KLocalizedDate &other) const;
1090
1096 bool operator!=(const QDate &other) const;
1097
1103 bool operator<(const KLocalizedDate &other) const;
1104
1110 bool operator<(const QDate &other) const;
1111
1117 bool operator<=(const KLocalizedDate &other) const;
1118
1124 bool operator<=(const QDate &other) const;
1125
1131 bool operator>(const KLocalizedDate &other) const;
1132
1138 bool operator>(const QDate &other) const;
1139
1145 bool operator>=(const KLocalizedDate &other) const;
1146
1152 bool operator>=(const QDate &other) const;
1153
1154private:
1155
1156 friend QDataStream KDECORE_EXPORT &operator<<(QDataStream &out, const KLocalizedDate &date);
1157 friend QDataStream KDECORE_EXPORT &operator>>(QDataStream &in, KLocalizedDate &date);
1158 friend QDebug KDECORE_EXPORT operator<<(QDebug, const KLocalizedDate &);
1159
1160 QSharedDataPointer<KLocalizedDatePrivate> d;
1161};
1162
1163Q_DECLARE_METATYPE(KLocalizedDate)
1164
1165
1171QDataStream KDECORE_EXPORT &operator<<(QDataStream &out, const KLocalizedDate &date);
1172
1179QDataStream KDECORE_EXPORT &operator>>(QDataStream &in, KLocalizedDate &date);
1180
1187QDebug KDECORE_EXPORT operator<<(QDebug debug, const KLocalizedDate &date);
1188
1189#endif // KLOCALIZEDDATE_H
KCalendarSystem
KCalendarSystem abstract base class, provides support for local Calendar Systems in KDE.
Definition kcalendarsystem.h:41
KLocale::WeekNumberSystem
WeekNumberSystem
Definition klocale.h:815
KLocale::DefaultWeekNumber
@ DefaultWeekNumber
The system locale default.
Definition klocale.h:816
KLocale::DateTimeFormatStandard
DateTimeFormatStandard
Definition klocale.h:829
KLocale::KdeFormat
@ KdeFormat
KDE Standard.
Definition klocale.h:830
KLocale::ReadDateFlags
ReadDateFlags
Flags for readDate()
Definition klocale.h:1249
KLocale::DateTimeComponent
DateTimeComponent
Definition klocale.h:865
KLocale::DateFormat
DateFormat
Format for date string.
Definition klocale.h:922
KLocale::LongDate
@ LongDate
Locale Long date format, e.g.
Definition klocale.h:924
KLocale::CalendarSystem
CalendarSystem
Definition klocale.h:780
KLocale::DateTimeParseMode
DateTimeParseMode
Definition klocale.h:841
KLocale::LiberalParsing
@ LiberalParsing
Parse Date/Time liberally.
Definition klocale.h:842
KLocale::DateTimeComponentFormat
DateTimeComponentFormat
Definition klocale.h:908
KLocale::DefaultComponentFormat
@ DefaultComponentFormat
The system locale default for the componant.
Definition klocale.h:909
KLocalizedDate
A class representing a date localized using the local calendar system, language and formats.
Definition klocalizeddate.h:139
KLocalizedDate::currentDate
static KLocalizedDate currentDate()
Returns a KLocalizedDate set to today's date in the Global Locale and Calendar System.
Definition klocalizeddate.cpp:222
KLocalizedDate::date
QDate date() const
Returns the currently set date as a QDate.
Definition klocalizeddate.cpp:248
KLocalizedDate::addDaysTo
bool addDaysTo(int days)
Add days onto this date instance.
Definition klocalizeddate.cpp:448
KLocalizedDate::day
int day() const
Returns the day portion of the date in the current calendar system.
Definition klocalizeddate.cpp:268
KLocalizedDate::operator>=
bool operator>=(const KLocalizedDate &other) const
KLocalizedDate greater than or equal to operator.
Definition klocalizeddate.cpp:580
KLocalizedDate::daysInWeek
int daysInWeek() const
Returns the number of days in the week.
Definition klocalizeddate.cpp:333
KLocalizedDate::addMonths
KLocalizedDate addMonths(int months) const
Returns a KLocalizedDate containing a date months months later.
Definition klocalizeddate.cpp:428
KLocalizedDate::readDate
static KLocalizedDate readDate(const QString &dateString, KLocale::DateTimeParseMode parseMode=KLocale::LiberalParsing, const KCalendarSystem *calendar=0)
Converts a localized date string to a KLocalizedDate using either the Global Calendar System and Loca...
Definition klocalizeddate.cpp:372
KLocalizedDate::setCalendarSystem
void setCalendarSystem(KLocale::CalendarSystem calendarSystem)
Set the Calendar System used for this date instance only.
Definition klocalizeddate.cpp:131
KLocalizedDate::week
int week(int *yearNum=0) const
Returns the localized Week Number for the date.
Definition klocalizeddate.cpp:298
KLocalizedDate::addMonthsTo
bool addMonthsTo(int months)
Add months onto this date instance.
Definition klocalizeddate.cpp:435
KLocalizedDate::yearsDifference
int yearsDifference(const KLocalizedDate &toDate) const
Returns the difference between this and another date in completed calendar years in the current Calen...
Definition klocalizeddate.cpp:466
KLocalizedDate::isNull
bool isNull() const
Returns whether the date is null, i.e.
Definition klocalizeddate.cpp:163
KLocalizedDate::lastDayOfMonth
KLocalizedDate lastDayOfMonth() const
Returns a KLocalizedDate containing the last day of the currently set month.
Definition klocalizeddate.cpp:517
KLocalizedDate::eraName
QString eraName() const
Returns the Era Name portion of the date in the current calendar system, for example "AD" or "Anno Do...
Definition klocalizeddate.cpp:273
KLocalizedDate::firstDayOfYear
KLocalizedDate firstDayOfYear() const
Returns a KLocalizedDate containing the first day of the currently set year.
Definition klocalizeddate.cpp:496
KLocalizedDate::yearInEra
int yearInEra() const
Returns the Year In Era portion of the date in the current calendar system, for example 1 for "1 BC".
Definition klocalizeddate.cpp:283
KLocalizedDate::formatDate
QString formatDate(KLocale::DateFormat dateFormat=KLocale::LongDate) const
Returns the Date as a localized string in the requested standard Locale format.
Definition klocalizeddate.cpp:349
KLocalizedDate::weeksInYear
int weeksInYear() const
Returns the number of localized weeks in the currently set year.
Definition klocalizeddate.cpp:313
KLocalizedDate::month
int month() const
Returns the month portion of the date in the current calendar system.
Definition klocalizeddate.cpp:263
KLocalizedDate::operator=
KLocalizedDate & operator=(const KLocalizedDate &rhs)
Assignment operator.
Definition klocalizeddate.cpp:109
KLocalizedDate::addYearsTo
bool addYearsTo(int years)
Add years onto this date instance.
Definition klocalizeddate.cpp:422
KLocalizedDate::daysInMonth
int daysInMonth() const
Returns the number of days in the month.
Definition klocalizeddate.cpp:328
KLocalizedDate::lastDayOfYear
KLocalizedDate lastDayOfYear() const
Returns a KLocalizedDate containing the last day of the currently set year.
Definition klocalizeddate.cpp:503
KLocalizedDate::dayOfWeek
int dayOfWeek() const
Returns the weekday number for the date.
Definition klocalizeddate.cpp:293
KLocalizedDate::fromJulianDay
static KLocalizedDate fromJulianDay(int jd)
Returns a KLocalizedDate set the required Julian Day number in the Global Locale and Calendar System.
Definition klocalizeddate.cpp:232
KLocalizedDate::operator>
bool operator>(const KLocalizedDate &other) const
KLocalizedDate greater than operator.
Definition klocalizeddate.cpp:570
KLocalizedDate::monthsInYear
int monthsInYear() const
Returns number of months in the year.
Definition klocalizeddate.cpp:308
KLocalizedDate::addDays
KLocalizedDate addDays(int days) const
Returns a KLocalizedDate containing a date days days later.
Definition klocalizeddate.cpp:441
KLocalizedDate::calendar
const KCalendarSystem * calendar() const
Returns a pointer to the Calendar System object used by this date instance.
Definition klocalizeddate.cpp:149
KLocalizedDate::KLocalizedDate
KLocalizedDate(const QDate &date=QDate(), const KCalendarSystem *calendar=0)
Constructs a localized date with the given date.
Definition klocalizeddate.cpp:93
KLocalizedDate::toJulianDay
int toJulianDay() const
Returns the currently set date as a Julian Day number.
Definition klocalizeddate.cpp:243
KLocalizedDate::dateDifference
void dateDifference(const KLocalizedDate &toDate, int *yearsDiff, int *monthsDiff, int *daysDiff, int *direction) const
Returns the difference between this and another date in years, months and days in the current Calenda...
Definition klocalizeddate.cpp:454
KLocalizedDate::firstDayOfMonth
KLocalizedDate firstDayOfMonth() const
Returns a KLocalizedDate containing the first day of the currently set month.
Definition klocalizeddate.cpp:510
KLocalizedDate::daysInYear
int daysInYear() const
Returns the number of days in the year.
Definition klocalizeddate.cpp:323
KLocalizedDate::isLeapYear
bool isLeapYear() const
Returns whether the currently set date falls in a Leap Year in the current Calendar System.
Definition klocalizeddate.cpp:338
KLocalizedDate::addYears
KLocalizedDate addYears(int years) const
Returns a KLocalizedDate containing a date years years later.
Definition klocalizeddate.cpp:414
KLocalizedDate::setCurrentDate
bool setCurrentDate()
Set the date to today's date.
Definition klocalizeddate.cpp:210
KLocalizedDate::isValid
bool isValid() const
Returns whether the date is valid in the current Calendar System.
Definition klocalizeddate.cpp:168
KLocalizedDate::dayOfYear
int dayOfYear() const
Returns the day number of year for the date.
Definition klocalizeddate.cpp:288
KLocalizedDate::year
int year() const
Returns the year portion of the date in the current calendar system.
Definition klocalizeddate.cpp:258
KLocalizedDate::monthsDifference
int monthsDifference(const KLocalizedDate &toDate) const
Returns the difference between this and another date in completed calendar months in the current Cale...
Definition klocalizeddate.cpp:476
KLocalizedDate::operator<=
bool operator<=(const KLocalizedDate &other) const
KLocalizedDate less than or equal to operator.
Definition klocalizeddate.cpp:560
KLocalizedDate::fromDate
static KLocalizedDate fromDate(const QDate &date)
Returns a KLocalizedDate set the required date in the Global Locale and Calendar System.
Definition klocalizeddate.cpp:227
KLocalizedDate::setDate
bool setDate(const QDate &date)
Set the date using a QDate.
Definition klocalizeddate.cpp:179
KLocalizedDate::eraYear
QString eraYear() const
Returns the Era Year portion of the date in the current calendar system, for example "2000 AD" or "He...
Definition klocalizeddate.cpp:278
KLocalizedDate::daysDifference
int daysDifference(const KLocalizedDate &toDate) const
Returns the difference between this and another date in days The returned value will be negative if t...
Definition klocalizeddate.cpp:486
KLocalizedDate::getDate
void getDate(int *year, int *month, int *day) const
Returns the year, month and day portion of the date in the current Calendar System.
Definition klocalizeddate.cpp:253
KLocalizedDate::calendarSystem
KLocale::CalendarSystem calendarSystem()
Returns the Calendar System used by this localized date instance.
Definition klocalizeddate.cpp:144
QString
kcalendarsystem.h
operator<<
QDebug operator<<(QDebug dbg, const KEntryKey &key)
Definition kconfigdata.cpp:25
operator==
bool operator==(const KEntry &k1, const KEntry &k2)
Definition kconfigdata.h:72
operator<
bool operator<(const KEntryKey &k1, const KEntryKey &k2)
Compares two KEntryKeys (needed for QMap).
Definition kconfigdata.h:124
operator!=
bool operator!=(const KEntry &k1, const KEntry &k2)
Definition kconfigdata.h:79
operator>>
QDataStream & operator>>(QDataStream &s, KDateTime::Spec &spec)
Read a KDateTime::Spec object into spec from in, in binary format.
Definition kdatetime.cpp:274
kdecore_export.h
klocale.h
operator>>
QDataStream & operator>>(QDataStream &in, KLocalizedDate &date)
Data stream input operator.
Definition klocalizeddate.cpp:595
operator<<
QDataStream & operator<<(QDataStream &out, const KLocalizedDate &date)
Data stream output operator.
Definition klocalizeddate.cpp:590
This file is part of the KDE documentation.
Documentation copyright © 1996-2025 The KDE developers.
Generated on Fri Jan 17 2025 00:00:00 by doxygen 1.13.2 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KDECore

Skip menu "KDECore"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdelibs-4.14.38 API Reference

Skip menu "kdelibs-4.14.38 API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal