00001
00002
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
00030
00036 #ifndef OWBI1_DATETIME_HPP_INCLUDE_GUARD_
00037 #define OWBI1_DATETIME_HPP_INCLUDE_GUARD_
00038 #include "OWBI1_config.h"
00039 #include "OWBI1_Exception.hpp"
00040 #include "OWBI1_Types.hpp"
00041 #include "OWBI1_CommonFwd.hpp"
00042
00043 extern "C"
00044 {
00045 #include <time.h>
00046 }
00047
00048 namespace OWBI1
00049 {
00050
00051 OWBI1_DECLARE_APIEXCEPTION(DateTime, OWBI1_COMMON_API)
00052
00053
00077 class OWBI1_COMMON_API DateTime
00078 {
00079 public:
00087 enum ETimeOffset
00088 {
00089 E_LOCAL_TIME,
00090 E_UTC_TIME
00091 };
00092
00097 DateTime();
00175 explicit DateTime(const String& str);
00185 explicit DateTime(time_t t, UInt32 microseconds=0);
00198 DateTime(int year, int month, int day, int hour=0, int minute=0,
00199 int second=0, UInt32 microsecond=0, ETimeOffset timeOffset = E_LOCAL_TIME);
00200
00201 explicit DateTime(const detail::DateTimeRepRef& rep);
00205 ~DateTime();
00212 int getHour(ETimeOffset timeOffset = E_LOCAL_TIME) const;
00219 int getMinute(ETimeOffset timeOffset = E_LOCAL_TIME) const;
00227 int getSecond(ETimeOffset timeOffset = E_LOCAL_TIME) const;
00235 UInt32 getMicrosecond() const;
00242 int getDay(ETimeOffset timeOffset = E_LOCAL_TIME) const;
00248 int getDow(ETimeOffset timeOffset = E_LOCAL_TIME) const;
00253 int getMonth(ETimeOffset timeOffset = E_LOCAL_TIME) const;
00258 int getYear(ETimeOffset timeOffset = E_LOCAL_TIME) const;
00262 time_t get() const;
00269 void setHour(int hour, ETimeOffset timeOffset = E_LOCAL_TIME);
00276 void setMinute(int minute, ETimeOffset timeOffset = E_LOCAL_TIME);
00283 void setSecond(int second, ETimeOffset timeOffset = E_LOCAL_TIME);
00290 void setMicrosecond(UInt32 microsecond);
00299 void setTime(int hour, int minute, int second, ETimeOffset timeOffset = E_LOCAL_TIME);
00306 void setDay(int day, ETimeOffset timeOffset = E_LOCAL_TIME);
00313 void setMonth(int month, ETimeOffset timeOffset = E_LOCAL_TIME);
00320 void setYear(int year, ETimeOffset timeOffset = E_LOCAL_TIME);
00328 void set(time_t t, UInt32 microseconds=0);
00341 void set(int year, int month, int day, int hour, int minute, int second, UInt32 microseconds, ETimeOffset timeOffset = E_LOCAL_TIME);
00345 void setToCurrent();
00351 void addDays(int days);
00357 void addWeeks(int weeks)
00358 {
00359 addDays(weeks * 7);
00360 }
00366 void addMonths(int months);
00372 void addYears(int years);
00378 void addSeconds(long seconds);
00383 void addMinutes(long minutes);
00388 void addHours(long hours);
00394 bool operator< ( const DateTime& tm ) const;
00400 bool operator> ( const DateTime& tm ) const
00401 {
00402 return tm < *this;
00403 }
00409 bool operator== ( const DateTime& tm ) const;
00415 bool operator!= ( const DateTime& tm ) const
00416 {
00417 return !(*this == tm);
00418 }
00425 bool operator<= ( const DateTime& tm ) const
00426 {
00427 return !(tm < *this);
00428 }
00435 bool operator>= ( const DateTime& tm ) const
00436 {
00437 return !(*this < tm);
00438 }
00444 DateTime& operator+= (long seconds)
00445 {
00446 addSeconds(seconds);
00447 return *this;
00448 }
00454 DateTime& operator-= (long seconds)
00455 {
00456 addSeconds(-seconds);
00457 return *this;
00458 }
00459
00465 String toString(ETimeOffset timeOffset = E_LOCAL_TIME) const;
00466
00476 String toString(
00477 char const * format, ETimeOffset timeOffset = E_LOCAL_TIME) const;
00478
00484 static char const DEFAULT_FORMAT[];
00485
00491 static Int16 getGMTOffsetMinutesNow()
00492 {
00493 time_t t = time(0);
00494 struct tm tt;
00495 return DateTime::localTimeAndOffset(t, tt);
00496 }
00497
00503 Int16 toLocal(struct tm & tt) const;
00504
00508 static DateTime getCurrent();
00509
00510 detail::DateTimeRepRef getRep() const;
00511
00512 private:
00513 detail::DateTimeRepRef m_rep;
00514
00515 tm getTm(ETimeOffset timeOffset) const;
00516 void setTime(tm& tmarg, ETimeOffset timeOffset);
00517 static Int16 localTimeAndOffset(time_t t, struct tm & tt);
00518 };
00519
00520 }
00521
00522 #endif