Go to the documentation of this file.
29 #if !defined(MYSQLPP_DATETIME_H)
30 #define MYSQLPP_DATETIME_H
48 class MYSQLPP_EXPORT DateTime :
public Comparable<DateTime>
53 Comparable<DateTime>(),
72 DateTime(
unsigned short y,
unsigned char mon,
unsigned char d,
73 unsigned char h,
unsigned char min,
unsigned char s) :
74 Comparable<DateTime>(),
86 DateTime(
const DateTime& other) :
87 Comparable<DateTime>(),
92 minute_(other.minute_),
93 second_(other.second_),
103 explicit DateTime(
const char* str) { convert(str); }
113 explicit DateTime(
const Str& str)
115 convert(str.c_str());
125 int compare(
const DateTime& other)
const;
128 const char* convert(
const char*);
131 unsigned char day()
const {
return day_; }
134 void day(
unsigned char d) { day_ = d; now_ =
false; }
137 unsigned char hour()
const {
return hour_; }
140 void hour(
unsigned char h) { hour_ = h; now_ =
false; }
144 bool is_now()
const {
return now_; }
147 unsigned char minute()
const {
return minute_; }
150 void minute(
unsigned char m) { minute_ = m; now_ =
false; }
153 unsigned char month()
const {
return month_; }
156 void month(
unsigned char m) { month_ = m; now_ =
false; }
165 operator std::string()
const;
168 operator time_t()
const;
171 unsigned char second()
const {
return second_; }
174 void second(
unsigned char s) { second_ = s; now_ =
false; }
177 std::string str()
const {
return *
this; }
184 unsigned short year()
const {
return year_; }
190 void year(
unsigned short y) { year_ = y; now_ =
false; }
193 unsigned short year_;
194 unsigned char month_;
197 unsigned char minute_;
198 unsigned char second_;
217 MYSQLPP_EXPORT std::ostream& operator <<(std::ostream& os,
229 Date() : year_(0), month_(0), day_(0) { }
236 Date(
unsigned short y,
unsigned char m,
unsigned char d) :
245 Date(
const Date& other) :
248 month_(other.month_),
257 month_(other.month()),
266 explicit Date(
const char* str) { convert(str); }
275 explicit Date(
const Str& str) { convert(str.c_str()); }
281 explicit Date(time_t t);
287 int compare(
const Date& other)
const;
290 const char* convert(
const char*);
293 unsigned char day()
const {
return day_; }
296 void day(
unsigned char d) { day_ = d; }
299 unsigned char month()
const {
return month_; }
302 void month(
unsigned char m) { month_ = m; }
305 operator std::string()
const;
310 operator time_t()
const;
313 std::string str()
const {
return *
this; }
319 unsigned short year()
const {
return year_; }
325 void year(
unsigned short y) { year_ = y; }
328 unsigned short year_;
329 unsigned char month_;
339 MYSQLPP_EXPORT std::ostream& operator <<(std::ostream& os,
351 Time() : hour_(0), minute_(0), second_(0) { }
357 Time(
unsigned char h,
unsigned char m,
unsigned char s) :
368 minute_(other.minute_),
369 second_(other.second_)
377 minute_(other.minute()),
378 second_(other.second())
387 explicit Time(
const char* str) { convert(str); }
397 explicit Time(
const Str& str) { convert(str.c_str()); }
403 explicit Time(time_t t);
409 int compare(
const Time& other)
const;
412 const char* convert(
const char*);
415 unsigned char hour()
const {
return hour_; }
418 void hour(
unsigned char h) { hour_ = h; }
421 unsigned char minute()
const {
return minute_; }
424 void minute(
unsigned char m) { minute_ = m; }
427 operator std::string()
const;
432 operator time_t()
const;
435 unsigned char second()
const {
return second_; }
438 void second(
unsigned char s) { second_ = s; }
441 std::string str()
const {
return *
this; }
445 unsigned char minute_;
446 unsigned char second_;
456 MYSQLPP_EXPORT std::ostream& operator <<(std::ostream& os,
462 #endif // !defined(MYSQLPP_DATETIME_H)
Declares an adapter that converts something that can be inserted into a C++ stream into a std::string...
const char * convert(const char *)
Parse a SQL time string into this object.
Definition: datetime.cpp:167
C++ form of SQL's DATE type.
Definition: datetime.h:247
unsigned short year() const
Get the date's year part.
Definition: datetime.h:341
Time(const Time &other)
Initialize object as a copy of another Time.
Definition: datetime.h:387
const char * convert(const char *)
Parse a SQL date string into this object.
Definition: datetime.cpp:139
DateTime NOW()
Returns a DateTime object that, when inserted into query will yield a SQL "NOW()" function call.
Definition: datetime.h:228
C++ form of SQL's TIME type.
Definition: datetime.h:369
unsigned char day() const
Get the date's day part, 1-31.
Definition: datetime.h:315
This file includes top-level definitions for use both internal to the library, and outside it....
unsigned char hour() const
Get the time's hour part, 0-255.
Definition: datetime.h:437
Declares the Comparable<T> mixin.
unsigned char second() const
Get the time's second part, 0-59.
Definition: datetime.h:457
Mix-in that gives its subclass a full set of comparison operators.
Definition: comparable.h:62
unsigned char month() const
Get the date's month part, 1-12.
Definition: datetime.h:321
C++ form of SQL's DATETIME type.
Definition: datetime.h:70
unsigned char minute() const
Get the time's minute part, 0-59.
Definition: datetime.h:443
Declares classes to add SQL-compatible date and time types to C++'s type system.
std::string stream2string(const T &object)
Converts anything you can insert into a C++ stream to a std::string via std::ostringstream.
Definition: stream2string.h:63