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

KDECore

  • sources
  • kde-4.14
  • kdelibs
  • kdecore
  • date
kdatetime.h
Go to the documentation of this file.
1 /*
2  This file is part of the KDE libraries
3  Copyright (c) 2005-2011 David Jarvie <djarvie@kde.org>
4 
5  This library is free software; you can redistribute it and/or
6  modify it under the terms of the GNU Library General Public
7  License as published by the Free Software Foundation; either
8  version 2 of the License, or (at your option) any later version.
9 
10  This library is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  Library General Public License for more details.
14 
15  You should have received a copy of the GNU Library General Public License
16  along with this library; see the file COPYING.LIB. If not, write to
17  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18  Boston, MA 02110-1301, USA.
19 */
20 
26 #ifndef _KDATETIME_H_
27 #define _KDATETIME_H_
28 
29 #include <kdecore_export.h>
30 #include <ktimezone.h>
31 
32 #include <QtCore/QMetaType>
33 #include <QtCore/QSharedDataPointer>
34 
35 class QDataStream;
36 class KDateTimePrivate;
37 class KDateTimeSpecPrivate;
38 
171 class KDECORE_EXPORT KDateTime //krazy:exclude=dpointer (implicitly shared)
172 {
173  public:
181  enum SpecType
182  {
183  Invalid,
184  UTC,
185  OffsetFromUTC,
186  TimeZone,
191  LocalZone,
203  ClockTime
215  };
216 
223  class KDECORE_EXPORT Spec
224  {
225  public:
229  Spec();
230 
237  Spec(const KTimeZone &tz); // allow implicit conversion
238 
246  Spec(SpecType type, int utcOffset = 0); // allow implicit conversion
247 
251  Spec(const Spec& spec);
252 
256  Spec& operator=(const Spec& spec);
257 
261  ~Spec();
262 
268  bool isValid() const;
269 
280  KTimeZone timeZone() const;
281 
291  SpecType type() const;
292 
300  bool isLocalZone() const;
301 
308  bool isClockTime() const;
309 
318  bool isUtc() const;
319 
327  bool isOffsetFromUtc() const;
328 
336  int utcOffset() const;
337 
347  void setType(SpecType type, int utcOffset = 0);
348 
358  void setType(const KTimeZone &tz);
359 
366  bool operator==(const Spec &other) const;
367 
368  bool operator!=(const Spec &other) const { return !operator==(other); }
369 
383  bool equivalentTo(const Spec &other) const;
384 
389  static Spec UTC();
390 
395  static Spec ClockTime();
396 
404  static Spec OffsetFromUTC(int utcOffset);
405 
412  static Spec LocalZone();
413 
414  private:
415  KDateTimeSpecPrivate* const d;
416  };
417 
419  enum TimeFormat
420  {
421  ISODate,
435  RFCDate,
442  RFCDateDay,
445  QtTextDate,
449  LocalDate,
453  RFC3339Date
458  };
459 
478  enum Comparison
479  {
480  Before = 0x01,
483  AtStart = 0x02,
487  Inside = 0x04,
491  AtEnd = 0x08,
495  After = 0x10,
498  Equal = AtStart | Inside | AtEnd,
501  Outside = Before | AtStart | Inside | AtEnd | After,
506  StartsAt = AtStart | Inside | AtEnd | After,
511  EndsAt = Before | AtStart | Inside | AtEnd
516  };
517 
518 
522  KDateTime();
523 
541  explicit KDateTime(const QDate &date, const Spec &spec = Spec(LocalZone));
542 
560  KDateTime(const QDate &date, const QTime &time, const Spec &spec = Spec(LocalZone));
561 
591  KDateTime(const QDateTime &dt, const Spec &spec);
592 
600  explicit KDateTime(const QDateTime &dt);
601 
602  KDateTime(const KDateTime &other);
603  ~KDateTime();
604 
605  KDateTime &operator=(const KDateTime &other);
606 
613  bool isNull() const;
614 
621  bool isValid() const;
622 
628  bool isDateOnly() const;
629 
637  QDate date() const;
638 
647  QTime time() const;
648 
660  QDateTime dateTime() const;
661 
670  KTimeZone timeZone() const;
671 
679  Spec timeSpec() const;
680 
690  SpecType timeType() const;
691 
699  bool isLocalZone() const;
700 
707  bool isClockTime() const;
708 
718  bool isUtc() const;
719 
727  bool isOffsetFromUtc() const;
728 
736  int utcOffset() const;
737 
756  bool isSecondOccurrence() const;
757 
769  KDateTime toUtc() const;
770 
786  KDateTime toOffsetFromUtc() const;
787 
800  KDateTime toOffsetFromUtc(int utcOffset) const;
801 
810  KDateTime toLocalZone() const;
811 
822  KDateTime toClockTime() const;
823 
835  KDateTime toZone(const KTimeZone &zone) const;
836 
848  KDateTime toTimeSpec(const Spec &spec) const;
849 
861  KDateTime toTimeSpec(const KDateTime &dt) const;
862 
870  uint toTime_t() const;
871 
879  void setTime_t(qint64 seconds);
880 
890  void setDateOnly(bool dateOnly);
891 
898  void setDate(const QDate &date);
899 
907  void setTime(const QTime &time);
908 
923  void setDateTime(const QDateTime &dt);
924 
936  void setTimeSpec(const Spec &spec);
937 
961  void setSecondOccurrence(bool second);
962 
981  KDateTime addMSecs(qint64 msecs) const;
982 
1001  KDateTime addSecs(qint64 secs) const;
1002 
1015  KDateTime addDays(int days) const;
1016 
1029  KDateTime addMonths(int months) const;
1030 
1043  KDateTime addYears(int years) const;
1044 
1070  int secsTo(const KDateTime &other) const;
1071 
1097  qint64 secsTo_long(const KDateTime &other) const;
1098 
1122  int daysTo(const KDateTime &other) const;
1123 
1131  static KDateTime currentLocalDateTime();
1132 
1140  static KDateTime currentUtcDateTime();
1141 
1154  static KDateTime currentDateTime(const Spec &spec);
1155 
1164  static QDate currentLocalDate();
1165 
1174  static QTime currentLocalTime();
1175 
1243  QString toString(const QString &format) const;
1244 
1266  QString toString(TimeFormat format = ISODate) const;
1267 
1308  static KDateTime fromString(const QString &string, TimeFormat format = ISODate, bool *negZero = 0);
1309 
1447  static KDateTime fromString(const QString &string, const QString &format,
1448  const KTimeZones *zones = 0, bool offsetIfAmbiguous = true);
1449 
1462  static void setFromStringDefault(const Spec &spec);
1463 
1464 
1476  bool outOfRange() const;
1477 
1506  Comparison compare(const KDateTime &other) const;
1507 
1528  bool operator==(const KDateTime &other) const;
1529 
1530  bool operator!=(const KDateTime &other) const { return !(*this == other); }
1531 
1551  bool operator<(const KDateTime &other) const;
1552 
1553  bool operator<=(const KDateTime &other) const { return !(other < *this); }
1554  bool operator>(const KDateTime &other) const { return other < *this; }
1555  bool operator>=(const KDateTime &other) const { return !(*this < other); }
1556 
1568  void detach();
1569 
1600  static void setSimulatedSystemTime(const KDateTime& newTime);
1601 
1619  static KDateTime realCurrentLocalDateTime();
1620 
1621  friend QDataStream KDECORE_EXPORT &operator<<(QDataStream &out, const KDateTime &dateTime);
1622  friend QDataStream KDECORE_EXPORT &operator>>(QDataStream &in, KDateTime &dateTime);
1623 
1624  private:
1625  QSharedDataPointer<KDateTimePrivate> d;
1626 };
1627 
1628 Q_DECLARE_METATYPE(KDateTime)
1629 Q_DECLARE_METATYPE(KDateTime::Spec)
1630 
1632 QDataStream KDECORE_EXPORT &operator<<(QDataStream &out, const KDateTime::Spec &spec);
1634 QDataStream KDECORE_EXPORT &operator>>(QDataStream &in, KDateTime::Spec &spec);
1635 
1637 QDataStream KDECORE_EXPORT &operator<<(QDataStream &out, const KDateTime &dateTime);
1639 QDataStream KDECORE_EXPORT &operator>>(QDataStream &in, KDateTime &dateTime);
1640 
1641 #endif
qint64
KDateTime::SpecType
SpecType
The time specification type of a KDateTime instance.
Definition: kdatetime.h:181
KDateTime::operator!=
bool operator!=(const KDateTime &other) const
Definition: kdatetime.h:1530
kdecore_export.h
QDataStream
operator>>
QDataStream & operator>>(QDataStream &in, KDateTime::Spec &spec)
Read a KDateTime::Spec object into spec from in, in binary format.
Definition: kdatetime.cpp:274
operator<
bool operator<(const KEntryKey &k1, const KEntryKey &k2)
Compares two KEntryKeys (needed for QMap).
Definition: kconfigdata.h:124
KDateTime::operator>=
bool operator>=(const KDateTime &other) const
Definition: kdatetime.h:1555
KDateTime::Comparison
Comparison
How this KDateTime compares with another.
Definition: kdatetime.h:478
KDateTime::operator>
bool operator>(const KDateTime &other) const
Definition: kdatetime.h:1554
KDateTime::Invalid
an invalid time specification.
Definition: kdatetime.h:183
KTimeZones
The KTimeZones class represents a time zone database which consists of a collection of individual tim...
Definition: ktimezone.h:308
KDateTime::operator<=
bool operator<=(const KDateTime &other) const
Definition: kdatetime.h:1553
QTime
operator==
bool operator==(const KEntry &k1, const KEntry &k2)
Definition: kconfigdata.h:72
KDateTime::TimeFormat
TimeFormat
Format for strings representing date/time values.
Definition: kdatetime.h:419
QDate
ktimezone.h
Time zone functions.
QString
KDateTime
A class representing a date and time with an associated time zone.
Definition: kdatetime.h:171
KTimeZone
Base class representing a time zone.
Definition: ktimezone.h:416
KDateTime::OffsetFromUTC
a local time which has a fixed offset from UTC.
Definition: kdatetime.h:185
operator<<
QDataStream & operator<<(QDataStream &out, const KDateTime::Spec &spec)
Write spec to the datastream out, in binary format.
Definition: kdatetime.cpp:248
KDateTime::UTC
a UTC time.
Definition: kdatetime.h:184
KDateTime::Spec::operator!=
bool operator!=(const Spec &other) const
Definition: kdatetime.h:368
KDateTime::Spec
The full time specification of a KDateTime instance.
Definition: kdatetime.h:223
QSharedDataPointer< KDateTimePrivate >
QDateTime
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:22:11 by doxygen 1.8.7 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 API Reference

Skip menu "kdelibs 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

Search



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