• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdelibs-4.8.3 API Reference
  • 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:
00436         Phase();
00437 
00447         Phase(int utcOffset, const QByteArray &abbreviations, bool dst,
00448               const QString &comment = QString());
00449 
00458         Phase(int utcOffset, const QList<QByteArray> &abbreviations, bool dst,
00459               const QString &comment = QString());
00460 
00461         Phase(const Phase &rhs);
00462         ~Phase();
00463         Phase &operator=(const Phase &rhs);
00464         bool operator==(const Phase &rhs) const;
00465         bool operator!=(const Phase &rhs) const  { return !operator==(rhs); }
00466 
00474         int utcOffset() const;
00475 
00483         QList<QByteArray> abbreviations() const;
00484 
00490         bool isDst() const;
00491 
00497         QString comment() const;
00498 
00499     private:
00500         QSharedDataPointer<class KTimeZonePhasePrivate> d;
00501     };
00502 
00503 
00504     /*
00505      * Time zone daylight saving time transition.
00506      *
00507      * A Transition instance holds details of a transition to daylight saving time or
00508      * standard time, including the UTC time of the change.
00509      *
00510      * @short Time zone transition
00511      * @author David Jarvie <djarvie@kde.org>.
00512      */
00513     class KDECORE_EXPORT Transition
00514     {
00515     public:
00516         Transition();
00517         Transition(const QDateTime &dt, const Phase &phase);
00518         Transition(const KTimeZone::Transition &t);
00519         ~Transition();
00520         Transition &operator=(const KTimeZone::Transition &t);
00521 
00527         QDateTime time() const;
00528 
00534         Phase phase() const;
00535 
00542         bool operator<(const Transition &rhs) const;
00543 
00544     private:
00545         KTimeZoneTransitionPrivate *const d;
00546     };
00547 
00548 
00549     /*
00550      * Leap seconds adjustment for a time zone.
00551      *
00552      * This class defines a leap seconds adjustment for a time zone by its UTC time of
00553      * occurrence and the cumulative number of leap seconds to be added at that time.
00554      *
00555      * @short Leap seconds adjustment for a time zone
00556      * @see KTimeZone, KTimeZoneData
00557      * @ingroup timezones
00558      * @author David Jarvie <djarvie@kde.org>.
00559      */
00560     class KDECORE_EXPORT LeapSeconds
00561     {
00562     public:
00563         LeapSeconds();
00564         LeapSeconds(const QDateTime &utcTime, int leapSeconds, const QString &comment = QString());
00565         LeapSeconds(const LeapSeconds &c);
00566         ~LeapSeconds();
00567         LeapSeconds &operator=(const LeapSeconds &c);
00568         bool operator<(const LeapSeconds &c) const;    // needed by qSort()
00569 
00575         bool isValid() const;
00576 
00582         QDateTime dateTime() const;
00583 
00590         int leapSeconds() const;
00591 
00597         QString comment() const;
00598 
00599     private:
00600         KTimeZoneLeapSecondsPrivate *const d;
00601     };
00602 
00603 
00609     KTimeZone();
00610 
00616     explicit KTimeZone(const QString &name);
00617 
00618     KTimeZone(const KTimeZone &tz);
00619     KTimeZone &operator=(const KTimeZone &tz);
00620 
00621     virtual ~KTimeZone();
00622 
00632     bool operator==(const KTimeZone &rhs) const;
00633     bool operator!=(const KTimeZone &rhs) const  { return !operator==(rhs); }
00634 
00642     QByteArray type() const;
00643 
00649     bool isValid() const;
00650 
00658     QString name() const;
00659 
00665     QString countryCode() const;
00666 
00672     float latitude() const;
00673 
00679     float longitude() const;
00680 
00686     QString comment() const;
00687 
00696     QList<QByteArray> abbreviations() const;
00697 
00706     QByteArray abbreviation(const QDateTime &utcDateTime) const;
00707 
00722     QList<int> utcOffsets() const;
00723 
00734     QDateTime convert(const KTimeZone &newZone, const QDateTime &zoneDateTime) const;
00735 
00749     QDateTime toUtc(const QDateTime &zoneDateTime) const;
00750 
00765     QDateTime toZoneTime(const QDateTime &utcDateTime, bool *secondOccurrence = 0) const;
00766 
00780     int currentOffset(Qt::TimeSpec basis = Qt::UTC) const;
00781 
00802     virtual int offsetAtZoneTime(const QDateTime &zoneDateTime, int *secondOffset = 0) const;
00803 
00823     virtual int offsetAtUtc(const QDateTime &utcDateTime) const;
00824 
00839     virtual int offset(time_t t) const;
00840 
00857     virtual bool isDstAtUtc(const QDateTime &utcDateTime) const;
00858 
00870     virtual bool isDst(time_t t) const;
00871 
00882     QList<Phase> phases() const;
00883 
00892     virtual bool hasTransitions() const;
00893 
00911     QList<KTimeZone::Transition> transitions(const QDateTime &start = QDateTime(), const QDateTime &end = QDateTime()) const;
00912 
00933     const KTimeZone::Transition *transition(const QDateTime &dt, const Transition **secondTransition = 0, bool *validTime = 0) const;
00934 
00957     int transitionIndex(const QDateTime &dt, int *secondIndex = 0, bool *validTime = 0) const;
00958 
00978     QList<QDateTime> transitionTimes(const Phase &phase, const QDateTime &start = QDateTime(), const QDateTime &end = QDateTime()) const;
00979 
00989     QList<LeapSeconds> leapSecondChanges() const;
00990 
00996     KTimeZoneSource *source() const;
00997 
01003     bool parse() const;
01004 
01013     const KTimeZoneData *data(bool create = false) const;
01014 
01031     bool updateBase(const KTimeZone &other);
01032 
01042     static QDateTime fromTime_t(time_t t);
01043 
01056     static time_t toTime_t(const QDateTime &utcDateTime);
01057 
01068     static KTimeZone utc();
01069 
01073     static const int InvalidOffset;
01074 
01077     static const time_t InvalidTime_t;
01078 
01083     static const float UNKNOWN;
01084 
01085 protected:
01086     KTimeZone(KTimeZoneBackend *impl);
01087 
01097     void setData(KTimeZoneData *data, KTimeZoneSource *source = 0);
01098 
01099 private:
01100     KTimeZoneBackend *d;
01101 };
01102 
01103 
01120 class KDECORE_EXPORT KTimeZoneBackend  //krazy:exclude=dpointer (non-const d-pointer for KTimeZoneBackend-derived classes)
01121 {
01122 public:
01124     KTimeZoneBackend();
01126     explicit KTimeZoneBackend(const QString &name);
01127 
01128     KTimeZoneBackend(const KTimeZoneBackend &other);
01129     KTimeZoneBackend &operator=(const KTimeZoneBackend &other);
01130     virtual ~KTimeZoneBackend();
01131 
01139     virtual KTimeZoneBackend *clone() const;
01140 
01150     virtual QByteArray type() const;
01151 
01157     virtual int offsetAtZoneTime(const KTimeZone* caller, const QDateTime &zoneDateTime, int *secondOffset) const;
01163     virtual int offsetAtUtc(const KTimeZone* caller, const QDateTime &utcDateTime) const;
01169     virtual int offset(const KTimeZone* caller, time_t t) const;
01175     virtual bool isDstAtUtc(const KTimeZone* caller, const QDateTime &utcDateTime) const;
01181     virtual bool isDst(const KTimeZone* caller, time_t t) const;
01187     virtual bool hasTransitions(const KTimeZone* caller) const;
01188 
01189 protected:
01202     KTimeZoneBackend(KTimeZoneSource *source, const QString &name,
01203                      const QString &countryCode = QString(), float latitude = KTimeZone::UNKNOWN,
01204                      float longitude = KTimeZone::UNKNOWN, const QString &comment = QString());
01205 
01206 private:
01207     KTimeZonePrivate *d;   // non-const
01208     friend class KTimeZone;
01209 };
01210 
01230 class KDECORE_EXPORT KTimeZoneSource
01231 {
01232 public:
01233     KTimeZoneSource();
01234     virtual ~KTimeZoneSource();
01235 
01252     virtual KTimeZoneData *parse(const KTimeZone &zone) const;
01253 
01261     bool useZoneParse() const;
01262 
01263 protected:
01281     explicit KTimeZoneSource(bool useZoneParse);
01282 
01283 private:
01284     KTimeZoneSourcePrivate * const d;
01285 };
01286 
01287 
01302 class KDECORE_EXPORT KTimeZoneData
01303 {
01304     friend class KTimeZone;
01305 
01306 public:
01307     KTimeZoneData();
01308     KTimeZoneData(const KTimeZoneData &c);
01309     virtual ~KTimeZoneData();
01310     KTimeZoneData &operator=(const KTimeZoneData &c);
01311 
01320     virtual KTimeZoneData *clone() const;
01321 
01330     virtual QList<QByteArray> abbreviations() const;
01331 
01340     virtual QByteArray abbreviation(const QDateTime &utcDateTime) const;
01341 
01351     virtual QList<int> utcOffsets() const;
01352 
01358     int previousUtcOffset() const;
01359 
01370     QList<KTimeZone::Phase> phases() const;
01371 
01380     virtual bool hasTransitions() const;
01381 
01399     QList<KTimeZone::Transition> transitions(const QDateTime &start = QDateTime(), const QDateTime &end = QDateTime()) const;
01400 
01421     const KTimeZone::Transition *transition(const QDateTime &dt, const KTimeZone::Transition **secondTransition = 0, bool *validTime = 0) const;
01422 
01445     int transitionIndex(const QDateTime &dt, int *secondIndex = 0, bool *validTime = 0) const;
01446 
01466     QList<QDateTime> transitionTimes(const KTimeZone::Phase &phase, const QDateTime &start = QDateTime(), const QDateTime &end = QDateTime()) const;
01467 
01477     QList<KTimeZone::LeapSeconds> leapSecondChanges() const;
01478 
01486     KTimeZone::LeapSeconds leapSecondChange(const QDateTime &utc) const;
01487 
01488 protected:
01498     void setPhases(const QList<KTimeZone::Phase> &phases, const KTimeZone::Phase& previousPhase);
01499 
01510     void setPhases(const QList<KTimeZone::Phase> &phases, int previousUtcOffset);
01511 
01518     void setTransitions(const QList<KTimeZone::Transition> &transitions);
01519 
01526     void setLeapSecondChanges(const QList<KTimeZone::LeapSeconds> &adjusts);
01527 
01528 private:
01529     KTimeZoneDataPrivate * const d;
01530 };
01531 
01532 #endif
This file is part of the KDE documentation.
Documentation copyright © 1996-2012 The KDE developers.
Generated on Thu May 10 2012 20:49:33 by doxygen 1.8.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

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-4.8.3 API Reference

Skip menu "kdelibs-4.8.3 API Reference"
  • 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
Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal