• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdepimlibs-4.14.10 API Reference
  • KDE Home
  • Contact Us
 

KAlarm Library

  • kalarmcal
datetime.h
1/*
2 * datetime.h - date/time with start-of-day time for date-only values
3 * This file is part of kalarmcal library, which provides access to KAlarm
4 * calendar data.
5 * Copyright © 2003,2005-2007,2009,2011 by David Jarvie <djarvie@kde.org>
6 *
7 * This library is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU Library General Public License as published
9 * by the Free Software Foundation; either version 2 of the License, or (at
10 * your option) any later version.
11 *
12 * This library is distributed in the hope that it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
15 * License for more details.
16 *
17 * You should have received a copy of the GNU Library General Public License
18 * along with this library; see the file COPYING.LIB. If not, write to the
19 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
20 * MA 02110-1301, USA.
21 */
22#ifndef KALARM_DATETIME_H
23#define KALARM_DATETIME_H
24
25#include "kalarmcal_export.h"
26
27#include <kdatetime.h>
28
29namespace KAlarmCal
30{
31
42class KALARMCAL_EXPORT DateTime
43{
44 public:
48 DateTime();
50 DateTime(const QDate& d, const KDateTime::Spec& spec);
52 DateTime(const QDate& d, const QTime& t, const KDateTime::Spec& spec);
54 DateTime(const QDateTime& dt, const KDateTime::Spec& spec);
56 DateTime(const KDateTime& dt);
58 DateTime(const DateTime& dt);
59
60 ~DateTime();
62 DateTime& operator=(const DateTime& dt);
66 DateTime& operator=(const KDateTime& dt);
67
69 bool isNull() const;
71 bool isValid() const;
73 bool isDateOnly() const;
77 void setDateOnly(bool d);
78
80 QDate date() const;
82 void setDate(const QDate& d);
83
86 QDateTime rawDateTime() const;
88 KDateTime kDateTime() const;
92 QTime effectiveTime() const;
95 void setTime(const QTime& t);
100 QDateTime effectiveDateTime() const;
102 void setDateTime(const QDateTime& dt);
103
108 KDateTime effectiveKDateTime() const;
112 KDateTime calendarKDateTime() const;
113
115 KTimeZone timeZone() const;
117 KDateTime::Spec timeSpec() const;
119 void setTimeSpec(const KDateTime::Spec &spec);
122 KDateTime::SpecType timeType() const;
124 bool isLocalZone() const;
126 bool isClockTime() const;
128 bool isUtc() const;
130 bool isOffsetFromUtc() const;
132 int utcOffset() const;
133
135 bool isSecondOccurrence() const;
137 void setSecondOccurrence(bool second);
138
140 DateTime toUtc() const;
143 DateTime toOffsetFromUtc() const;
145 DateTime toOffsetFromUtc(int utcOffset) const;
147 DateTime toLocalZone() const;
149 DateTime toClockTime() const;
151 DateTime toZone(const KTimeZone& zone) const;
153 DateTime toTimeSpec(const KDateTime::Spec &spec) const;
154
157 uint toTime_t() const;
162 void setTime_t(uint secs);
163
165 DateTime addSecs(qint64 n) const;
167 DateTime addMins(qint64 n) const;
169 DateTime addDays(int n) const;
171 DateTime addMonths(int n) const;
173 DateTime addYears(int n) const;
174
176 int daysTo(const DateTime& dt) const;
178 int minsTo(const DateTime& dt) const;
184 int secsTo(const DateTime& dt) const;
186 qint64 secsTo_long(const DateTime& dt) const;
187
192 QString toString(Qt::DateFormat f = Qt::TextDate) const;
197 QString toString(const QString& format) const;
202 QString formatLocale(bool shortFormat = true) const;
203
207 static void setStartOfDay(const QTime& sod);
208
210 static QTime startOfDay();
211
213 KDateTime::Comparison compare(const DateTime &other) const;
214
215 KALARMCAL_EXPORT friend bool operator==(const KAlarmCal::DateTime& dt1, const KAlarmCal::DateTime& dt2);
216 KALARMCAL_EXPORT friend bool operator==(const KDateTime& dt1, const KAlarmCal::DateTime& dt2);
217 KALARMCAL_EXPORT friend bool operator<(const KAlarmCal::DateTime& dt1, const KAlarmCal::DateTime& dt2);
218 friend bool operator<(const KDateTime& dt1, const KAlarmCal::DateTime& dt2);
219
220 private:
221 //@cond PRIVATE
222 class Private;
223 Private* const d;
224 //@endcond
225};
226
228KALARMCAL_EXPORT bool operator==(const DateTime& dt1, const DateTime& dt2);
229KALARMCAL_EXPORT bool operator==(const KDateTime& dt1, const DateTime& dt2);
230
232inline bool operator!=(const DateTime& dt1, const DateTime& dt2) { return !operator==(dt1, dt2); }
233inline bool operator!=(const KDateTime& dt1, const DateTime& dt2) { return !operator==(dt1, dt2); }
234
239KALARMCAL_EXPORT bool operator<(const DateTime& dt1, const DateTime& dt2);
240inline bool operator<(const KDateTime& dt1, const DateTime& dt2) { return operator<(DateTime(dt1), dt2); }
241
246inline bool operator>(const DateTime& dt1, const DateTime& dt2) { return operator<(dt2, dt1); }
247inline bool operator>(const KDateTime& dt1, const DateTime& dt2) { return operator<(dt2, DateTime(dt1)); }
248
253inline bool operator>=(const DateTime& dt1, const DateTime& dt2) { return !operator<(dt1, dt2); }
254inline bool operator>=(const KDateTime& dt1, const DateTime& dt2) { return !operator<(DateTime(dt1), dt2); }
255
260inline bool operator<=(const DateTime& dt1, const DateTime& dt2) { return !operator<(dt2, dt1); }
261inline bool operator<=(const KDateTime& dt1, const DateTime& dt2) { return !operator<(dt2, DateTime(dt1)); }
262
263} // namespace KAlarmCal
264
265#endif // KALARM_DATETIME_H
266
267// vim: et sw=4:
KAlarmCal::DateTime
As KDateTime, but with a configurable start-of-day time for date-only values.
Definition datetime.h:43
KAlarmCal::DateTime::rawDateTime
QDateTime rawDateTime() const
Returns the date and time of the value.
Definition datetime.cpp:127
KAlarmCal::DateTime::addMins
DateTime addMins(qint64 n) const
Returns a DateTime value mins minutes later than the value of this object.
Definition datetime.cpp:290
KAlarmCal::DateTime::isOffsetFromUtc
bool isOffsetFromUtc() const
Returns whether the date/time is a local time at a fixed offset from UTC.
Definition datetime.cpp:220
KAlarmCal::DateTime::utcOffset
int utcOffset() const
Returns the UTC offset associated with the date/time.
Definition datetime.cpp:225
KAlarmCal::DateTime::kDateTime
KDateTime kDateTime() const
Returns the date and time of the value as a KDateTime.
Definition datetime.cpp:132
KAlarmCal::DateTime::toString
QString toString(Qt::DateFormat f=Qt::TextDate) const
Returns the value as a string.
Definition datetime.cpp:330
KAlarmCal::DateTime::toOffsetFromUtc
DateTime toOffsetFromUtc() const
Returns the time expressed as an offset from UTC, using the UTC offset associated with this instance'...
Definition datetime.cpp:245
KAlarmCal::DateTime::operator==
KALARMCAL_EXPORT friend bool operator==(const KAlarmCal::DateTime &dt1, const KAlarmCal::DateTime &dt2)
Returns true if the two values are equal.
Definition datetime.cpp:366
KAlarmCal::DateTime::startOfDay
static QTime startOfDay()
Returns the start-of-day time.
Definition datetime.cpp:361
KAlarmCal::DateTime::setTime_t
void setTime_t(uint secs)
Sets the value to a specified date-time value.
Definition datetime.cpp:280
KAlarmCal::DateTime::setTime
void setTime(const QTime &t)
Sets the time component of the value.
Definition datetime.cpp:142
KAlarmCal::DateTime::isDateOnly
bool isDateOnly() const
Returns true if it is date-only value.
Definition datetime.cpp:107
KAlarmCal::DateTime::secsTo_long
qint64 secsTo_long(const DateTime &dt) const
Returns the number of seconds as a qint64 from this date or date-time to dt.
Definition datetime.cpp:325
KAlarmCal::DateTime::isValid
bool isValid() const
Returns true if the date is valid and, if it is a date-time value, the time is also valid.
Definition datetime.cpp:102
KAlarmCal::DateTime::setDateOnly
void setDateOnly(bool d)
Sets the value to be either date-only or date-time.
Definition datetime.cpp:112
KAlarmCal::DateTime::isSecondOccurrence
bool isSecondOccurrence() const
Returns whether the date/time is the second occurrence of this time.
Definition datetime.cpp:230
KAlarmCal::DateTime::operator<
KALARMCAL_EXPORT friend bool operator<(const KAlarmCal::DateTime &dt1, const KAlarmCal::DateTime &dt2)
Returns true if the dt1 is earlier than dt2.
Definition datetime.cpp:376
KAlarmCal::DateTime::isClockTime
bool isClockTime() const
Returns whether the date/time is a local clock time.
Definition datetime.cpp:210
KAlarmCal::DateTime::operator=
DateTime & operator=(const DateTime &dt)
Assignment operator.
Definition datetime.cpp:84
KAlarmCal::DateTime::setDateTime
void setDateTime(const QDateTime &dt)
Sets the date/time component of the value.
Definition datetime.cpp:158
KAlarmCal::DateTime::timeType
KDateTime::SpecType timeType() const
Returns the time specification type of the date/time, i.e.
Definition datetime.cpp:200
KAlarmCal::DateTime::isUtc
bool isUtc() const
Returns whether the date/time is a UTC time.
Definition datetime.cpp:215
KAlarmCal::DateTime::setTimeSpec
void setTimeSpec(const KDateTime::Spec &spec)
Changes the time specification of the value.
Definition datetime.cpp:195
KAlarmCal::DateTime::DateTime
DateTime()
Default constructor.
Definition datetime.cpp:49
KAlarmCal::DateTime::setDate
void setDate(const QDate &d)
Sets the date component of the value.
Definition datetime.cpp:122
KAlarmCal::DateTime::effectiveTime
QTime effectiveTime() const
Returns the time part of the value.
Definition datetime.cpp:137
KAlarmCal::DateTime::toTimeSpec
DateTime toTimeSpec(const KDateTime::Spec &spec) const
Returns the time converted to a new time specification.
Definition datetime.cpp:270
KAlarmCal::DateTime::setSecondOccurrence
void setSecondOccurrence(bool second)
Sets whether this is the second occurrence of this date/time.
Definition datetime.cpp:235
KAlarmCal::DateTime::formatLocale
QString formatLocale(bool shortFormat=true) const
Returns the value as a string, formatted according to the user's locale.
Definition datetime.cpp:346
KAlarmCal::DateTime::effectiveKDateTime
KDateTime effectiveKDateTime() const
Returns the date and time of the value.
Definition datetime.cpp:163
KAlarmCal::DateTime::addDays
DateTime addDays(int n) const
Returns a DateTime value n days later than the value of this object.
Definition datetime.cpp:295
KAlarmCal::DateTime::effectiveDateTime
QDateTime effectiveDateTime() const
Returns the date and time of the value.
Definition datetime.cpp:147
KAlarmCal::DateTime::calendarKDateTime
KDateTime calendarKDateTime() const
Returns the date and time of the value as written in the calendar.
Definition datetime.cpp:174
KAlarmCal::DateTime::secsTo
int secsTo(const DateTime &dt) const
Returns the number of seconds from this date or date-time to dt.
Definition datetime.cpp:320
KAlarmCal::DateTime::toZone
DateTime toZone(const KTimeZone &zone) const
Returns the time converted to a specified time zone.
Definition datetime.cpp:265
KAlarmCal::DateTime::addSecs
DateTime addSecs(qint64 n) const
Returns a DateTime value secs seconds later than the value of this object.
Definition datetime.cpp:285
KAlarmCal::DateTime::toClockTime
DateTime toClockTime() const
Returns the time converted to the local clock time.
Definition datetime.cpp:260
KAlarmCal::DateTime::setStartOfDay
static void setStartOfDay(const QTime &sod)
Sets the start-of-day time.
Definition datetime.cpp:351
KAlarmCal::DateTime::toTime_t
uint toTime_t() const
Converts the time to a UTC time, measured in seconds since 00:00:00 UTC 1st January 1970 (as returned...
Definition datetime.cpp:275
KAlarmCal::DateTime::toLocalZone
DateTime toLocalZone() const
Returns the time converted to the current local system time zone.
Definition datetime.cpp:255
KAlarmCal::DateTime::isLocalZone
bool isLocalZone() const
Returns whether the time zone for the date/time is the current local system time zone.
Definition datetime.cpp:205
KAlarmCal::DateTime::addYears
DateTime addYears(int n) const
Returns a DateTime value n years later than the value of this object.
Definition datetime.cpp:305
KAlarmCal::DateTime::daysTo
int daysTo(const DateTime &dt) const
Returns the number of days from this date or date-time to dt.
Definition datetime.cpp:310
KAlarmCal::DateTime::timeSpec
KDateTime::Spec timeSpec() const
Returns the time specification of the value.
Definition datetime.cpp:190
KAlarmCal::DateTime::isNull
bool isNull() const
Returns true if the date is null and, if it is a date-time value, the time is also null.
Definition datetime.cpp:97
KAlarmCal::DateTime::toUtc
DateTime toUtc() const
Returns the time converted to UTC.
Definition datetime.cpp:240
KAlarmCal::DateTime::timeZone
KTimeZone timeZone() const
Returns the time zone of the value.
Definition datetime.cpp:185
KAlarmCal::DateTime::date
QDate date() const
Returns the date part of the value.
Definition datetime.cpp:117
KAlarmCal::DateTime::addMonths
DateTime addMonths(int n) const
Returns a DateTime value n months later than the value of this object.
Definition datetime.cpp:300
KAlarmCal::DateTime::compare
KDateTime::Comparison compare(const DateTime &other) const
Compare this value with another.
Definition datetime.cpp:356
KAlarmCal::DateTime::minsTo
int minsTo(const DateTime &dt) const
Returns the number of minutes from this date or date-time to dt.
Definition datetime.cpp:315
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.

KAlarm Library

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

kdepimlibs-4.14.10 API Reference

Skip menu "kdepimlibs-4.14.10 API Reference"
  • akonadi
  •   contact
  •   kmime
  •   socialutils
  • kabc
  • kalarmcal
  • kblog
  • kcal
  • kcalcore
  • kcalutils
  • kholidays
  • kimap
  • kioslave
  •   imap4
  •   mbox
  •   nntp
  • kldap
  • kmbox
  • kmime
  • kontactinterface
  • kpimidentities
  • kpimtextedit
  • kpimutils
  • kresources
  • ktnef
  • kxmlrpcclient
  • mailtransport
  • microblog
  • qgpgme
  • syndication
  •   atom
  •   rdf
  •   rss2
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