00001 #ifndef IONFLUX_TOOLS_TIMEZONE
00002 #define IONFLUX_TOOLS_TIMEZONE
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #include <string>
00030 #include <iostream>
00031 #include "ionflux/DateTime.hpp"
00032
00033 namespace Ionflux
00034 {
00035
00036 namespace Tools
00037 {
00038
00039 class DateTime;
00040
00044 typedef int64_t TimeTicks;
00048 typedef int64_t Year;
00049
00060 struct DSTSwitchingRule
00061 {
00063 static const int DSR_TYPE_TO_DST;
00065 static const int DSR_TYPE_TO_NORMAL;
00067 int type;
00069 int month;
00071 int weekDay;
00078 int week;
00080 int hour;
00082 int minute;
00084 int second;
00085 };
00086
00093 class TimeZone
00094 {
00095 protected:
00097 int offset;
00099 bool useDST;
00101 DSTSwitchingRule toDST;
00103 DSTSwitchingRule toNormal;
00105 std::string nameNormal;
00107 std::string nameDST;
00109 std::string shortNameNormal;
00111 std::string shortNameDST;
00113 std::string aliases;
00114
00115 public:
00117 static const DSTSwitchingRule DSR_TO_DST_EUROPE_WESTERN;
00119 static const DSTSwitchingRule DSR_TO_NORMAL_EUROPE_WESTERN;
00121 static const DSTSwitchingRule DSR_TO_DST_EUROPE_CENTRAL;
00123 static const DSTSwitchingRule DSR_TO_NORMAL_EUROPE_CENTRAL;
00125 static const DSTSwitchingRule DSR_TO_DST_EUROPE_EASTERN;
00127 static const DSTSwitchingRule DSR_TO_NORMAL_EUROPE_EASTERN;
00129 static const DSTSwitchingRule DSR_TO_DST_USA;
00131 static const DSTSwitchingRule DSR_TO_NORMAL_USA;
00133 static const DSTSwitchingRule DSR_TO_DST_EGYPT;
00135 static const DSTSwitchingRule DSR_TO_NORMAL_EGYPT;
00136
00141 TimeZone();
00142
00149 TimeZone(int initOffset);
00150
00162 TimeZone(int initOffset,
00163 const std::string &initNameNormal,
00164 const std::string &initNameDST,
00165 const std::string &initShortNameNormal,
00166 const std::string &initShortNameDST,
00167 const std::string &initAliases);
00168
00177 TimeZone(int initOffset,
00178 const DSTSwitchingRule &initToDST,
00179 const DSTSwitchingRule &initToNormal);
00180
00194 TimeZone(int initOffset,
00195 const DSTSwitchingRule &initToDST,
00196 const DSTSwitchingRule &initToNormal,
00197 const std::string &initNameNormal,
00198 const std::string &initNameDST,
00199 const std::string &initShortNameNormal,
00200 const std::string &initShortNameDST,
00201 const std::string &initAliases);
00202
00207 virtual ~TimeZone();
00208
00215 virtual void setOffset(int newOffset);
00216
00224 virtual void setNameNormal(const std::string &newNameNormal);
00225
00233 virtual void setNameDST(const std::string &newNameDST);
00234
00242 virtual void setShortNameNormal(const std::string &newNameNormal);
00243
00250 virtual void setShortNameDST(const std::string &newNameDST);
00251
00264 virtual void setAliases(const std::string &newAliases);
00265
00273 virtual void setDSTRules(const DSTSwitchingRule &newToDST,
00274 const DSTSwitchingRule &newToNormal);
00275
00289 virtual bool isDST(const DateTime &utcDT) const;
00290
00311 virtual bool localIsDST(const DateTime &localDT) const;
00312
00326 virtual int getCurrentOffset(const DateTime &utcDT) const;
00327
00338 virtual const DSTSwitchingRule *getDSTRule(bool ruleFlag) const;
00339
00350 DateTime getSwitchDT(Year year, const DSTSwitchingRule &rule) const;
00351
00356 virtual int getOffset() const;
00357
00362 virtual std::string getNameNormal() const;
00363
00368 virtual std::string getNameDST() const;
00369
00374 virtual std::string getShortNameNormal() const;
00375
00380 virtual std::string getShortNameDST() const;
00381
00387 virtual std::string getAliases() const;
00388
00396 virtual bool hasAlias(const std::string &checkAlias) const;
00397
00406 virtual void enableDST(bool enableFlag);
00407 };
00408
00409 }
00410
00411 }
00412
00416 #endif