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

KDECore

  • kdecore
  • date
klocalizeddate.cpp
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#include "klocalizeddate.h"
21
22#include "kglobal.h"
23#include "kdebug.h"
24
25/*****************************************************************************
26 *
27 * Private Section
28 *
29 *****************************************************************************/
30
31class KLocalizedDatePrivate : public QSharedData
32{
33public:
34 explicit KLocalizedDatePrivate(const QDate &date, const KCalendarSystem *calendar, bool manageCalendar);
35 KLocalizedDatePrivate(const KLocalizedDatePrivate &rhs);
36 KLocalizedDatePrivate &operator=(const KLocalizedDatePrivate &rhs);
37 virtual ~KLocalizedDatePrivate();
38
39 QDate m_date;
40 const KCalendarSystem *m_calendar;
41 bool m_manageCalendar;
42};
43
44KLocalizedDatePrivate::KLocalizedDatePrivate(const QDate &date, const KCalendarSystem *calendar, bool manageCalendar)
45 : QSharedData(),
46 m_date(date),
47 m_calendar(calendar),
48 m_manageCalendar(manageCalendar)
49{
50}
51
52KLocalizedDatePrivate::KLocalizedDatePrivate(const KLocalizedDatePrivate &rhs)
53 : QSharedData(rhs),
54 m_date(rhs.m_date),
55 m_calendar(rhs.m_calendar),
56 m_manageCalendar(rhs.m_manageCalendar)
57{
58 // If we're managing the calendar object, then take a copy,
59 // i.e. user called setCalendarSystem() rather than passing a custom one into the constructor
60 if (m_manageCalendar) {
61 m_calendar = KCalendarSystem::create(m_calendar->calendarSystem(), new KLocale(*m_calendar->locale()));
62 }
63}
64
65KLocalizedDatePrivate &KLocalizedDatePrivate::operator=(const KLocalizedDatePrivate &rhs)
66{
67 m_date = rhs.m_date;
68 m_calendar = rhs.m_calendar;
69 m_manageCalendar = rhs.m_manageCalendar;
70 // If we're managing the calendar object, then take a copy,
71 // i.e. user called setCalendarSystem() rather than passing a custom one into the constructor
72 if (rhs.m_manageCalendar) {
73 m_calendar = KCalendarSystem::create(m_calendar->calendarSystem(), new KLocale(*m_calendar->locale()));
74 }
75 return *this;
76}
77
78KLocalizedDatePrivate::~KLocalizedDatePrivate()
79{
80 // If we're managing the calendar object, then delete it,
81 // i.e. user called setCalendarSystem() rather than passing a custom one into the constructor
82 if (m_manageCalendar) {
83 delete m_calendar;
84 }
85}
86
87/*****************************************************************************
88 *
89 * Date Creation Section
90 *
91 *****************************************************************************/
92
93KLocalizedDate::KLocalizedDate(const QDate &date, const KCalendarSystem *calendarSystem)
94 : d(new KLocalizedDatePrivate(date, calendarSystem, false))
95{
96}
97
98KLocalizedDate::KLocalizedDate(int year, int month, int day, const KCalendarSystem *calendarSystem)
99 : d(new KLocalizedDatePrivate(QDate(), calendarSystem, false))
100{
101 setDate(year, month, day);
102}
103
104KLocalizedDate::KLocalizedDate(const KLocalizedDate &rhs)
105 : d(new KLocalizedDatePrivate(*rhs.d))
106{
107}
108
109KLocalizedDate &KLocalizedDate::operator=(const KLocalizedDate &rhs)
110{
111 *d = *rhs.d;
112 return *this;
113}
114
115KLocalizedDate &KLocalizedDate::operator=(const QDate &rhs)
116{
117 d->m_date = rhs;
118 return *this;
119}
120
121KLocalizedDate::~KLocalizedDate()
122{
123}
124
125/*****************************************************************************
126 *
127 * Calendar System Section
128 *
129 *****************************************************************************/
130
131void KLocalizedDate::setCalendarSystem(KLocale::CalendarSystem calendarSystem)
132{
133 if (calendarSystem == calendar()->calendarSystem()) {
134 return;
135 }
136 KCalendarSystem *newCalendar = KCalendarSystem::create(calendarSystem,
137 new KLocale(*calendar()->locale()));
138 if (d->m_manageCalendar) {
139 delete d->m_calendar;
140 }
141 d->m_calendar = newCalendar;
142}
143
144KLocale::CalendarSystem KLocalizedDate::calendarSystem()
145{
146 return calendar()->calendarSystem();
147}
148
149const KCalendarSystem *KLocalizedDate::calendar() const
150{
151 if (d->m_calendar) {
152 return d->m_calendar;
153 }
154 return KGlobal::locale()->calendar();
155}
156
157/*****************************************************************************
158 *
159 * Date Status Section
160 *
161 *****************************************************************************/
162
163bool KLocalizedDate::isNull() const
164{
165 return date().isNull();
166}
167
168bool KLocalizedDate::isValid() const
169{
170 return calendar()->isValid(date());
171}
172
173/*****************************************************************************
174 *
175 * Date Setting Section
176 *
177 *****************************************************************************/
178
179bool KLocalizedDate::setDate(const QDate &date)
180{
181 d->m_date = date;
182 return isValid();
183}
184
185bool KLocalizedDate::setDate(int year, int month, int day)
186{
187 calendar()->setDate(d->m_date, year, month, day);
188 return isValid();
189}
190
191bool KLocalizedDate::setDate(int year, int dayOfYear)
192{
193 calendar()->setDate(d->m_date, year, dayOfYear);
194 return isValid();
195}
196
197bool KLocalizedDate::setDate(QString eraName, int yearInEra, int month, int day)
198{
199 calendar()->setDate(d->m_date, eraName, yearInEra, month, day);
200 return isValid();
201}
202
203bool KLocalizedDate::setDate(KLocale::WeekNumberSystem weekNumberSystem, int year, int isoWeekNumber, int dayOfIsoWeek)
204{
205 Q_UNUSED(weekNumberSystem); // Only support ISO Week at the moment
206 calendar()->setDateIsoWeek(d->m_date, year, isoWeekNumber, dayOfIsoWeek);
207 return isValid();
208}
209
210bool KLocalizedDate::setCurrentDate()
211{
212 d->m_date = QDate::currentDate();
213 return isValid();
214}
215
216/*****************************************************************************
217 *
218 * Static Date Creation Section
219 *
220 *****************************************************************************/
221
222KLocalizedDate KLocalizedDate::currentDate()
223{
224 return KLocalizedDate(QDate::currentDate());
225}
226
227KLocalizedDate KLocalizedDate::fromDate(const QDate &date)
228{
229 return KLocalizedDate(date);
230}
231
232KLocalizedDate KLocalizedDate::fromJulianDay(int jd)
233{
234 return KLocalizedDate(QDate::fromJulianDay(jd));
235}
236
237/*****************************************************************************
238 *
239 * Date Componant Section
240 *
241 *****************************************************************************/
242
243int KLocalizedDate::toJulianDay() const
244{
245 return d->m_date.toJulianDay();
246}
247
248QDate KLocalizedDate::date() const
249{
250 return d->m_date;
251}
252
253void KLocalizedDate::getDate(int *year, int *month, int *day) const
254{
255 calendar()->getDate(date(), year, month, day);
256}
257
258int KLocalizedDate::year() const
259{
260 return calendar()->year(date());
261}
262
263int KLocalizedDate::month() const
264{
265 return calendar()->month(date());
266}
267
268int KLocalizedDate::day() const
269{
270 return calendar()->day(date());
271}
272
273QString KLocalizedDate::eraName() const
274{
275 return formatDate(KLocale::EraName);
276}
277
278QString KLocalizedDate::eraYear() const
279{
280 return formatDate(KLocale::EraYear);
281}
282
283int KLocalizedDate::yearInEra() const
284{
285 return calendar()->yearInEra(date());
286}
287
288int KLocalizedDate::dayOfYear() const
289{
290 return calendar()->dayOfYear(date());
291}
292
293int KLocalizedDate::dayOfWeek() const
294{
295 return calendar()->dayOfWeek(date());
296}
297
298int KLocalizedDate::week(int *yearNum) const
299{
300 return calendar()->week(date(), yearNum);
301}
302
303int KLocalizedDate::week(KLocale::WeekNumberSystem weekNumberSystem, int *yearNum) const
304{
305 return calendar()->week(date(), weekNumberSystem, yearNum);
306}
307
308int KLocalizedDate::monthsInYear() const
309{
310 return calendar()->monthsInYear(date());
311}
312
313int KLocalizedDate::weeksInYear() const
314{
315 return calendar()->weeksInYear(date());
316}
317
318int KLocalizedDate::weeksInYear(KLocale::WeekNumberSystem weekNumberSystem) const
319{
320 return calendar()->weeksInYear(date(), weekNumberSystem);
321}
322
323int KLocalizedDate::daysInYear() const
324{
325 return calendar()->daysInYear(date());
326}
327
328int KLocalizedDate::daysInMonth() const
329{
330 return calendar()->daysInMonth(date());
331}
332
333int KLocalizedDate::daysInWeek() const
334{
335 return calendar()->daysInWeek(date());
336}
337
338bool KLocalizedDate::isLeapYear() const
339{
340 return calendar()->isLeapYear(date());
341}
342
343/*****************************************************************************
344 *
345 * Date Formatting Section
346 *
347 *****************************************************************************/
348
349QString KLocalizedDate::formatDate(KLocale::DateFormat toFormat) const
350{
351 return calendar()->formatDate(date(), toFormat);
352}
353
354QString KLocalizedDate::formatDate(const QString &toFormat, KLocale::DateTimeFormatStandard formatStandard) const
355{
356 return calendar()->formatDate(date(), toFormat, formatStandard);
357}
358
359QString KLocalizedDate::formatDate(KLocale::DateTimeComponent component,
360 KLocale::DateTimeComponentFormat format,
361 KLocale::WeekNumberSystem weekNumberSystem) const
362{
363 return calendar()->formatDate(date(), component, format, weekNumberSystem);
364}
365
366/*****************************************************************************
367 *
368 * Date Parsing Section
369 *
370 *****************************************************************************/
371
372KLocalizedDate KLocalizedDate::readDate(const QString &dateString,
373 KLocale::DateTimeParseMode parseMode,
374 const KCalendarSystem *calendar)
375{
376 Q_UNUSED(parseMode);
377 if (!calendar) {
378 calendar = KGlobal::locale()->calendar();
379 }
380 return KLocalizedDate(calendar->readDate(dateString));
381}
382
383KLocalizedDate KLocalizedDate::readDate(const QString &dateString,
384 KLocale::ReadDateFlags formatFlags,
385 KLocale::DateTimeParseMode parseMode,
386 const KCalendarSystem *calendar)
387{
388 Q_UNUSED(parseMode);
389 if (!calendar) {
390 calendar = KGlobal::locale()->calendar();
391 }
392 return KLocalizedDate(calendar->readDate(dateString, formatFlags));
393}
394
395KLocalizedDate KLocalizedDate::readDate(const QString &dateString,
396 const QString &dateFormat,
397 KLocale::DateTimeParseMode parseMode,
398 KLocale::DateTimeFormatStandard formatStandard,
399 const KCalendarSystem *calendar)
400{
401 Q_UNUSED(parseMode);
402 if (!calendar) {
403 calendar = KGlobal::locale()->calendar();
404 }
405 return KLocalizedDate(calendar->readDate(dateString, dateFormat, 0, formatStandard));
406}
407
408/*****************************************************************************
409 *
410 * Date Maths Section
411 *
412 *****************************************************************************/
413
414KLocalizedDate KLocalizedDate::addYears(int years) const
415{
416 KLocalizedDate newDate;
417 newDate = *this;
418 newDate.setDate(calendar()->addYears(date(), years));
419 return newDate;
420}
421
422bool KLocalizedDate::addYearsTo(int years)
423{
424 d->m_date = calendar()->addYears(date(), years);
425 return isValid();
426}
427
428KLocalizedDate KLocalizedDate::addMonths(int months) const
429{
430 KLocalizedDate newDate(*this);
431 newDate.setDate(calendar()->addMonths(date(), months));
432 return newDate;
433}
434
435bool KLocalizedDate::addMonthsTo(int months)
436{
437 d->m_date = calendar()->addMonths(date(), months);
438 return isValid();
439}
440
441KLocalizedDate KLocalizedDate::addDays(int days) const
442{
443 KLocalizedDate newDate(*this);
444 newDate.setDate(calendar()->addDays(date(), days));
445 return newDate;
446}
447
448bool KLocalizedDate::addDaysTo(int days)
449{
450 d->m_date = calendar()->addDays(date(), days);
451 return isValid();
452}
453
454void KLocalizedDate::dateDifference(const KLocalizedDate &toDate,
455 int *yearsDiff, int *monthsDiff, int *daysDiff, int *direction) const
456{
457 dateDifference(toDate.date(), yearsDiff, monthsDiff, daysDiff, direction);
458}
459
460void KLocalizedDate::dateDifference(const QDate &toDate,
461 int *yearsDiff, int *monthsDiff, int *daysDiff, int *direction) const
462{
463 calendar()->dateDifference(date(), toDate, yearsDiff, monthsDiff, daysDiff, direction);
464}
465
466int KLocalizedDate::yearsDifference(const KLocalizedDate &toDate) const
467{
468 return yearsDifference(toDate.date());
469}
470
471int KLocalizedDate::yearsDifference(const QDate &toDate) const
472{
473 return calendar()->yearsDifference(date(), toDate);
474}
475
476int KLocalizedDate::monthsDifference(const KLocalizedDate &toDate) const
477{
478 return monthsDifference(toDate.date());
479}
480
481int KLocalizedDate::monthsDifference(const QDate &toDate) const
482{
483 return calendar()->monthsDifference(date(), toDate);
484}
485
486int KLocalizedDate::daysDifference(const KLocalizedDate &toDate) const
487{
488 return daysDifference(toDate.date());
489}
490
491int KLocalizedDate::daysDifference(const QDate &toDate) const
492{
493 return calendar()->daysDifference(date(), toDate);
494}
495
496KLocalizedDate KLocalizedDate::firstDayOfYear() const
497{
498 KLocalizedDate newDate(*this);
499 newDate.setDate(calendar()->firstDayOfYear(date()));
500 return newDate;
501}
502
503KLocalizedDate KLocalizedDate::lastDayOfYear() const
504{
505 KLocalizedDate newDate(*this);
506 newDate.setDate(calendar()->lastDayOfYear(date()));
507 return newDate;
508}
509
510KLocalizedDate KLocalizedDate::firstDayOfMonth() const
511{
512 KLocalizedDate newDate(*this);
513 newDate.setDate(calendar()->firstDayOfMonth(date()));
514 return newDate;
515}
516
517KLocalizedDate KLocalizedDate::lastDayOfMonth() const
518{
519 KLocalizedDate newDate(*this);
520 newDate.setDate(calendar()->lastDayOfMonth(date()));
521 return newDate;
522}
523
524/*****************************************************************************
525 *
526 * Date Operators Section
527 *
528 *****************************************************************************/
529
530bool KLocalizedDate::operator==(const KLocalizedDate &rhs) const
531{
532 return (date() == rhs.date());
533}
534
535bool KLocalizedDate::operator==(const QDate &rhs) const
536{
537 return (date() == rhs);
538}
539
540bool KLocalizedDate::operator!=(const KLocalizedDate &rhs) const
541{
542 return (date() != rhs.date());
543}
544
545bool KLocalizedDate::operator!=(const QDate &rhs) const
546{
547 return (date() != rhs);
548}
549
550bool KLocalizedDate::operator<(const KLocalizedDate &rhs) const
551{
552 return (date() < rhs.date());
553}
554
555bool KLocalizedDate::operator<(const QDate &rhs) const
556{
557 return (date() < rhs);
558}
559
560bool KLocalizedDate::operator<=(const KLocalizedDate &rhs) const
561{
562 return (d->m_date <= rhs.date());
563}
564
565bool KLocalizedDate::operator<=(const QDate &rhs) const
566{
567 return (date() <= rhs);
568}
569
570bool KLocalizedDate::operator>(const KLocalizedDate &rhs) const
571{
572 return (date() > rhs.date());
573}
574
575bool KLocalizedDate::operator>(const QDate &rhs) const
576{
577 return (date() > rhs);
578}
579
580bool KLocalizedDate::operator>=(const KLocalizedDate &rhs) const
581{
582 return (date() >= rhs.date());
583}
584
585bool KLocalizedDate::operator>=(const QDate &rhs) const
586{
587 return (date() >= rhs);
588}
589
590QDataStream &operator<<(QDataStream &out, const KLocalizedDate &date)
591{
592 return out << (quint32)(date.toJulianDay()) << date.calendar()->calendarSystem();
593}
594
595QDataStream &operator>>(QDataStream &in, KLocalizedDate &date)
596{
597 quint32 jd;
598 int calendarSystem;
599 in >> jd >> calendarSystem;
600 date.setDate(QDate::fromJulianDay(jd));
601 date.setCalendarSystem((KLocale::CalendarSystem)calendarSystem);
602 return in;
603}
604
605QDebug operator<<(QDebug dbg, const KLocalizedDate &date)
606{
607 if (date.calendar()->calendarSystem() == KLocale::QDateCalendar) {
608 dbg.nospace() << "KLocalizedDate(" << date.formatDate(KLocale::IsoDate) << ", "
609 << date.calendar()->calendarLabel() << ')';
610 } else {
611 dbg.nospace() << "KLocalizedDate(" << date.formatDate(KLocale::IsoDate) << ", "
612 << date.calendar()->calendarLabel() << ')'
613 << " = QDate(" << date.date().toString(Qt::ISODate) << ')';
614 }
615 return dbg.space();
616}
KCalendarSystem
KCalendarSystem abstract base class, provides support for local Calendar Systems in KDE.
Definition: kcalendarsystem.h:41
KCalendarSystem::yearsDifference
int yearsDifference(const QDate &fromDate, const QDate &toDate) const
Returns the difference between two dates in completed calendar years.
Definition: kcalendarsystem.cpp:1530
KCalendarSystem::dayOfWeek
virtual int dayOfWeek(const QDate &date) const
Returns the weekday number for the given date.
Definition: kcalendarsystem.cpp:1686
KCalendarSystem::day
virtual int day(const QDate &date) const
Returns the day portion of a given date in the current calendar system.
Definition: kcalendarsystem.cpp:1357
KCalendarSystem::year
virtual int year(const QDate &date) const
Returns the year portion of a given date in the current calendar system.
Definition: kcalendarsystem.cpp:1331
KCalendarSystem::daysInMonth
virtual int daysInMonth(const QDate &date) const
Returns the number of days in the given month.
Definition: kcalendarsystem.cpp:1643
KCalendarSystem::isLeapYear
virtual bool isLeapYear(int year) const =0
Returns whether a given year is a leap year.
Definition: kcalendarsystem.cpp:1720
KCalendarSystem::daysDifference
int daysDifference(const QDate &fromDate, const QDate &toDate) const
Returns the difference between two dates in days The returned value will be negative if fromDate > to...
Definition: kcalendarsystem.cpp:1554
KCalendarSystem::create
static KCalendarSystem * create(const QString &calType=QLatin1String("gregorian"), const KLocale *locale=0)
Definition: kcalendarsystem.cpp:47
KCalendarSystem::calendarSystem
static KLocale::CalendarSystem calendarSystem(const QString &calendarType)
Definition: kcalendarsystem.cpp:183
KCalendarSystem::readDate
virtual QDate readDate(const QString &str, bool *ok=0) const
Converts a localized date string to a QDate.
Definition: kcalendarsystem.cpp:2333
KCalendarSystem::yearInEra
int yearInEra(const QDate &date) const
Definition: kcalendarsystem.cpp:1400
KCalendarSystem::formatDate
virtual QString formatDate(const QDate &fromDate, KLocale::DateFormat toFormat=KLocale::LongDate) const
Returns a string formatted to the current locale's conventions regarding dates.
Definition: kcalendarsystem.cpp:2048
KCalendarSystem::dateDifference
void dateDifference(const QDate &fromDate, const QDate &toDate, int *yearsDiff, int *monthsDiff, int *daysDiff, int *direction) const
Returns the difference between two dates in years, months and days.
Definition: kcalendarsystem.cpp:1519
KCalendarSystem::week
int week(const QDate &date, int *yearNum=0) const
Returns the localized Week Number for the date.
Definition: kcalendarsystem.cpp:1703
KCalendarSystem::isValid
virtual bool isValid(int year, int month, int day) const =0
Returns whether a given date is valid in this calendar system.
Definition: kcalendarsystem.cpp:1133
KCalendarSystem::getDate
void getDate(const QDate date, int *year, int *month, int *day) const
Definition: kcalendarsystem.cpp:1307
KCalendarSystem::dayOfYear
virtual int dayOfYear(const QDate &date) const
Returns the day number of year for the given date.
Definition: kcalendarsystem.cpp:1675
KCalendarSystem::monthsDifference
int monthsDifference(const QDate &fromDate, const QDate &toDate) const
Returns the difference between two dates in completed calendar months The returned value will be nega...
Definition: kcalendarsystem.cpp:1542
KCalendarSystem::addMonths
virtual QDate addMonths(const QDate &date, int nmonths) const
Returns a QDate containing a date nmonths months later.
Definition: kcalendarsystem.cpp:1463
KCalendarSystem::daysInYear
virtual int daysInYear(const QDate &date) const
Returns the number of days in the given year.
Definition: kcalendarsystem.cpp:1620
KCalendarSystem::calendarLabel
static QString calendarLabel(const QString &calendarType)
Definition: kcalendarsystem.cpp:78
KCalendarSystem::monthsInYear
virtual int monthsInYear(const QDate &date) const
Returns number of months in the given year.
Definition: kcalendarsystem.cpp:1563
KCalendarSystem::addDays
virtual QDate addDays(const QDate &date, int ndays) const
Returns a QDate containing a date ndays days later.
Definition: kcalendarsystem.cpp:1502
KCalendarSystem::setDateIsoWeek
bool setDateIsoWeek(QDate &date, int year, int isoWeekNumber, int dayOfIsoWeek) const
Definition: kcalendarsystem.cpp:1272
KCalendarSystem::weeksInYear
virtual int weeksInYear(const QDate &date) const
Returns the number of localized weeks in the given year.
Definition: kcalendarsystem.cpp:1586
KCalendarSystem::addYears
virtual QDate addYears(const QDate &date, int nyears) const
Returns a QDate containing a date nyears years later.
Definition: kcalendarsystem.cpp:1435
KCalendarSystem::month
virtual int month(const QDate &date) const
Returns the month portion of a given date in the current calendar system.
Definition: kcalendarsystem.cpp:1344
KCalendarSystem::setDate
virtual bool setDate(QDate &date, int year, int month, int day) const
Changes the date's year, month and day.
Definition: kcalendarsystem.cpp:1222
KCalendarSystem::daysInWeek
virtual int daysInWeek(const QDate &date) const
Returns the number of days in the given week.
Definition: kcalendarsystem.cpp:1668
KLocale
KLocale provides support for country specific stuff like the national language.
Definition: klocale.h:70
KLocale::WeekNumberSystem
WeekNumberSystem
Definition: klocale.h:815
KLocale::DateTimeFormatStandard
DateTimeFormatStandard
Definition: klocale.h:829
KLocale::ReadDateFlags
ReadDateFlags
Flags for readDate()
Definition: klocale.h:1249
KLocale::DateTimeComponent
DateTimeComponent
Definition: klocale.h:865
KLocale::EraYear
@ EraYear
The Era and Year portion of a date.
Definition: klocale.h:874
KLocale::EraName
@ EraName
The Era Name portion of a date.
Definition: klocale.h:873
KLocale::DateFormat
DateFormat
Format for date string.
Definition: klocale.h:922
KLocale::IsoDate
@ IsoDate
ISO-8601 Date format YYYY-MM-DD, e.g.
Definition: klocale.h:931
KLocale::calendar
const KCalendarSystem * calendar() const
Returns a pointer to the calendar system object.
Definition: klocale.cpp:705
KLocale::CalendarSystem
CalendarSystem
Definition: klocale.h:780
KLocale::QDateCalendar
@ QDateCalendar
KDE Default, hybrid of Gregorian and Julian as used by QDate.
Definition: klocale.h:781
KLocale::DateTimeParseMode
DateTimeParseMode
Definition: klocale.h:841
KLocale::DateTimeComponentFormat
DateTimeComponentFormat
Definition: klocale.h:908
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::~KLocalizedDate
~KLocalizedDate()
Destructor.
Definition: klocalizeddate.cpp:121
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::operator<
bool operator<(const KLocalizedDate &other) const
KLocalizedDate less than operator.
Definition: klocalizeddate.cpp:550
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::operator!=
bool operator!=(const KLocalizedDate &other) const
KLocalizedDate inequality operator.
Definition: klocalizeddate.cpp:540
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::operator==
bool operator==(const KLocalizedDate &other) const
KLocalizedDate equality operator.
Definition: klocalizeddate.cpp:530
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
quint32
kdebug.h
kglobal.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
klocalizeddate.h
KGlobal::locale
KLocale * locale()
Returns the global locale object.
Definition: kglobal.cpp:170
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Mon Feb 20 2023 00:00:00 by doxygen 1.9.6 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
  • Modules
  • 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