ANNA Suite  2020b
Multipurpose development suite for Telco applications
Date.hpp
Go to the documentation of this file.
1 // ANNA - Anna is Not Nothingness Anymore //
2 // //
3 // (c) Copyright 2005-2015 Eduardo Ramos Testillano & Francisco Ruiz Rayo //
4 // //
5 // See project site at http://redmine.teslayout.com/projects/anna-suite //
6 // See accompanying file LICENSE or copy at http://www.teslayout.com/projects/public/anna.LICENSE //
7 
8 
9 #ifndef anna_dbms_Date_hpp
10 #define anna_dbms_Date_hpp
11 
12 #include <time.h>
13 
14 #include <anna/config/defines.hpp>
16 
17 #include <anna/dbms/Data.hpp>
18 
19 namespace anna {
20 
21 namespace dbms {
22 
45 class Date : public Data {
46 public:
50  static const int MaxDateSize = 48;
51 
152  explicit Date(const bool isNulleable = false, const char* format = NULL) ;
153 
158  Date(const Date& other);
159 
163  virtual ~Date();
164 
170  const tm& getValue() const { return a_value; }
171 
177  tm& getValue() { return a_value; }
178 
184  virtual const char* getCStringValue() const ;
185 
194  Second getSecondValue() const { return Second((Data::isNull() == true) ? 0 : mktime(&const_cast <Date*>(this)->a_value)); }
195 
200  const char* getFormat() const { return a_format; }
201 
206  int getYear() const { return a_value.tm_year + 1900; }
207 
212  int getMonth() const { return a_value.tm_mon + 1; }
213 
218  int getDay() const { return a_value.tm_mday; }
219 
225  int getHour() const { return a_value.tm_hour; }
226 
232  int getMinute() const { return a_value.tm_min; }
233 
239  int getSecond() const { return a_value.tm_sec; }
240 
245  void setYear(const int year) noexcept(false) { set("Year", a_value.tm_year, year - 1900, 0, -1); }
246 
251  void setMonth(const int month) noexcept(false) { set("Month", a_value.tm_mon, month - 1, 0, 11); }
252 
257  void setDay(const int day) noexcept(false) { set("Day", a_value.tm_mday, day, 1, 31); }
258 
264  void setHour(const int hour) noexcept(false) { set("Hour", a_value.tm_hour, hour, 0, 23); }
265 
271  void setMinute(const int minute) noexcept(false) { set("Minute", a_value.tm_min, minute, 0, 59); }
272 
278  void setSecond(const int second) noexcept(false) { set("Second", a_value.tm_sec, second, 0, 60); }
279 
285  void setValue(const char* str) noexcept(false);
286 
292  void setValue(const std::string& str) noexcept(false) { setValue(str.c_str()); }
293 
299  void setValue(const Second &second) noexcept(false);
300 
307  Date& operator = (const Date& date) noexcept(false);
308 
313  virtual std::string asString() const ;
314 
315 protected:
316  char* a_format;
318  char a_buffer [MaxDateSize + 1];
319 
326  explicit Date(const Type::_v type, const bool isNulleable, const char* format);
327 
328 private:
329  void set(const char* what, int& variable, const int value, const int min, const int max) noexcept(false);
330  void do_clear() { anna_memset(&a_value, 0, sizeof(a_value)); }
331 };
332 
333 }
334 }
335 
336 #endif
337 
virtual const char * getCStringValue() const
void setValue(const char *str) noexcept(false)
char a_buffer[MaxDateSize+1]
Definition: Date.hpp:318
_v
Definition: Data.hpp:30
const tm & getValue() const
Definition: Date.hpp:170
bool isNull() const
Definition: Data.hpp:62
void setHour(const int hour) noexcept(false)
Definition: Date.hpp:264
static const int MaxDateSize
Definition: Date.hpp:50
void setYear(const int year) noexcept(false)
Definition: Date.hpp:245
const char * getFormat() const
Definition: Date.hpp:200
void setMonth(const int month) noexcept(false)
Definition: Date.hpp:251
virtual std::string asString() const
int getHour() const
Definition: Date.hpp:225
Definition: Second.hpp:25
Definition: Date.hpp:45
#define anna_memset(a, b, c)
Definition: defines.hpp:43
int getSecond() const
Definition: Date.hpp:239
Definition: Data.hpp:27
void setDay(const int day) noexcept(false)
Definition: Date.hpp:257
int getMinute() const
Definition: Date.hpp:232
int getMonth() const
Definition: Date.hpp:212
char * a_format
Definition: Date.hpp:316
Date & operator=(const Date &date) noexcept(false)
Date(const bool isNulleable=false, const char *format=NULL)
int getDay() const
Definition: Date.hpp:218
Definition: app.hpp:12
tm a_value
Definition: Date.hpp:317
tm & getValue()
Definition: Date.hpp:177
void setValue(const std::string &str) noexcept(false)
Definition: Date.hpp:292
int getYear() const
Definition: Date.hpp:206
Second getSecondValue() const
Definition: Date.hpp:194
void setSecond(const int second) noexcept(false)
Definition: Date.hpp:278
bool isNulleable() const
Definition: Data.hpp:68
void setMinute(const int minute) noexcept(false)
Definition: Date.hpp:271