00001 // OSB library ********************************************* -*- C++ -*- 00006 /* 00007 AUTHOR(S): Manikandan (mk) 00008 00009 RCS information 00010 $Name: OSB_060808 $ 00011 $Revision: 1.23 $ 00012 00013 License 00014 OSB rating and billing library for communication networks 00015 Copyright (C) 2004, 2005, 2006 OSB systems 00016 00017 This file may be distributed and/or modify under the terms of the 00018 GNU General Public License (GPL) as published by the Free Software 00019 Foundation which is provided in the file LICENSE.GPL included in the 00020 packaging of this file. 00021 00022 The file is distributed in the hope that it will be useful, but WITHOUT 00023 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 00024 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 00025 for more details. 00026 00027 Holders of a OSB Commercial License may use this file under the terms 00028 and conditions of this commercial license. 00029 */ 00030 #ifndef _TIMEZONE_H_ 00031 #define _TIMEZONE_H_ 00032 00033 // ********************************************************************* 00034 // included header files 00035 // + standard includes 00036 #include <vector> 00037 00038 // + local headers 00039 #include "chrono.h" 00040 #include "osbid.h" 00041 #include "osberror.h" 00042 00043 // ********************************************************************* 00044 // class declarations 00045 namespace OSB_DB { 00046 class Session; 00047 struct TimeZoneGw; 00048 } 00049 00050 // ********************************************************************* 00051 // namespace extensions 00052 namespace OSB_LIB { 00053 00054 // ********************************************************************* 00055 // class definitions 00056 00057 // ***************************************************************** 00058 // class TimeZone 00066 class TimeZone { 00072 friend struct OSB_DB::TimeZoneGw; 00073 public: 00075 typedef Id<TimeZone> Oid; 00076 00078 struct Interval { 00080 DateTime from; 00082 DateTime to; 00084 long offset; 00086 bool isDst; 00087 }; 00088 00090 typedef std::vector<Interval> Intervals; 00091 00098 class Undefined : public OsbException { 00100 static const ErrorNo errNo = 535; 00101 public: 00103 Undefined(); 00104 }; 00105 00106 public: 00132 TimeZone( 00133 const Oid& oid, 00134 const std::string& name, 00135 const std::string& dstStart, 00136 const std::string& dstStartTime, 00137 const std::string& dstEnd, 00138 const std::string& dstEndTime, 00139 long stdOffset, 00140 long dstOffset 00141 ); 00142 00151 explicit TimeZone(const Oid& oid = Oid()); 00152 00154 00155 00156 const Oid& oid() const; 00157 00159 const std::string& name() const; 00160 00162 const std::string& dstStart() const; 00163 00165 const std::string& dstEnd() const; 00166 00168 const std::string& dstStartTime() const; 00169 00171 const std::string& dstEndTime() const; 00172 00178 long stdOffset() const; 00179 00185 long dstOffset() const; 00187 00201 long offset(DateTime& ts); 00202 00271 void normalize(DateTime& ts); 00272 00274 00275 00289 bool read(const OSB_DB::Session& session); 00290 00304 bool insert(const OSB_DB::Session& session); 00305 00319 bool remove(const OSB_DB::Session& session); 00321 00322 private: 00324 Oid oid_; 00325 00327 std::string name_; 00328 00330 std::string dstStart_; 00331 00333 std::string dstStartTime_; 00334 00336 std::string dstEnd_; 00337 00339 std::string dstEndTime_; 00340 00342 long stdOffset_; 00343 00345 long dstOffset_; 00346 00348 mutable Intervals intervals_; 00349 00350 private: 00352 const TimeZone::Intervals& intervals() const; 00353 00365 DateTime mkDstStart(int year); 00366 00378 DateTime mkDstEnd(int year); 00379 00395 DateTime mkDateTime( 00396 std::string& dstDate, 00397 std::string& dstTime, 00398 int year 00399 ); 00400 00408 long find(const DateTime& ts) const; 00409 00427 long mkInterval(const DateTime& ts); 00428 }; 00429 00431 typedef std::vector<TimeZone> TimeZones; 00432 00433 } // namespace OSB_LIB 00434 #endif // #ifndef _TIMEZONE_H_