• Skip to content
  • Skip to link menu
KDE 4.7 API Reference
  • KDE API Reference
  • kdelibs
  • KDE Home
  • 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-2011 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/QMetaType>
00033 #include <QtCore/QSharedDataPointer>
00034 
00035 class QDataStream;
00036 class KDateTimePrivate;
00037 class KDateTimeSpecPrivate;
00038 
00171 class KDECORE_EXPORT KDateTime //krazy:exclude=dpointer (implicitly shared)
00172 {
00173   public:
00181     enum SpecType
00182     {
00183         Invalid,    
00184         UTC,        
00185         OffsetFromUTC, 
00186         TimeZone,   
00191         LocalZone,  
00203         ClockTime   
00215     };
00216 
00223     class KDECORE_EXPORT Spec
00224     {
00225       public:
00229         Spec();
00230 
00237         Spec(const KTimeZone &tz);   // allow implicit conversion
00238 
00246         Spec(SpecType type, int utcOffset = 0);   // allow implicit conversion
00247 
00251         Spec(const Spec& spec);
00252 
00256         Spec& operator=(const Spec& spec);
00257 
00261         ~Spec();
00262 
00268         bool isValid() const;
00269 
00280         KTimeZone timeZone() const;
00281 
00291         SpecType type() const;
00292 
00300         bool isLocalZone() const;
00301 
00308         bool isClockTime() const;
00309 
00318         bool isUtc() const;
00319 
00327         bool isOffsetFromUtc() const;
00328 
00336         int utcOffset() const;
00337 
00347         void setType(SpecType type, int utcOffset = 0);
00348 
00358         void setType(const KTimeZone &tz);
00359 
00366         bool operator==(const Spec &other) const;
00367 
00368         bool operator!=(const Spec &other) const { return !operator==(other); }
00369 
00383         bool equivalentTo(const Spec &other) const;
00384 
00389         static Spec UTC();
00390 
00395         static Spec ClockTime();
00396 
00404         static Spec OffsetFromUTC(int utcOffset);
00405 
00412         static Spec LocalZone();
00413 
00414     private:
00415         KDateTimeSpecPrivate* const d;
00416     };
00417 
00419     enum TimeFormat
00420     {
00421         ISODate,    
00435         RFCDate,    
00442         RFCDateDay, 
00445         QtTextDate, 
00449         LocalDate,  
00453         RFC3339Date 
00458     };
00459 
00478     enum Comparison
00479     {
00480         Before  = 0x01, 
00483         AtStart = 0x02, 
00487         Inside  = 0x04, 
00491         AtEnd   = 0x08, 
00495         After   = 0x10, 
00498         Equal = AtStart | Inside | AtEnd,
00501         Outside = Before | AtStart | Inside | AtEnd | After,
00506         StartsAt = AtStart | Inside | AtEnd | After,
00511         EndsAt = Before | AtStart | Inside | AtEnd
00516    };
00517 
00518   
00522     KDateTime();
00523 
00541     explicit KDateTime(const QDate &date, const Spec &spec = Spec(LocalZone));
00542 
00560     KDateTime(const QDate &date, const QTime &time, const Spec &spec = Spec(LocalZone));
00561 
00591     KDateTime(const QDateTime &dt, const Spec &spec);
00592 
00600     explicit KDateTime(const QDateTime &dt);
00601 
00602     KDateTime(const KDateTime &other);
00603     ~KDateTime();
00604 
00605     KDateTime &operator=(const KDateTime &other);
00606 
00613     bool isNull() const;
00614 
00621     bool isValid() const;
00622 
00628     bool isDateOnly() const;
00629 
00637     QDate date() const;
00638 
00647     QTime time() const;
00648 
00660     QDateTime dateTime() const;
00661 
00670     KTimeZone timeZone() const;
00671 
00679     Spec timeSpec() const;
00680 
00690     SpecType timeType() const;
00691 
00699     bool isLocalZone() const;
00700 
00707     bool isClockTime() const;
00708 
00718     bool isUtc() const;
00719 
00727     bool isOffsetFromUtc() const;
00728 
00736     int utcOffset() const;
00737 
00756     bool isSecondOccurrence() const;
00757 
00769     KDateTime toUtc() const;
00770 
00786     KDateTime toOffsetFromUtc() const;
00787 
00800     KDateTime toOffsetFromUtc(int utcOffset) const;
00801 
00810     KDateTime toLocalZone() const;
00811 
00822     KDateTime toClockTime() const;
00823 
00835     KDateTime toZone(const KTimeZone &zone) const;
00836 
00848     KDateTime toTimeSpec(const Spec &spec) const;
00849 
00861     KDateTime toTimeSpec(const KDateTime &dt) const;
00862 
00870     uint toTime_t() const;
00871 
00879     void setTime_t(qint64 seconds);
00880 
00890     void setDateOnly(bool dateOnly);
00891 
00898     void setDate(const QDate &date);
00899 
00907     void setTime(const QTime &time);
00908 
00923     void setDateTime(const QDateTime &dt);
00924 
00936     void setTimeSpec(const Spec &spec);
00937 
00961     void setSecondOccurrence(bool second);
00962 
00981     KDateTime addMSecs(qint64 msecs) const;
00982 
01001     KDateTime addSecs(qint64 secs) const;
01002 
01015     KDateTime addDays(int days) const;
01016 
01029     KDateTime addMonths(int months) const;
01030 
01043     KDateTime addYears(int years) const;
01044 
01070     int secsTo(const KDateTime &other) const;
01071 
01097     qint64 secsTo_long(const KDateTime &other) const;
01098 
01122     int daysTo(const KDateTime &other) const;
01123 
01131     static KDateTime currentLocalDateTime();
01132 
01140     static KDateTime currentUtcDateTime();
01141 
01154     static KDateTime currentDateTime(const Spec &spec);
01155 
01164     static QDate currentLocalDate();
01165 
01174     static QTime currentLocalTime();
01175 
01243     QString toString(const QString &format) const;
01244 
01266     QString toString(TimeFormat format = ISODate) const;
01267 
01308     static KDateTime fromString(const QString &string, TimeFormat format = ISODate, bool *negZero = 0);
01309 
01447     static KDateTime fromString(const QString &string, const QString &format,
01448                                 const KTimeZones *zones = 0, bool offsetIfAmbiguous = true);
01449 
01462     static void setFromStringDefault(const Spec &spec);
01463 
01464 
01476     bool outOfRange() const;
01477 
01506     Comparison compare(const KDateTime &other) const;
01507 
01528     bool operator==(const KDateTime &other) const;
01529 
01530     bool operator!=(const KDateTime &other) const { return !(*this == other); }
01531 
01551     bool operator<(const KDateTime &other) const;
01552 
01553     bool operator<=(const KDateTime &other) const { return !(other < *this); }
01554     bool operator>(const KDateTime &other) const { return other < *this; }
01555     bool operator>=(const KDateTime &other) const { return !(*this < other); }
01556 
01568     void detach();
01569 
01600     static void setSimulatedSystemTime(const KDateTime& newTime);
01601 
01619     static KDateTime realCurrentLocalDateTime();
01620 
01621     friend QDataStream KDECORE_EXPORT &operator<<(QDataStream &out, const KDateTime &dateTime);
01622     friend QDataStream KDECORE_EXPORT &operator>>(QDataStream &in, KDateTime &dateTime);
01623 
01624   private:
01625     QSharedDataPointer<KDateTimePrivate> d;
01626 };
01627 
01628 Q_DECLARE_METATYPE(KDateTime)
01629 Q_DECLARE_METATYPE(KDateTime::Spec)
01630 
01632 QDataStream KDECORE_EXPORT &operator<<(QDataStream &out, const KDateTime::Spec &spec);
01634 QDataStream KDECORE_EXPORT &operator>>(QDataStream &in, KDateTime::Spec &spec);
01635 
01637 QDataStream KDECORE_EXPORT &operator<<(QDataStream &out, const KDateTime &dateTime);
01639 QDataStream KDECORE_EXPORT &operator>>(QDataStream &in, KDateTime &dateTime);
01640 
01641 #endif

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

Skip menu "kdelibs"
  • 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
Generated for kdelibs by doxygen 1.7.5
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