libtabula::Date Class Reference

C++ form of SQL's DATE type. More...

#include <datetime.h>

Inheritance diagram for libtabula::Date:
Inheritance graph
Collaboration diagram for libtabula::Date:
Collaboration graph

List of all members.

Public Member Functions

 Date ()
 Default constructor.
 Date (unsigned short y, unsigned char m, unsigned char d)
 Initialize object.
 Date (const Date &other)
 Initialize object as a copy of another Date.
 Date (const DateTime &other)
 Initialize object from date part of date/time object.
 Date (const char *str)
 Initialize object from a C string containing a date.
template<class Str >
 Date (const Str &str)
 Initialize object from a C++ string containing a date.
 Date (time_t t)
 Initialize object from a time_t.
int compare (const Date &other) const
 Compare this date to another.
const char * convert (const char *)
 Parse a SQL date string into this object.
unsigned char day () const
 Get the date's day part, 1-31.
void day (unsigned char d)
 Change the date's day part, 1-31.
unsigned char month () const
 Get the date's month part, 1-12.
void month (unsigned char m)
 Change the date's month part, 1-12.
 operator std::string () const
 Convert to std::string.
 operator time_t () const
 Convert to time_t.
std::string str () const
 Return our value in std::string form.
unsigned short year () const
 Get the date's year part.
void year (unsigned short y)
 Change the date's year part.

Detailed Description

C++ form of SQL's DATE type.

Objects of this class can be inserted into streams, and initialized from SQL DATE strings.

Constructor & Destructor Documentation

libtabula::Date::Date ( unsigned short  y,
unsigned char  m,
unsigned char  d 
) [inline]

Initialize object.

y year, 1000-9999
m month, 1-12
d day of month, 1-31
libtabula::Date::Date ( const char *  str  )  [inline, explicit]

Initialize object from a C string containing a date.

String must be in the YYYY-MM-DD format. It doesn't have to be zero-padded.

template<class Str >
libtabula::Date::Date ( const Str &  str  )  [inline, explicit]

Initialize object from a C++ string containing a date.

This works with any stringish class that declares a c_str() member function: std::string, libtabula::String...

See also:
Date(const char*)
libtabula::Date::Date ( time_t  t  )  [explicit]

Initialize object from a time_t.

Naturally, we throw away the "time" part of the time_t. If you need to keep it, you want to use DateTime instead.

Member Function Documentation

int libtabula::Date::compare ( const Date other  )  const

Compare this date to another.

Returns < 0 if this date is before the other, 0 of they are equal, and > 0 if this date is after the other.

libtabula::Date::operator time_t (  )  const

Convert to time_t.

The "time" part of the time_t is "now"

void libtabula::Date::year ( unsigned short  y  )  [inline]

Change the date's year part.

Pass the year value normally; we don't optimize the value by subtracting 1900 like some other date implementations.

unsigned short libtabula::Date::year (  )  const [inline]

Get the date's year part.

There's no trickery here like in some date implementations where you have to add 1900 or something like that.

Referenced by libtabula::DateTime::convert().

The documentation for this class was generated from the following files:

Generated on 26 May 2014 for Libtabula by  doxygen 1.6.1