Go to the documentation of this file.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
00031
00032 #ifndef CalendarH
00033 #define CalendarH
00034
00035 #include <zeusbase/System/ZObject.h>
00036
00037 #if defined(ENABLE_LINUX_BINDING)
00038 #include <sys/time.h>
00039 #else
00040 #include <time.h>
00041
00042 #if defined(USE_WINDOWS_H)
00043 #include <windows.h>
00044 #endif
00045 #endif
00046
00047 BEGIN_NAMESPACE_Zeus
00048
00049 class TLocale;
00050
00051
00056
00057 zeusbase_class TCalendar : public TZObject
00058 {
00059 public:
00060 TCalendar(bool bLocalTime = true);
00061 TCalendar(Timeval tmTime, bool bLocalTime = true);
00062 TCalendar(Int iYear,
00063 Int iMonth,
00064 Int iDayOfMonth,
00065 Int iHour,
00066 Int iMin,
00067 Int iSec);
00068
00069
00070 virtual ~TCalendar();
00071
00072 Int getSecond() const;
00073 Int getMinute() const;
00074 Int getHour() const;
00075 Int getDayOfWeek() const;
00076 Int getDayOfMonth() const;
00077 Int getDayOfYear() const;
00078 Int getWeekOfYear() const;
00079 Int getMonth() const;
00080 Int getYear() const;
00081
00082 Timeval getTimeValue();
00083
00084 TString formatDateTime() const;
00085 TString formatDateTime(TLocale& rLocale) const;
00086 TString formatDateTime(const IString& rFormat, Int iExpectedLength = 200) const;
00087 TString formatDate(const TString& rDelimiter) const;
00088 TString formatTime(const TString& rDelimiter) const;
00089
00090 void setSecond(Int iValue);
00091 void setMinute(Int iValue);
00092 void setHour(Int iValue);
00093 void setDayOfWeek(Int iValue);
00094 void setDayOfMonth(Int iValue);
00095 void setDayOfYear(Int iValue);
00096 void setMonth(Int iValue);
00097 void setYear(Int iValue);
00098 void setDateTime( Int iYear,
00099 Int iMonth,
00100 Int iDayOfMonth,
00101 Int iHour,
00102 Int iMin,
00103 Int iSec);
00104 void setDate( Int iYear,
00105 Int iMonth,
00106 Int iDayOfMonth);
00107 void setTime( Int iHour,
00108 Int iMin,
00109 Int iSec);
00110
00111 static TString formatDateTimeForLogger();
00112 static TString formatDateTimeForLogger(const TCalendar& rCal);
00113
00114
00115 #if defined(ENABLE_WIN32_BINDING)
00116 TCalendar(const FILETIME& rFileTime, bool bLocalTime = true);
00117 static time_t convertToTimeValue(const FILETIME& rFileTime);
00118 static FILETIME convertToFileTime(time_t tmValue);
00119 #endif
00120
00121 static void convertToMSDOSFormat(Timeval tmValue, Uint16& rFileDate, Uint16& rFileTime);
00122 static Timeval convertFromMSDOSFormat(Uint16 usFileDate, Uint16 usFileTime);
00123
00124 protected:
00125
00126 private:
00128 tm m_TimeStruct;
00130 void create(time_t tmTime, bool bLocalTime);
00131 };
00132
00133
00134
00137
00138 inline Int TCalendar::getSecond() const
00139 {
00140 return m_TimeStruct.tm_sec;
00141 }
00142
00143
00146
00147 inline Int TCalendar::getMinute() const
00148 {
00149 return m_TimeStruct.tm_min;
00150 }
00151
00152
00155
00156 inline Int TCalendar::getHour() const
00157 {
00158 return m_TimeStruct.tm_hour;
00159 }
00160
00161
00164
00165 inline Int TCalendar::getDayOfWeek() const
00166 {
00167 return m_TimeStruct.tm_wday+1;
00168 }
00169
00170
00173
00174 inline Int TCalendar::getDayOfMonth() const
00175 {
00176 return m_TimeStruct.tm_mday;
00177 }
00178
00179
00182
00183 inline Int TCalendar::getDayOfYear() const
00184 {
00185 return m_TimeStruct.tm_yday+1;
00186 }
00187
00188
00191
00192 inline Int TCalendar::getWeekOfYear() const
00193 {
00194 return formatDateTime(TString(L"%U")).toInt();
00195 }
00196
00197
00200
00201 inline Int TCalendar::getMonth() const
00202 {
00203 return m_TimeStruct.tm_mon+1;
00204 }
00205
00206
00209
00210 inline Int TCalendar::getYear() const
00211 {
00212 return m_TimeStruct.tm_year+1900;
00213 }
00214
00215
00219
00220 inline Timeval TCalendar::getTimeValue()
00221 {
00222 return ::mktime(&m_TimeStruct);
00223 }
00224
00225
00228
00229 inline void TCalendar::setSecond(Int iValue)
00230 {
00231 m_TimeStruct.tm_sec = iValue;
00232 ::mktime(&m_TimeStruct);
00233 }
00234
00235
00238
00239 inline void TCalendar::setMinute(Int iValue)
00240 {
00241 m_TimeStruct.tm_min = iValue;
00242 ::mktime(&m_TimeStruct);
00243 }
00244
00245
00248
00249 inline void TCalendar::setHour(Int iValue)
00250 {
00251 m_TimeStruct.tm_hour = iValue;
00252 ::mktime(&m_TimeStruct);
00253 }
00254
00255
00258
00259 inline void TCalendar::setDayOfWeek(Int iValue)
00260 {
00261 m_TimeStruct.tm_wday = iValue - 1;
00262 ::mktime(&m_TimeStruct);
00263 }
00264
00265
00268
00269 inline void TCalendar::setDayOfMonth(Int iValue)
00270 {
00271 m_TimeStruct.tm_mday = iValue;
00272 ::mktime(&m_TimeStruct);
00273 }
00274
00275
00278
00279 inline void TCalendar::setDayOfYear(Int iValue)
00280 {
00281 m_TimeStruct.tm_yday = iValue - 1;
00282 ::mktime(&m_TimeStruct);
00283 }
00284
00285
00288
00289 inline void TCalendar::setMonth(Int iValue)
00290 {
00291 m_TimeStruct.tm_mon = iValue - 1;
00292 ::mktime(&m_TimeStruct);
00293 }
00294
00295
00298
00299 inline void TCalendar::setYear(Int iValue)
00300 {
00301 m_TimeStruct.tm_year = iValue - 1900;
00302 ::mktime(&m_TimeStruct);
00303 }
00304
00305
00306 END_NAMESPACE_Zeus
00307
00308 #endif