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

KDECore

kdatetime.h

Go to the documentation of this file.
00001 /*
00002     This file is part of the KDE libraries
00003     Copyright (c) 2005-2009 David Jarvie <djarvie@kde.org>
00004 
00005     This library is free software; you can redistribute it and/or
00006     modify it under the terms of the GNU Library General Public
00007     License as published by the Free Software Foundation; either
00008     version 2 of the License, or (at your option) any later version.
00009 
00010     This library is distributed in the hope that it will be useful,
00011     but WITHOUT ANY WARRANTY; without even the implied warranty of
00012     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013     Library General Public License for more details.
00014 
00015     You should have received a copy of the GNU Library General Public License
00016     along with this library; see the file COPYING.LIB.  If not, write to
00017     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00018     Boston, MA 02110-1301, USA.
00019 */
00020 
00026 #ifndef _KDATETIME_H_
00027 #define _KDATETIME_H_
00028 
00029 #include <kdecore_export.h>
00030 #include <ktimezone.h>
00031 
00032 #include <QtCore/QSharedDataPointer>
00033 
00034 class QDataStream;
00035 class KDateTimePrivate;
00036 class KDateTimeSpecPrivate;
00037 
00170 class KDECORE_EXPORT KDateTime //krazy:exclude=dpointer (implicitly shared)
00171 {
00172   public:
00180     enum SpecType
00181     {
00182         Invalid,    
00183         UTC,        
00184         OffsetFromUTC, 
00185         TimeZone,   
00190         LocalZone,  
00202         ClockTime   
00214     };
00215 
00222     class KDECORE_EXPORT Spec
00223     {
00224       public:
00228         Spec();
00229 
00236         Spec(const KTimeZone &tz);   // allow implicit conversion
00237 
00245         Spec(SpecType type, int utcOffset = 0);   // allow implicit conversion
00246 
00250         Spec(const Spec& spec);
00251 
00255         Spec& operator=(const Spec& spec);
00256 
00260         ~Spec();
00261 
00267         bool isValid() const;
00268 
00279         KTimeZone timeZone() const;
00280 
00290         SpecType type() const;
00291 
00299         bool isLocalZone() const;
00300 
00307         bool isClockTime() const;
00308 
00317         bool isUtc() const;
00318 
00326         bool isOffsetFromUtc() const;
00327 
00335         int utcOffset() const;
00336 
00346         void setType(SpecType type, int utcOffset = 0);
00347 
00357         void setType(const KTimeZone &tz);
00358 
00365         bool operator==(const Spec &other) const;
00366 
00367         bool operator!=(const Spec &other) const { return !operator==(other); }
00368 
00382         bool equivalentTo(const Spec &other) const;
00383 
00388         static Spec UTC();
00389 
00394         static Spec ClockTime();
00395 
00403         static Spec OffsetFromUTC(int utcOffset);
00404 
00411         static Spec LocalZone();
00412 
00413     private:
00414         KDateTimeSpecPrivate* const d;
00415     };
00416 
00418     enum TimeFormat
00419     {
00420         ISODate,    
00434         RFCDate,    
00441         RFCDateDay, 
00444         QtTextDate, 
00448         LocalDate   
00452     };
00453 
00472     enum Comparison
00473     {
00474         Before  = 0x01, 
00477         AtStart = 0x02, 
00481         Inside  = 0x04, 
00485         AtEnd   = 0x08, 
00489         After   = 0x10, 
00492         Equal = AtStart | Inside | AtEnd,
00495         Outside = Before | AtStart | Inside | AtEnd | After,
00500         StartsAt = AtStart | Inside | AtEnd | After,
00505         EndsAt = Before | AtStart | Inside | AtEnd
00510    };
00511 
00512   
00516     KDateTime();
00517 
00535     explicit KDateTime(const QDate &date, const Spec &spec = Spec(LocalZone));
00536 
00554     KDateTime(const QDate &date, const QTime &time, const Spec &spec = Spec(LocalZone));
00555 
00585     KDateTime(const QDateTime &dt, const Spec &spec);
00586 
00594     explicit KDateTime(const QDateTime &dt);
00595 
00596     KDateTime(const KDateTime &other);
00597     ~KDateTime();
00598 
00599     KDateTime &operator=(const KDateTime &other);
00600 
00607     bool isNull() const;
00608 
00615     bool isValid() const;
00616 
00622     bool isDateOnly() const;
00623 
00631     QDate date() const;
00632 
00641     QTime time() const;
00642 
00654     QDateTime dateTime() const;
00655 
00664     KTimeZone timeZone() const;
00665 
00673     Spec timeSpec() const;
00674 
00684     SpecType timeType() const;
00685 
00693     bool isLocalZone() const;
00694 
00701     bool isClockTime() const;
00702 
00712     bool isUtc() const;
00713 
00721     bool isOffsetFromUtc() const;
00722 
00730     int utcOffset() const;
00731 
00750     bool isSecondOccurrence() const;
00751 
00763     KDateTime toUtc() const;
00764 
00780     KDateTime toOffsetFromUtc() const;
00781 
00794     KDateTime toOffsetFromUtc(int utcOffset) const;
00795 
00804     KDateTime toLocalZone() const;
00805 
00816     KDateTime toClockTime() const;
00817 
00829     KDateTime toZone(const KTimeZone &zone) const;
00830 
00842     KDateTime toTimeSpec(const Spec &spec) const;
00843 
00855     KDateTime toTimeSpec(const KDateTime &dt) const;
00856 
00864     uint toTime_t() const;
00865 
00873     void setTime_t(qint64 seconds);
00874 
00884     void setDateOnly(bool dateOnly);
00885 
00892     void setDate(const QDate &date);
00893 
00901     void setTime(const QTime &time);
00902 
00917     void setDateTime(const QDateTime &dt);
00918 
00930     void setTimeSpec(const Spec &spec);
00931 
00955     void setSecondOccurrence(bool second);
00956 
00975     KDateTime addMSecs(qint64 msecs) const;
00976 
00995     KDateTime addSecs(qint64 secs) const;
00996 
01009     KDateTime addDays(int days) const;
01010 
01023     KDateTime addMonths(int months) const;
01024 
01037     KDateTime addYears(int years) const;
01038 
01064     int secsTo(const KDateTime &other) const;
01065 
01091     qint64 secsTo_long(const KDateTime &other) const;
01092 
01116     int daysTo(const KDateTime &other) const;
01117 
01125     static KDateTime currentLocalDateTime();
01126 
01134     static KDateTime currentUtcDateTime();
01135 
01144     static KDateTime currentDateTime(const Spec &spec);
01145 
01153     static QDate currentLocalDate();
01154 
01162     static QTime currentLocalTime();
01163 
01231     QString toString(const QString &format) const;
01232 
01254     QString toString(TimeFormat format = ISODate) const;
01255 
01295     static KDateTime fromString(const QString &string, TimeFormat format = ISODate, bool *negZero = 0);
01296 
01434     static KDateTime fromString(const QString &string, const QString &format,
01435                                 const KTimeZones *zones = 0, bool offsetIfAmbiguous = true);
01436 
01449     static void setFromStringDefault(const Spec &spec);
01450 
01451 
01463     bool outOfRange() const;
01464 
01493     Comparison compare(const KDateTime &other) const;
01494 
01512     bool operator==(const KDateTime &other) const;
01513 
01514     bool operator!=(const KDateTime &other) const { return !(*this == other); }
01515 
01535     bool operator<(const KDateTime &other) const;
01536 
01537     bool operator<=(const KDateTime &other) const { return !(other < *this); }
01538     bool operator>(const KDateTime &other) const { return other < *this; }
01539     bool operator>=(const KDateTime &other) const { return !(*this < other); }
01540 
01552     void detach();
01553 
01583     static void setSimulatedSystemTime(const KDateTime& newTime);
01584 
01600     static KDateTime realCurrentLocalDateTime();
01601 
01602     friend QDataStream &operator<<(QDataStream &out, const KDateTime &dateTime);
01603     friend QDataStream &operator>>(QDataStream &in, KDateTime &dateTime);
01604 
01605   private:
01606     QSharedDataPointer<KDateTimePrivate> d;
01607 };
01608 
01610 QDataStream &operator<<(QDataStream &out, const KDateTime::Spec &spec);
01612 QDataStream &operator>>(QDataStream &in, KDateTime::Spec &spec);
01613 
01615 QDataStream &operator<<(QDataStream &out, const KDateTime &dateTime);
01617 QDataStream &operator>>(QDataStream &in, KDateTime &dateTime);
01618 
01619 #endif

KDECore

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

kdelibs

Skip menu "kdelibs"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • Kate
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.6.1
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal