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

KDECore

  • sources
  • kde-4.14
  • kdelibs
  • kdecore
  • date
ktimezone.h
Go to the documentation of this file.
1 /*
2  This file is part of the KDE libraries
3  Copyright (c) 2005-2007 David Jarvie <djarvie@kde.org>
4  Copyright (c) 2005 S.R.Haque <srhaque@iee.org>.
5 
6  This library is free software; you can redistribute it and/or
7  modify it under the terms of the GNU Library General Public
8  License as published by the Free Software Foundation; either
9  version 2 of the License, or (at your option) any later version.
10 
11  This library is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  Library General Public License for more details.
15 
16  You should have received a copy of the GNU Library General Public License
17  along with this library; see the file COPYING.LIB. If not, write to
18  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19  Boston, MA 02110-1301, USA.
20 */
21 
28 #ifndef _KTIMEZONES_H
29 #define _KTIMEZONES_H
30 
31 #include <kdecore_export.h>
32 
33 #include <sys/time.h>
34 #include <ctime>
35 
36 #include <QtCore/QDateTime>
37 #include <QtCore/QMap>
38 #include <QtCore/QList>
39 #include <QtCore/QString>
40 #include <QtCore/QByteArray>
41 #include <QtCore/QSharedDataPointer>
42 
43 class KTimeZone;
44 class KTimeZoneBackend;
45 class KTimeZoneData;
46 class KTimeZoneSource;
47 class KTimeZonesPrivate;
48 class KTimeZonePrivate;
49 class KTimeZoneSourcePrivate;
50 class KTimeZoneDataPrivate;
51 class KTimeZoneTransitionPrivate;
52 class KTimeZoneLeapSecondsPrivate;
53 
308 class KDECORE_EXPORT KTimeZones
309 {
310 public:
311  KTimeZones();
312  ~KTimeZones();
313 
320  KTimeZone zone(const QString &name) const;
321 
323  typedef QMap<QString, KTimeZone> ZoneMap;
324 
330  const ZoneMap zones() const;
331 
340  bool add(const KTimeZone &zone);
341 
349  KTimeZone remove(const KTimeZone &zone);
350 
358  KTimeZone remove(const QString &name);
359 
365  void clear();
366 
367 private:
368  KTimeZones(const KTimeZones &); // prohibit copying
369  KTimeZones &operator=(const KTimeZones &); // prohibit copying
370 
371  KTimeZonesPrivate * const d;
372 };
373 
374 
416 class KDECORE_EXPORT KTimeZone //krazy:exclude=dpointer (has non-const d-pointer to Backend class)
417 {
418 public:
419 
420  /*
421  * Time zone phase.
422  *
423  * A phase can be daylight savings time or standard time. It holds the
424  * UTC offset and time zone abbreviation (e.g. EST, GMT).
425  *
426  * @short Time zone phase
427  * @author David Jarvie <djarvie@kde.org>.
428  */
429  class KDECORE_EXPORT Phase
430  {
431  public:
436  Phase();
437 
447  Phase(int utcOffset, const QByteArray &abbreviations, bool dst,
448  const QString &comment = QString());
449 
458  Phase(int utcOffset, const QList<QByteArray> &abbreviations, bool dst,
459  const QString &comment = QString());
460 
461  Phase(const Phase &rhs);
462  ~Phase();
463  Phase &operator=(const Phase &rhs);
464  bool operator==(const Phase &rhs) const;
465  bool operator!=(const Phase &rhs) const { return !operator==(rhs); }
466 
474  int utcOffset() const;
475 
483  QList<QByteArray> abbreviations() const;
484 
490  bool isDst() const;
491 
497  QString comment() const;
498 
499  private:
500  QSharedDataPointer<class KTimeZonePhasePrivate> d;
501  };
502 
503 
504  /*
505  * Time zone daylight saving time transition.
506  *
507  * A Transition instance holds details of a transition to daylight saving time or
508  * standard time, including the UTC time of the change.
509  *
510  * @short Time zone transition
511  * @author David Jarvie <djarvie@kde.org>.
512  */
513  class KDECORE_EXPORT Transition
514  {
515  public:
516  Transition();
517  Transition(const QDateTime &dt, const Phase &phase);
518  Transition(const KTimeZone::Transition &t);
519  ~Transition();
520  Transition &operator=(const KTimeZone::Transition &t);
521 
527  QDateTime time() const;
528 
534  Phase phase() const;
535 
542  bool operator<(const Transition &rhs) const;
543 
544  private:
545  KTimeZoneTransitionPrivate *const d;
546  };
547 
548 
549  /*
550  * Leap seconds adjustment for a time zone.
551  *
552  * This class defines a leap seconds adjustment for a time zone by its UTC time of
553  * occurrence and the cumulative number of leap seconds to be added at that time.
554  *
555  * @short Leap seconds adjustment for a time zone
556  * @see KTimeZone, KTimeZoneData
557  * @ingroup timezones
558  * @author David Jarvie <djarvie@kde.org>.
559  */
560  class KDECORE_EXPORT LeapSeconds
561  {
562  public:
563  LeapSeconds();
564  LeapSeconds(const QDateTime &utcTime, int leapSeconds, const QString &comment = QString());
565  LeapSeconds(const LeapSeconds &c);
566  ~LeapSeconds();
567  LeapSeconds &operator=(const LeapSeconds &c);
568  bool operator<(const LeapSeconds &c) const; // needed by qSort()
569 
575  bool isValid() const;
576 
582  QDateTime dateTime() const;
583 
590  int leapSeconds() const;
591 
597  QString comment() const;
598 
599  private:
600  KTimeZoneLeapSecondsPrivate *const d;
601  };
602 
603 
609  KTimeZone();
610 
616  explicit KTimeZone(const QString &name);
617 
618  KTimeZone(const KTimeZone &tz);
619  KTimeZone &operator=(const KTimeZone &tz);
620 
621  virtual ~KTimeZone();
622 
632  bool operator==(const KTimeZone &rhs) const;
633  bool operator!=(const KTimeZone &rhs) const { return !operator==(rhs); }
634 
642  QByteArray type() const;
643 
649  bool isValid() const;
650 
658  QString name() const;
659 
665  QString countryCode() const;
666 
672  float latitude() const;
673 
679  float longitude() const;
680 
686  QString comment() const;
687 
696  QList<QByteArray> abbreviations() const;
697 
706  QByteArray abbreviation(const QDateTime &utcDateTime) const;
707 
722  QList<int> utcOffsets() const;
723 
734  QDateTime convert(const KTimeZone &newZone, const QDateTime &zoneDateTime) const;
735 
749  QDateTime toUtc(const QDateTime &zoneDateTime) const;
750 
765  QDateTime toZoneTime(const QDateTime &utcDateTime, bool *secondOccurrence = 0) const;
766 
780  int currentOffset(Qt::TimeSpec basis = Qt::UTC) const;
781 
802  virtual int offsetAtZoneTime(const QDateTime &zoneDateTime, int *secondOffset = 0) const;
803 
823  virtual int offsetAtUtc(const QDateTime &utcDateTime) const;
824 
839  virtual int offset(time_t t) const;
840 
857  virtual bool isDstAtUtc(const QDateTime &utcDateTime) const;
858 
870  virtual bool isDst(time_t t) const;
871 
882  QList<Phase> phases() const;
883 
892  virtual bool hasTransitions() const;
893 
911  QList<KTimeZone::Transition> transitions(const QDateTime &start = QDateTime(), const QDateTime &end = QDateTime()) const;
912 
933  const KTimeZone::Transition *transition(const QDateTime &dt, const Transition **secondTransition = 0, bool *validTime = 0) const;
934 
957  int transitionIndex(const QDateTime &dt, int *secondIndex = 0, bool *validTime = 0) const;
958 
978  QList<QDateTime> transitionTimes(const Phase &phase, const QDateTime &start = QDateTime(), const QDateTime &end = QDateTime()) const;
979 
989  QList<LeapSeconds> leapSecondChanges() const;
990 
996  KTimeZoneSource *source() const;
997 
1003  bool parse() const;
1004 
1013  const KTimeZoneData *data(bool create = false) const;
1014 
1031  bool updateBase(const KTimeZone &other);
1032 
1042  static QDateTime fromTime_t(time_t t);
1043 
1056  static time_t toTime_t(const QDateTime &utcDateTime);
1057 
1068  static KTimeZone utc();
1069 
1073  static const int InvalidOffset;
1074 
1077  static const time_t InvalidTime_t;
1078 
1083  static const float UNKNOWN;
1084 
1085 protected:
1086  KTimeZone(KTimeZoneBackend *impl);
1087 
1097  void setData(KTimeZoneData *data, KTimeZoneSource *source = 0);
1098 
1099 private:
1100  KTimeZoneBackend *d;
1101 };
1102 
1103 
1120 class KDECORE_EXPORT KTimeZoneBackend //krazy:exclude=dpointer (non-const d-pointer for KTimeZoneBackend-derived classes)
1121 {
1122 public:
1124  KTimeZoneBackend();
1126  explicit KTimeZoneBackend(const QString &name);
1127 
1128  KTimeZoneBackend(const KTimeZoneBackend &other);
1129  KTimeZoneBackend &operator=(const KTimeZoneBackend &other);
1130  virtual ~KTimeZoneBackend();
1131 
1139  virtual KTimeZoneBackend *clone() const;
1140 
1150  virtual QByteArray type() const;
1151 
1157  virtual int offsetAtZoneTime(const KTimeZone* caller, const QDateTime &zoneDateTime, int *secondOffset) const;
1163  virtual int offsetAtUtc(const KTimeZone* caller, const QDateTime &utcDateTime) const;
1169  virtual int offset(const KTimeZone* caller, time_t t) const;
1175  virtual bool isDstAtUtc(const KTimeZone* caller, const QDateTime &utcDateTime) const;
1181  virtual bool isDst(const KTimeZone* caller, time_t t) const;
1187  virtual bool hasTransitions(const KTimeZone* caller) const;
1188 
1189 protected:
1202  KTimeZoneBackend(KTimeZoneSource *source, const QString &name,
1203  const QString &countryCode = QString(), float latitude = KTimeZone::UNKNOWN,
1204  float longitude = KTimeZone::UNKNOWN, const QString &comment = QString());
1205 
1206 private:
1207  KTimeZonePrivate *d; // non-const
1208  friend class KTimeZone;
1209 };
1210 
1230 class KDECORE_EXPORT KTimeZoneSource
1231 {
1232 public:
1233  KTimeZoneSource();
1234  virtual ~KTimeZoneSource();
1235 
1252  virtual KTimeZoneData *parse(const KTimeZone &zone) const;
1253 
1261  bool useZoneParse() const;
1262 
1263 protected:
1281  explicit KTimeZoneSource(bool useZoneParse);
1282 
1283 private:
1284  KTimeZoneSourcePrivate * const d;
1285 };
1286 
1287 
1302 class KDECORE_EXPORT KTimeZoneData
1303 {
1304  friend class KTimeZone;
1305 
1306 public:
1307  KTimeZoneData();
1308  KTimeZoneData(const KTimeZoneData &c);
1309  virtual ~KTimeZoneData();
1310  KTimeZoneData &operator=(const KTimeZoneData &c);
1311 
1320  virtual KTimeZoneData *clone() const;
1321 
1330  virtual QList<QByteArray> abbreviations() const;
1331 
1340  virtual QByteArray abbreviation(const QDateTime &utcDateTime) const;
1341 
1351  virtual QList<int> utcOffsets() const;
1352 
1358  int previousUtcOffset() const;
1359 
1370  QList<KTimeZone::Phase> phases() const;
1371 
1380  virtual bool hasTransitions() const;
1381 
1399  QList<KTimeZone::Transition> transitions(const QDateTime &start = QDateTime(), const QDateTime &end = QDateTime()) const;
1400 
1421  const KTimeZone::Transition *transition(const QDateTime &dt, const KTimeZone::Transition **secondTransition = 0, bool *validTime = 0) const;
1422 
1445  int transitionIndex(const QDateTime &dt, int *secondIndex = 0, bool *validTime = 0) const;
1446 
1466  QList<QDateTime> transitionTimes(const KTimeZone::Phase &phase, const QDateTime &start = QDateTime(), const QDateTime &end = QDateTime()) const;
1467 
1477  QList<KTimeZone::LeapSeconds> leapSecondChanges() const;
1478 
1486  KTimeZone::LeapSeconds leapSecondChange(const QDateTime &utc) const;
1487 
1488 protected:
1498  void setPhases(const QList<KTimeZone::Phase> &phases, const KTimeZone::Phase& previousPhase);
1499 
1510  void setPhases(const QList<KTimeZone::Phase> &phases, int previousUtcOffset);
1511 
1518  void setTransitions(const QList<KTimeZone::Transition> &transitions);
1519 
1526  void setLeapSecondChanges(const QList<KTimeZone::LeapSeconds> &adjusts);
1527 
1528 private:
1529  KTimeZoneDataPrivate * const d;
1530 };
1531 
1532 #endif
kdecore_export.h
QByteArray
KTimeZoneData
Base class for the parsed data returned by a KTimeZoneSource class.
Definition: ktimezone.h:1302
transitions
Transitions transitions(const TIME_ZONE_INFORMATION &tz, int year)
Definition: ktimezone_win.cpp:368
fromTime_t
static QDateTime fromTime_t(qint32 seconds)
Definition: ktzfiletimezone.cpp:41
operator<
bool operator<(const KEntryKey &k1, const KEntryKey &k2)
Compares two KEntryKeys (needed for QMap).
Definition: kconfigdata.h:124
QMap< QString, KTimeZone >
KTimeZones
The KTimeZones class represents a time zone database which consists of a collection of individual tim...
Definition: ktimezone.h:308
KTimeZone::hasTransitions
virtual bool hasTransitions() const
Return whether daylight saving transitions are available for the time zone.
Definition: ktimezone.cpp:702
KTimeZone::Phase
Definition: ktimezone.h:429
operator==
bool operator==(const KEntry &k1, const KEntry &k2)
Definition: kconfigdata.h:72
KTimeZone::operator!=
bool operator!=(const KTimeZone &rhs) const
Definition: ktimezone.h:633
KTimeZone::abbreviation
QByteArray abbreviation(const QDateTime &utcDateTime) const
Returns the time zone abbreviation current at a specified time.
Definition: ktimezone.cpp:681
KTimeZone::phases
QList< Phase > phases() const
Return all daylight savings time phases for the time zone.
Definition: ktimezone.cpp:695
KTimeZone::UNKNOWN
static const float UNKNOWN
A representation for unknown locations; this is a float that does not represent a real latitude or lo...
Definition: ktimezone.h:1083
KTimeZone::LeapSeconds
Definition: ktimezone.h:560
KTimeZone::InvalidTime_t
static const time_t InvalidTime_t
Indicates an invalid time_t value.
Definition: ktimezone.h:1077
QString
QList< QByteArray >
KTimeZone::InvalidOffset
static const int InvalidOffset
Indicates an invalid UTC offset.
Definition: ktimezone.h:1073
KTimeZone
Base class representing a time zone.
Definition: ktimezone.h:416
KTimeZone::Phase::operator!=
bool operator!=(const Phase &rhs) const
Definition: ktimezone.h:465
KTimeZone::leapSecondChanges
QList< LeapSeconds > leapSecondChanges() const
Return all leap second adjustments, in time order.
Definition: ktimezone.cpp:742
KTimeZone::transitionTimes
QList< QDateTime > transitionTimes(const Phase &phase, const QDateTime &start=QDateTime(), const QDateTime &end=QDateTime()) const
Return the times of all daylight saving transitions to a given time zone phase, in time order...
Definition: ktimezone.cpp:735
transition
static QDateTime transition(const SYSTEMTIME &st, int year)
Definition: ktimezone_win.cpp:357
KTimeZones::ZoneMap
QMap< QString, KTimeZone > ZoneMap
Map of KTimeZone instances, indexed by time zone name.
Definition: ktimezone.h:323
KTimeZone::Transition
Definition: ktimezone.h:513
KTimeZoneSource
Base class representing a source of time zone information.
Definition: ktimezone.h:1230
KTimeZone::utcOffsets
QList< int > utcOffsets() const
Returns the complete list of UTC offsets used by the time zone.
Definition: ktimezone.cpp:688
KTimeZone::abbreviations
QList< QByteArray > abbreviations() const
Returns the list of time zone abbreviations used by the time zone.
Definition: ktimezone.cpp:674
parse
QList< Action > parse(QSettings &ini)
Definition: policy-gen.cpp:54
KTimeZone::transitionIndex
int transitionIndex(const QDateTime &dt, int *secondIndex=0, bool *validTime=0) const
Find the index to the last daylight savings time transition at or before a given UTC or local time...
Definition: ktimezone.cpp:725
KTimeZone::utc
static KTimeZone utc()
Returns a standard UTC time zone, with name "UTC".
Definition: ktimezone.cpp:911
QSharedDataPointer< class KTimeZonePhasePrivate >
QDateTime
KTimeZoneBackend
Base backend class for KTimeZone classes.
Definition: ktimezone.h:1120
KTimeZone::operator=
KTimeZone & operator=(const KTimeZone &tz)
Definition: ktimezone.cpp:624
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:22:11 by doxygen 1.8.7 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 API Reference

Skip menu "kdelibs 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

Search



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