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

KDECore

ktimezone.h

Go to the documentation of this file.
00001 /*
00002    This file is part of the KDE libraries
00003    Copyright (c) 2005-2007 David Jarvie <djarvie@kde.org>
00004    Copyright (c) 2005 S.R.Haque <srhaque@iee.org>.
00005 
00006    This library is free software; you can redistribute it and/or
00007    modify it under the terms of the GNU Library General Public
00008    License as published by the Free Software Foundation; either
00009    version 2 of the License, or (at your option) any later version.
00010 
00011    This library is distributed in the hope that it will be useful,
00012    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014    Library General Public License for more details.
00015 
00016    You should have received a copy of the GNU Library General Public License
00017    along with this library; see the file COPYING.LIB.  If not, write to
00018    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00019    Boston, MA 02110-1301, USA.
00020 */
00021 
00028 #ifndef _KTIMEZONES_H
00029 #define _KTIMEZONES_H
00030 
00031 #include <kdecore_export.h>
00032 
00033 #include <sys/time.h>
00034 #include <ctime>
00035 
00036 #include <QtCore/QDateTime>
00037 #include <QtCore/QMap>
00038 #include <QtCore/QList>
00039 #include <QtCore/QString>
00040 #include <QtCore/QByteArray>
00041 #include <QtCore/QSharedDataPointer>
00042 
00043 class KTimeZone;
00044 class KTimeZoneBackend;
00045 class KTimeZoneData;
00046 class KTimeZoneSource;
00047 class KTimeZonesPrivate;
00048 class KTimeZonePrivate;
00049 class KTimeZoneSourcePrivate;
00050 class KTimeZoneDataPrivate;
00051 class KTimeZoneTransitionPrivate;
00052 class KTimeZoneLeapSecondsPrivate;
00053 
00308 class KDECORE_EXPORT KTimeZones
00309 {
00310 public:
00311     KTimeZones();
00312     ~KTimeZones();
00313 
00320     KTimeZone zone(const QString &name) const;
00321 
00322     typedef QMap<QString, KTimeZone> ZoneMap;
00323 
00329     const ZoneMap zones() const;
00330 
00339     bool add(const KTimeZone &zone);
00340 
00348     KTimeZone remove(const KTimeZone &zone);
00349 
00357     KTimeZone remove(const QString &name);
00358 
00364     void clear();
00365 
00366 private:
00367     KTimeZones(const KTimeZones &);              // prohibit copying
00368     KTimeZones &operator=(const KTimeZones &);   // prohibit copying
00369 
00370     KTimeZonesPrivate * const d;
00371 };
00372 
00373 
00415 class KDECORE_EXPORT KTimeZone  //krazy:exclude=dpointer (has non-const d-pointer to Backend class)
00416 {
00417 public:
00418 
00419     /*
00420      * Time zone phase.
00421      *
00422      * A phase can be daylight savings time or standard time. It holds the
00423      * UTC offset and time zone abbreviation (e.g. EST, GMT).
00424      *
00425      * @short Time zone phase
00426      * @author David Jarvie <djarvie@kde.org>.
00427      */
00428     class KDECORE_EXPORT Phase
00429     {
00430     public:
00431         Phase();
00432 
00442         Phase(int utcOffset, const QByteArray &abbreviations, bool dst,
00443               const QString &comment = QString());
00444 
00453         Phase(int utcOffset, const QList<QByteArray> &abbreviations, bool dst,
00454               const QString &comment = QString());
00455 
00456         Phase(const Phase &rhs);
00457         ~Phase();
00458         Phase &operator=(const Phase &rhs);
00459         bool operator==(const Phase &rhs) const;
00460         bool operator!=(const Phase &rhs) const  { return !operator==(rhs); }
00461 
00469         int utcOffset() const;
00470 
00478         QList<QByteArray> abbreviations() const;
00479 
00485         bool isDst() const;
00486 
00492         QString comment() const;
00493 
00494     private:
00495         QSharedDataPointer<class KTimeZonePhasePrivate> d;
00496     };
00497 
00498 
00499     /*
00500      * Time zone daylight saving time transition.
00501      *
00502      * A Transition instance holds details of a transition to daylight saving time or
00503      * standard time, including the UTC time of the change.
00504      *
00505      * @short Time zone transition
00506      * @author David Jarvie <djarvie@kde.org>.
00507      */
00508     class KDECORE_EXPORT Transition
00509     {
00510     public:
00511         Transition();
00512         Transition(const QDateTime &dt, const Phase &phase);
00513         Transition(const KTimeZone::Transition &t);
00514         ~Transition();
00515         Transition &operator=(const KTimeZone::Transition &t);
00516 
00522         QDateTime time() const;
00523 
00529         Phase phase() const;
00530 
00537         bool operator<(const Transition &rhs) const;
00538 
00539     private:
00540         KTimeZoneTransitionPrivate *const d;
00541     };
00542 
00543 
00544     /*
00545      * Leap seconds adjustment for a time zone.
00546      *
00547      * This class defines a leap seconds adjustment for a time zone by its UTC time of
00548      * occurrence and the cumulative number of leap seconds to be added at that time.
00549      *
00550      * @short Leap seconds adjustment for a time zone
00551      * @see KTimeZone, KTimeZoneData
00552      * @ingroup timezones
00553      * @author David Jarvie <djarvie@kde.org>.
00554      */
00555     class KDECORE_EXPORT LeapSeconds
00556     {
00557     public:
00558         LeapSeconds();
00559         LeapSeconds(const QDateTime &utcTime, int leapSeconds, const QString &comment = QString());
00560         LeapSeconds(const LeapSeconds &c);
00561         ~LeapSeconds();
00562         LeapSeconds &operator=(const LeapSeconds &c);
00563         bool operator<(const LeapSeconds &c) const;    // needed by qSort()
00564 
00570         bool isValid() const;
00571 
00577         QDateTime dateTime() const;
00578 
00585         int leapSeconds() const;
00586 
00592         QString comment() const;
00593 
00594     private:
00595         KTimeZoneLeapSecondsPrivate *const d;
00596     };
00597 
00598 
00604     KTimeZone();
00605 
00611     explicit KTimeZone(const QString &name);
00612 
00613     KTimeZone(const KTimeZone &tz);
00614     KTimeZone &operator=(const KTimeZone &tz);
00615 
00616     virtual ~KTimeZone();
00617 
00627     bool operator==(const KTimeZone &rhs) const;
00628     bool operator!=(const KTimeZone &rhs) const  { return !operator==(rhs); }
00629 
00637     QByteArray type() const;
00638 
00644     bool isValid() const;
00645 
00653     QString name() const;
00654 
00660     QString countryCode() const;
00661 
00667     float latitude() const;
00668 
00674     float longitude() const;
00675 
00681     QString comment() const;
00682 
00691     QList<QByteArray> abbreviations() const;
00692 
00701     QByteArray abbreviation(const QDateTime &utcDateTime) const;
00702 
00717     QList<int> utcOffsets() const;
00718 
00729     QDateTime convert(const KTimeZone &newZone, const QDateTime &zoneDateTime) const;
00730 
00744     QDateTime toUtc(const QDateTime &zoneDateTime) const;
00745 
00760     QDateTime toZoneTime(const QDateTime &utcDateTime, bool *secondOccurrence = 0) const;
00761 
00775     int currentOffset(Qt::TimeSpec basis = Qt::UTC) const;
00776 
00797     virtual int offsetAtZoneTime(const QDateTime &zoneDateTime, int *secondOffset = 0) const;
00798 
00818     virtual int offsetAtUtc(const QDateTime &utcDateTime) const;
00819 
00834     virtual int offset(time_t t) const;
00835 
00852     virtual bool isDstAtUtc(const QDateTime &utcDateTime) const;
00853 
00865     virtual bool isDst(time_t t) const;
00866 
00877     QList<Phase> phases() const;
00878 
00887     virtual bool hasTransitions() const;
00888 
00906     QList<KTimeZone::Transition> transitions(const QDateTime &start = QDateTime(), const QDateTime &end = QDateTime()) const;
00907 
00928     const KTimeZone::Transition *transition(const QDateTime &dt, const Transition **secondTransition = 0, bool *validTime = 0) const;
00929 
00952     int transitionIndex(const QDateTime &dt, int *secondIndex = 0, bool *validTime = 0) const;
00953 
00973     QList<QDateTime> transitionTimes(const Phase &phase, const QDateTime &start = QDateTime(), const QDateTime &end = QDateTime()) const;
00974 
00984     QList<LeapSeconds> leapSecondChanges() const;
00985 
00991     KTimeZoneSource *source() const;
00992 
00998     bool parse() const;
00999 
01008     const KTimeZoneData *data(bool create = false) const;
01009 
01026     bool updateBase(const KTimeZone &other);
01027 
01037     static QDateTime fromTime_t(time_t t);
01038 
01051     static time_t toTime_t(const QDateTime &utcDateTime);
01052 
01063     static KTimeZone utc();
01064 
01068     static const int InvalidOffset;
01069 
01072     static const time_t InvalidTime_t;
01073 
01078     static const float UNKNOWN;
01079 
01080 protected:
01081     KTimeZone(KTimeZoneBackend *impl);
01082 
01092     void setData(KTimeZoneData *data, KTimeZoneSource *source = 0);
01093 
01094 private:
01095     KTimeZoneBackend *d;
01096 };
01097 
01098 
01115 class KDECORE_EXPORT KTimeZoneBackend  //krazy:exclude=dpointer (non-const d-pointer for KTimeZoneBackend-derived classes)
01116 {
01117 public:
01119     KTimeZoneBackend();
01121     explicit KTimeZoneBackend(const QString &name);
01122 
01123     KTimeZoneBackend(const KTimeZoneBackend &other);
01124     KTimeZoneBackend &operator=(const KTimeZoneBackend &other);
01125     virtual ~KTimeZoneBackend();
01126 
01134     virtual KTimeZoneBackend *clone() const;
01135 
01143     virtual QByteArray type() const;
01144 
01150     virtual int offsetAtZoneTime(const KTimeZone* caller, const QDateTime &zoneDateTime, int *secondOffset) const;
01156     virtual int offsetAtUtc(const KTimeZone* caller, const QDateTime &utcDateTime) const;
01162     virtual int offset(const KTimeZone* caller, time_t t) const;
01168     virtual bool isDstAtUtc(const KTimeZone* caller, const QDateTime &utcDateTime) const;
01174     virtual bool isDst(const KTimeZone* caller, time_t t) const;
01180     virtual bool hasTransitions(const KTimeZone* caller) const;
01181 
01182 protected:
01195     KTimeZoneBackend(KTimeZoneSource *source, const QString &name,
01196                      const QString &countryCode = QString(), float latitude = KTimeZone::UNKNOWN,
01197                      float longitude = KTimeZone::UNKNOWN, const QString &comment = QString());
01198 
01199 private:
01200     KTimeZonePrivate *d;   // non-const
01201     friend class KTimeZone;
01202 };
01203 
01223 class KDECORE_EXPORT KTimeZoneSource
01224 {
01225 public:
01226     KTimeZoneSource();
01227     virtual ~KTimeZoneSource();
01228 
01245     virtual KTimeZoneData *parse(const KTimeZone &zone) const;
01246 
01254     bool useZoneParse() const;
01255 
01256 protected:
01274     explicit KTimeZoneSource(bool useZoneParse);
01275 
01276 private:
01277     KTimeZoneSourcePrivate * const d;
01278 };
01279 
01280 
01295 class KDECORE_EXPORT KTimeZoneData
01296 {
01297     friend class KTimeZone;
01298 
01299 public:
01300     KTimeZoneData();
01301     KTimeZoneData(const KTimeZoneData &c);
01302     virtual ~KTimeZoneData();
01303     KTimeZoneData &operator=(const KTimeZoneData &c);
01304 
01313     virtual KTimeZoneData *clone() const;
01314 
01323     virtual QList<QByteArray> abbreviations() const;
01324 
01333     virtual QByteArray abbreviation(const QDateTime &utcDateTime) const;
01334 
01344     virtual QList<int> utcOffsets() const;
01345 
01351     int previousUtcOffset() const;
01352 
01363     QList<KTimeZone::Phase> phases() const;
01364 
01373     virtual bool hasTransitions() const;
01374 
01392     QList<KTimeZone::Transition> transitions(const QDateTime &start = QDateTime(), const QDateTime &end = QDateTime()) const;
01393 
01414     const KTimeZone::Transition *transition(const QDateTime &dt, const KTimeZone::Transition **secondTransition = 0, bool *validTime = 0) const;
01415 
01438     int transitionIndex(const QDateTime &dt, int *secondIndex = 0, bool *validTime = 0) const;
01439 
01459     QList<QDateTime> transitionTimes(const KTimeZone::Phase &phase, const QDateTime &start = QDateTime(), const QDateTime &end = QDateTime()) const;
01460 
01470     QList<KTimeZone::LeapSeconds> leapSecondChanges() const;
01471 
01479     KTimeZone::LeapSeconds leapSecondChange(const QDateTime &utc) const;
01480 
01481 protected:
01490     void setPhases(const QList<KTimeZone::Phase> &phases, int previousUtcOffset);
01491 
01498     void setTransitions(const QList<KTimeZone::Transition> &transitions);
01499 
01506     void setLeapSecondChanges(const QList<KTimeZone::LeapSeconds> &adjusts);
01507 
01508 private:
01509     KTimeZoneDataPrivate * const d;
01510 };
01511 
01512 #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