UCommon
|
00001 // Copyright (C) 1999-2005 Open Source Telecom Corporation. 00002 // Copyright (C) 2006-2014 David Sugar, Tycho Softworks. 00003 // Copyright (C) 2015 Cherokees of Idaho. 00004 // 00005 // This program is free software; you can redistribute it and/or modify 00006 // it under the terms of the GNU General Public License as published by 00007 // the Free Software Foundation; either version 2 of the License, or 00008 // (at your option) any later version. 00009 // 00010 // This program is distributed in the hope that it will be useful, 00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 // GNU General Public License for more details. 00014 // 00015 // You should have received a copy of the GNU Lesser General Public License 00016 // along with this program. If not, see <http://www.gnu.org/licenses/>. 00017 // 00018 // As a special exception, you may use this file as part of a free software 00019 // library without restriction. Specifically, if other files instantiate 00020 // templates or use macros or inline functions from this file, or you compile 00021 // this file and link it with other files to produce an executable, this 00022 // file does not by itself cause the resulting executable to be covered by 00023 // the GNU General Public License. This exception does not however 00024 // invalidate any other reasons why the executable file might be covered by 00025 // the GNU General Public License. 00026 // 00027 // This exception applies only to the code released under the name GNU 00028 // Common C++. If you copy code from other releases into a copy of GNU 00029 // Common C++, as the General Public License permits, the exception does 00030 // not apply to the code that you add in this way. To avoid misleading 00031 // anyone as to the status of such modified files, you must delete 00032 // this exception notice from them. 00033 // 00034 // If you write modifications of your own for GNU Common C++, it is your choice 00035 // whether to permit this exception to apply to your modifications. 00036 // If you do not wish that, delete this exception notice. 00037 // 00038 00039 #ifndef COMMONCPP_NUMBERS_H_ 00040 #define COMMONCPP_NUMBERS_H_ 00041 00042 #ifndef COMMONCPP_CONFIG_H_ 00043 #include <commoncpp/config.h> 00044 #endif 00045 00046 #ifndef COMMONCPP_STRING_H_ 00047 #include <commoncpp/string.h> 00048 #endif 00049 00050 typedef ucommon::DateTimeString DateTimeString; 00051 typedef ucommon::DateNumber DateNumber; 00052 00053 namespace ost { 00054 00055 class __EXPORT Date : public ucommon::Date 00056 { 00057 protected: 00058 inline void toJulian(long year, long month, long day) 00059 {ucommon::Date::set(year, month, day);} 00060 00061 inline void fromJulian(char *buf) const 00062 {put(buf);} 00063 00064 public: 00065 inline Date(time_t value) : ucommon::Date(value) {} 00066 00067 inline Date(struct tm *object) : ucommon::Date(object) {} 00068 00069 inline Date(const char *ptr, size_t size = 0) : ucommon::Date(ptr, size) {} 00070 00071 inline Date(int y, unsigned m, unsigned d) : ucommon::Date(y, m, d) {} 00072 00073 inline Date(const Date& object) : ucommon::Date(object) {} 00074 00075 inline Date() : ucommon::Date() {} 00076 00077 inline int getYear(void) const 00078 {return year();} 00079 00080 inline unsigned getMonth(void) const 00081 {return month();} 00082 00083 inline unsigned getDay(void) const 00084 {return day();} 00085 00086 inline unsigned getDayOfWeek(void) const 00087 {return dow();} 00088 00089 inline long getJulian(void) const 00090 {return julian;} 00091 00092 inline const char *get(char *buffer) const 00093 {return put(buffer);} 00094 00095 inline time_t getTime(void) const 00096 {return timeref();} 00097 00098 inline bool isValid(void) const 00099 {return is_valid();} 00100 }; 00101 00102 class __EXPORT Time : public ucommon::Time 00103 { 00104 protected: 00105 inline void toSeconds(int h, int m = 0, int s = 0) 00106 {set(h, m, s);} 00107 00108 inline void fromSeconds(char *buf) const 00109 {put(buf);} 00110 00111 public: 00112 inline Time(time_t value) : ucommon::Time(value) {} 00113 00114 inline Time(tm_t *object) : ucommon::Time(object) {} 00115 00116 inline Time(const char *ptr, size_t size) : ucommon::Time(ptr, size) {} 00117 00118 inline Time(int h, int m, int s) : ucommon::Time(h, m, s) {} 00119 00120 inline Time() : ucommon::Time() {} 00121 00122 inline int getHour(void) const 00123 {return hour();} 00124 00125 inline int getMinute(void) const 00126 {return minute();} 00127 00128 inline int getSecond(void) const 00129 {return second();} 00130 00131 inline const char *get(char *buffer) const 00132 {return put(buffer);} 00133 00134 inline bool isValid(void) const 00135 {return is_valid();} 00136 00137 }; 00138 00139 class __EXPORT DateTime : public ucommon::DateTime 00140 { 00141 public: 00142 inline DateTime(time_t time) : ucommon::DateTime(time) {} 00143 00144 inline DateTime(struct tm *dt) : ucommon::DateTime(dt) {} 00145 00146 00147 inline DateTime(int year, unsigned month, unsigned day, 00148 int hour = 0, int minute = 0, int second = 0) : 00149 ucommon::DateTime(year, month, day, hour, minute, second) {} 00150 00151 inline DateTime(const char *ptr, size_t size) : 00152 ucommon::DateTime(ptr, size) {} 00153 00154 inline DateTime(const DateTime& obj) : ucommon::DateTime(obj) {} 00155 00156 inline DateTime() : ucommon::DateTime() {} 00157 00158 inline int getYear(void) const 00159 {return year();} 00160 00161 inline unsigned getMonth(void) const 00162 {return month();} 00163 00164 inline unsigned getDay(void) const 00165 {return day();} 00166 00167 inline unsigned getDayOfWeek(void) const 00168 {return dow();} 00169 00170 inline long getJulian(void) const 00171 {return julian;} 00172 00173 inline const char *get(char *buffer) const 00174 {return ucommon::DateTime::put(buffer);} 00175 00176 inline time_t getTime(void) const 00177 {return ucommon::DateTime::timeref();} 00178 00179 inline bool isValid(void) const 00180 {return ucommon::DateTime::is_valid();} 00181 00182 inline int getHour(void) const 00183 {return hour();} 00184 00185 inline int getMinute(void) const 00186 {return minute();} 00187 00188 inline int getSecond(void) const 00189 {return second();} 00190 00191 inline static tm_t *glt(time_t *time = NULL) 00192 {return ucommon::DateTime::local(time);} 00193 }; 00194 00195 } // namespace ost 00196 00197 #endif 00198