• Skip to content
  • Skip to link menu
KDE 4.1 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-2008 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 
00160 class KDECORE_EXPORT KDateTime //krazy:exclude=dpointer (implicitly shared)
00161 {
00162   public:
00170     enum SpecType
00171     {
00172         Invalid,    
00173         UTC,        
00174         OffsetFromUTC, 
00175         TimeZone,   
00180         LocalZone,  
00192         ClockTime   
00204     };
00205 
00212     class KDECORE_EXPORT Spec
00213     {
00214       public:
00218         Spec();
00219 
00226         Spec(const KTimeZone &tz);   // allow implicit conversion
00227 
00235         Spec(SpecType type, int utcOffset = 0);   // allow implicit conversion
00236 
00240         Spec(const Spec& spec);
00241 
00245         Spec& operator=(const Spec& spec);
00246 
00250         ~Spec();
00251 
00257         bool isValid() const;
00258 
00269         KTimeZone timeZone() const;
00270 
00280         SpecType type() const;
00281 
00289         bool isLocalZone() const;
00290 
00297         bool isClockTime() const;
00298 
00307         bool isUtc() const;
00308 
00316         bool isOffsetFromUtc() const;
00317 
00325         int utcOffset() const;
00326 
00336         void setType(SpecType type, int utcOffset = 0);
00337 
00347         void setType(const KTimeZone &tz);
00348 
00355         bool operator==(const Spec &other) const;
00356 
00357         bool operator!=(const Spec &other) const { return !operator==(other); }
00358 
00372         bool equivalentTo(const Spec &other) const;
00373 
00378         static Spec UTC();
00379 
00384         static Spec ClockTime();
00385 
00393         static Spec OffsetFromUTC(int utcOffset);
00394 
00401         static Spec LocalZone();
00402 
00403     private:
00404         KDateTimeSpecPrivate* const d;
00405     };
00406 
00408     enum TimeFormat
00409     {
00410         ISODate,    
00424         RFCDate,    
00431         RFCDateDay, 
00434         QtTextDate, 
00438         LocalDate   
00442     };
00443 
00462     enum Comparison
00463     {
00464         Before  = 0x01, 
00467         AtStart = 0x02, 
00471         Inside  = 0x04, 
00475         AtEnd   = 0x08, 
00479         After   = 0x10, 
00482         Equal = AtStart | Inside | AtEnd,
00485         Outside = Before | AtStart | Inside | AtEnd | After,
00490         StartsAt = AtStart | Inside | AtEnd | After,
00495         EndsAt = Before | AtStart | Inside | AtEnd
00500    };
00501 
00502   
00506     KDateTime();
00507 
00525     explicit KDateTime(const QDate &date, const Spec &spec = Spec(LocalZone));
00526 
00544     KDateTime(const QDate &date, const QTime &time, const Spec &spec = Spec(LocalZone));
00545 
00575     KDateTime(const QDateTime &dt, const Spec &spec);
00576 
00584     explicit KDateTime(const QDateTime &dt);
00585 
00586     KDateTime(const KDateTime &other);
00587     ~KDateTime();
00588 
00589     KDateTime &operator=(const KDateTime &other);
00590 
00597     bool isNull() const;
00598 
00605     bool isValid() const;
00606 
00612     bool isDateOnly() const;
00613 
00621     QDate date() const;
00622 
00631     QTime time() const;
00632 
00644     QDateTime dateTime() const;
00645 
00654     KTimeZone timeZone() const;
00655 
00663     Spec timeSpec() const;
00664 
00674     SpecType timeType() const;
00675 
00683     bool isLocalZone() const;
00684 
00691     bool isClockTime() const;
00692 
00702     bool isUtc() const;
00703 
00711     bool isOffsetFromUtc() const;
00712 
00720     int utcOffset() const;
00721 
00740     bool isSecondOccurrence() const;
00741 
00753     KDateTime toUtc() const;
00754 
00770     KDateTime toOffsetFromUtc() const;
00771 
00784     KDateTime toOffsetFromUtc(int utcOffset) const;
00785 
00794     KDateTime toLocalZone() const;
00795 
00806     KDateTime toClockTime() const;
00807 
00819     KDateTime toZone(const KTimeZone &zone) const;
00820 
00832     KDateTime toTimeSpec(const Spec &spec) const;
00833 
00845     KDateTime toTimeSpec(const KDateTime &dt) const;
00846 
00854     uint toTime_t() const;
00855 
00863     void setTime_t(qint64 seconds);
00864 
00874     void setDateOnly(bool dateOnly);
00875 
00882     void setDate(const QDate &date);
00883 
00891     void setTime(const QTime &time);
00892 
00907     void setDateTime(const QDateTime &dt);
00908 
00920     void setTimeSpec(const Spec &spec);
00921 
00945     void setSecondOccurrence(bool second);
00946 
00965     KDateTime addMSecs(qint64 msecs) const;
00966 
00985     KDateTime addSecs(qint64 secs) const;
00986 
00999     KDateTime addDays(int days) const;
01000 
01013     KDateTime addMonths(int months) const;
01014 
01027     KDateTime addYears(int years) const;
01028 
01054     int secsTo(const KDateTime &other) const;
01055 
01081     qint64 secsTo_long(const KDateTime &other) const;
01082 
01106     int daysTo(const KDateTime &other) const;
01107 
01115     static KDateTime currentLocalDateTime();
01116 
01124     static KDateTime currentUtcDateTime();
01125 
01134     static KDateTime currentDateTime(const Spec &spec);
01135 
01203     QString toString(const QString &format) const;
01204 
01226     QString toString(TimeFormat format = ISODate) const;
01227 
01267     static KDateTime fromString(const QString &string, TimeFormat format = ISODate, bool *negZero = 0);
01268 
01406     static KDateTime fromString(const QString &string, const QString &format,
01407                                 const KTimeZones *zones = 0, bool offsetIfAmbiguous = true);
01408 
01421     static void setFromStringDefault(const Spec &spec);
01422 
01423 
01435     bool outOfRange() const;
01436 
01465     Comparison compare(const KDateTime &other) const;
01466 
01484     bool operator==(const KDateTime &other) const;
01485 
01486     bool operator!=(const KDateTime &other) const { return !(*this == other); }
01487 
01507     bool operator<(const KDateTime &other) const;
01508 
01509     bool operator<=(const KDateTime &other) const { return !(other < *this); }
01510     bool operator>(const KDateTime &other) const { return other < *this; }
01511     bool operator>=(const KDateTime &other) const { return !(*this < other); }
01512 
01524     void detach();
01525 
01527     friend QDataStream &operator<<(QDataStream &out, const KDateTime &dateTime);
01529     friend QDataStream &operator>>(QDataStream &in, KDateTime &dateTime);
01530 
01531   private:
01532     QSharedDataPointer<KDateTimePrivate> d;
01533 };
01534 
01536 QDataStream &operator<<(QDataStream &out, const KDateTime::Spec &spec);
01538 QDataStream &operator>>(QDataStream &in, KDateTime::Spec &spec);
01539 
01541 QDataStream &operator<<(QDataStream &out, const KDateTime &dateTime);
01543 QDataStream &operator>>(QDataStream &in, KDateTime &dateTime);
01544 
01545 #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
  • Kross
  • KUtils
  • Nepomuk
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.5.4
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