• Skip to content
  • Skip to link menu
KDE 4.7 API Reference
  • KDE API Reference
  • kdelibs
  • KDE Home
  • 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 
00323     typedef QMap<QString, KTimeZone> ZoneMap;
00324 
00330     const ZoneMap zones() const;
00331 
00340     bool add(const KTimeZone &zone);
00341 
00349     KTimeZone remove(const KTimeZone &zone);
00350 
00358     KTimeZone remove(const QString &name);
00359 
00365     void clear();
00366 
00367 private:
00368     KTimeZones(const KTimeZones &);              // prohibit copying
00369     KTimeZones &operator=(const KTimeZones &);   // prohibit copying
00370 
00371     KTimeZonesPrivate * const d;
00372 };
00373 
00374 
00416 class KDECORE_EXPORT KTimeZone  //krazy:exclude=dpointer (has non-const d-pointer to Backend class)
00417 {
00418 public:
00419 
00420     /*
00421      * Time zone phase.
00422      *
00423      * A phase can be daylight savings time or standard time. It holds the
00424      * UTC offset and time zone abbreviation (e.g. EST, GMT).
00425      *
00426      * @short Time zone phase
00427      * @author David Jarvie <djarvie@kde.org>.
00428      */
00429     class KDECORE_EXPORT Phase
00430     {
00431     public:
00432         Phase();
00433 
00443         Phase(int utcOffset, const QByteArray &abbreviations, bool dst,
00444               const QString &comment = QString());
00445 
00454         Phase(int utcOffset, const QList<QByteArray> &abbreviations, bool dst,
00455               const QString &comment = QString());
00456 
00457         Phase(const Phase &rhs);
00458         ~Phase();
00459         Phase &operator=(const Phase &rhs);
00460         bool operator==(const Phase &rhs) const;
00461         bool operator!=(const Phase &rhs) const  { return !operator==(rhs); }
00462 
00470         int utcOffset() const;
00471 
00479         QList<QByteArray> abbreviations() const;
00480 
00486         bool isDst() const;
00487 
00493         QString comment() const;
00494 
00495     private:
00496         QSharedDataPointer<class KTimeZonePhasePrivate> d;
00497     };
00498 
00499 
00500     /*
00501      * Time zone daylight saving time transition.
00502      *
00503      * A Transition instance holds details of a transition to daylight saving time or
00504      * standard time, including the UTC time of the change.
00505      *
00506      * @short Time zone transition
00507      * @author David Jarvie <djarvie@kde.org>.
00508      */
00509     class KDECORE_EXPORT Transition
00510     {
00511     public:
00512         Transition();
00513         Transition(const QDateTime &dt, const Phase &phase);
00514         Transition(const KTimeZone::Transition &t);
00515         ~Transition();
00516         Transition &operator=(const KTimeZone::Transition &t);
00517 
00523         QDateTime time() const;
00524 
00530         Phase phase() const;
00531 
00538         bool operator<(const Transition &rhs) const;
00539 
00540     private:
00541         KTimeZoneTransitionPrivate *const d;
00542     };
00543 
00544 
00545     /*
00546      * Leap seconds adjustment for a time zone.
00547      *
00548      * This class defines a leap seconds adjustment for a time zone by its UTC time of
00549      * occurrence and the cumulative number of leap seconds to be added at that time.
00550      *
00551      * @short Leap seconds adjustment for a time zone
00552      * @see KTimeZone, KTimeZoneData
00553      * @ingroup timezones
00554      * @author David Jarvie <djarvie@kde.org>.
00555      */
00556     class KDECORE_EXPORT LeapSeconds
00557     {
00558     public:
00559         LeapSeconds();
00560         LeapSeconds(const QDateTime &utcTime, int leapSeconds, const QString &comment = QString());
00561         LeapSeconds(const LeapSeconds &c);
00562         ~LeapSeconds();
00563         LeapSeconds &operator=(const LeapSeconds &c);
00564         bool operator<(const LeapSeconds &c) const;    // needed by qSort()
00565 
00571         bool isValid() const;
00572 
00578         QDateTime dateTime() const;
00579 
00586         int leapSeconds() const;
00587 
00593         QString comment() const;
00594 
00595     private:
00596         KTimeZoneLeapSecondsPrivate *const d;
00597     };
00598 
00599 
00605     KTimeZone();
00606 
00612     explicit KTimeZone(const QString &name);
00613 
00614     KTimeZone(const KTimeZone &tz);
00615     KTimeZone &operator=(const KTimeZone &tz);
00616 
00617     virtual ~KTimeZone();
00618 
00628     bool operator==(const KTimeZone &rhs) const;
00629     bool operator!=(const KTimeZone &rhs) const  { return !operator==(rhs); }
00630 
00638     QByteArray type() const;
00639 
00645     bool isValid() const;
00646 
00654     QString name() const;
00655 
00661     QString countryCode() const;
00662 
00668     float latitude() const;
00669 
00675     float longitude() const;
00676 
00682     QString comment() const;
00683 
00692     QList<QByteArray> abbreviations() const;
00693 
00702     QByteArray abbreviation(const QDateTime &utcDateTime) const;
00703 
00718     QList<int> utcOffsets() const;
00719 
00730     QDateTime convert(const KTimeZone &newZone, const QDateTime &zoneDateTime) const;
00731 
00745     QDateTime toUtc(const QDateTime &zoneDateTime) const;
00746 
00761     QDateTime toZoneTime(const QDateTime &utcDateTime, bool *secondOccurrence = 0) const;
00762 
00776     int currentOffset(Qt::TimeSpec basis = Qt::UTC) const;
00777 
00798     virtual int offsetAtZoneTime(const QDateTime &zoneDateTime, int *secondOffset = 0) const;
00799 
00819     virtual int offsetAtUtc(const QDateTime &utcDateTime) const;
00820 
00835     virtual int offset(time_t t) const;
00836 
00853     virtual bool isDstAtUtc(const QDateTime &utcDateTime) const;
00854 
00866     virtual bool isDst(time_t t) const;
00867 
00878     QList<Phase> phases() const;
00879 
00888     virtual bool hasTransitions() const;
00889 
00907     QList<KTimeZone::Transition> transitions(const QDateTime &start = QDateTime(), const QDateTime &end = QDateTime()) const;
00908 
00929     const KTimeZone::Transition *transition(const QDateTime &dt, const Transition **secondTransition = 0, bool *validTime = 0) const;
00930 
00953     int transitionIndex(const QDateTime &dt, int *secondIndex = 0, bool *validTime = 0) const;
00954 
00974     QList<QDateTime> transitionTimes(const Phase &phase, const QDateTime &start = QDateTime(), const QDateTime &end = QDateTime()) const;
00975 
00985     QList<LeapSeconds> leapSecondChanges() const;
00986 
00992     KTimeZoneSource *source() const;
00993 
00999     bool parse() const;
01000 
01009     const KTimeZoneData *data(bool create = false) const;
01010 
01027     bool updateBase(const KTimeZone &other);
01028 
01038     static QDateTime fromTime_t(time_t t);
01039 
01052     static time_t toTime_t(const QDateTime &utcDateTime);
01053 
01064     static KTimeZone utc();
01065 
01069     static const int InvalidOffset;
01070 
01073     static const time_t InvalidTime_t;
01074 
01079     static const float UNKNOWN;
01080 
01081 protected:
01082     KTimeZone(KTimeZoneBackend *impl);
01083 
01093     void setData(KTimeZoneData *data, KTimeZoneSource *source = 0);
01094 
01095 private:
01096     KTimeZoneBackend *d;
01097 };
01098 
01099 
01116 class KDECORE_EXPORT KTimeZoneBackend  //krazy:exclude=dpointer (non-const d-pointer for KTimeZoneBackend-derived classes)
01117 {
01118 public:
01120     KTimeZoneBackend();
01122     explicit KTimeZoneBackend(const QString &name);
01123 
01124     KTimeZoneBackend(const KTimeZoneBackend &other);
01125     KTimeZoneBackend &operator=(const KTimeZoneBackend &other);
01126     virtual ~KTimeZoneBackend();
01127 
01135     virtual KTimeZoneBackend *clone() const;
01136 
01146     virtual QByteArray type() const;
01147 
01153     virtual int offsetAtZoneTime(const KTimeZone* caller, const QDateTime &zoneDateTime, int *secondOffset) const;
01159     virtual int offsetAtUtc(const KTimeZone* caller, const QDateTime &utcDateTime) const;
01165     virtual int offset(const KTimeZone* caller, time_t t) const;
01171     virtual bool isDstAtUtc(const KTimeZone* caller, const QDateTime &utcDateTime) const;
01177     virtual bool isDst(const KTimeZone* caller, time_t t) const;
01183     virtual bool hasTransitions(const KTimeZone* caller) const;
01184 
01185 protected:
01198     KTimeZoneBackend(KTimeZoneSource *source, const QString &name,
01199                      const QString &countryCode = QString(), float latitude = KTimeZone::UNKNOWN,
01200                      float longitude = KTimeZone::UNKNOWN, const QString &comment = QString());
01201 
01202 private:
01203     KTimeZonePrivate *d;   // non-const
01204     friend class KTimeZone;
01205 };
01206 
01226 class KDECORE_EXPORT KTimeZoneSource
01227 {
01228 public:
01229     KTimeZoneSource();
01230     virtual ~KTimeZoneSource();
01231 
01248     virtual KTimeZoneData *parse(const KTimeZone &zone) const;
01249 
01257     bool useZoneParse() const;
01258 
01259 protected:
01277     explicit KTimeZoneSource(bool useZoneParse);
01278 
01279 private:
01280     KTimeZoneSourcePrivate * const d;
01281 };
01282 
01283 
01298 class KDECORE_EXPORT KTimeZoneData
01299 {
01300     friend class KTimeZone;
01301 
01302 public:
01303     KTimeZoneData();
01304     KTimeZoneData(const KTimeZoneData &c);
01305     virtual ~KTimeZoneData();
01306     KTimeZoneData &operator=(const KTimeZoneData &c);
01307 
01316     virtual KTimeZoneData *clone() const;
01317 
01326     virtual QList<QByteArray> abbreviations() const;
01327 
01336     virtual QByteArray abbreviation(const QDateTime &utcDateTime) const;
01337 
01347     virtual QList<int> utcOffsets() const;
01348 
01354     int previousUtcOffset() const;
01355 
01366     QList<KTimeZone::Phase> phases() const;
01367 
01376     virtual bool hasTransitions() const;
01377 
01395     QList<KTimeZone::Transition> transitions(const QDateTime &start = QDateTime(), const QDateTime &end = QDateTime()) const;
01396 
01417     const KTimeZone::Transition *transition(const QDateTime &dt, const KTimeZone::Transition **secondTransition = 0, bool *validTime = 0) const;
01418 
01441     int transitionIndex(const QDateTime &dt, int *secondIndex = 0, bool *validTime = 0) const;
01442 
01462     QList<QDateTime> transitionTimes(const KTimeZone::Phase &phase, const QDateTime &start = QDateTime(), const QDateTime &end = QDateTime()) const;
01463 
01473     QList<KTimeZone::LeapSeconds> leapSecondChanges() const;
01474 
01482     KTimeZone::LeapSeconds leapSecondChange(const QDateTime &utc) const;
01483 
01484 protected:
01493     void setPhases(const QList<KTimeZone::Phase> &phases, int previousUtcOffset);
01494 
01501     void setTransitions(const QList<KTimeZone::Transition> &transitions);
01502 
01509     void setLeapSecondChanges(const QList<KTimeZone::LeapSeconds> &adjusts);
01510 
01511 private:
01512     KTimeZoneDataPrivate * const d;
01513 };
01514 
01515 #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