restcgi::date_time Class Reference

List of all members.

Detailed Description

Date and time class wrapping UTC time_t type for HTTP formats.


Public Types

typedef ::tm tm_type

Public Member Functions

 date_time ()
 Construct null.
 date_time (const time_t &t)
 date_time (const tm_type &tm, bool check_wday=false)
 date_time (unsigned short y, unsigned char mon, unsigned char d, unsigned char h, unsigned char min, unsigned char s)
 Construct from given date. Note that y is 2004, not 104, and mon 9is 12 for Dec.
 date_time (const std::string &s)
bool is_null () const
 Test if null.
bool operator== (const date_time &rhs) const
 Equal operator.
bool operator!= (const date_time &rhs) const
 Not equal operator.
bool operator< (const date_time &rhs) const
 Less operator (null is bottom).
 operator time_t () const
date_time operator+ (int seconds) const
date_timeoperator+= (int seconds)
date_time operator- (int seconds) const
date_timeoperator-= (int seconds)
tm_type tm () const
std::string string () const
std::string iso_string () const

Static Public Member Functions

static date_time now ()
static void assert_in_range (const tm_type &v, bool check_wday)
static time_t to_time (const tm_type &tm, bool check_wday)
static tm_type to_tm (const time_t &t)
static void to_tm (const time_t &t, tm_type &tm)

Static Public Attributes

static const time_t NULL_TIME
 null (0)


Member Typedef Documentation

typedef struct ::tm restcgi::date_time::tm_type

time structure type


Constructor & Destructor Documentation

restcgi::date_time::date_time ( const time_t &  t  ) 

Construct from time_t type (or null if t is 0).

Exceptions:
std::invalid_argument if t negative

restcgi::date_time::date_time ( const tm_type tm,
bool  check_wday = false 
)

Construct from time structure. This checks to be sure that tm is in correct form. For example, the month day cannot be 43 and it cannot be 31 in Feb.

Parameters:
tm time structure with time to construct
check_wday if true the week day will be checked for correctness
Exceptions:
std::invalid_argument if tm not valid

restcgi::date_time::date_time ( const std::string &  s  ) 

Construct from string. No isspace chars allowed before or after. Acceptable formats:

            Sun, 06 Nov 1994 08:49:37 GMT  ; RFC 822, updated by RFC 1123
            Sunday, 06-Nov-94 08:49:37 GMT ; RFC 850, obsoleted by RFC 1036
            Sun Nov  6 08:49:37 1994       ; ANSI C's asctime() format
            
See also:
http://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.3.1
Exceptions:
std::invalid_argument on conversion error


Member Function Documentation

static void restcgi::date_time::assert_in_range ( const tm_type v,
bool  check_wday 
) [static]

Assert struct tm is within range. This does not to a complete validity check as it misses Feb 31 errors.

Parameters:
v time structure with time to test
check_wday if true the week day will be checked for correctness
Exceptions:
std::invalid_argument if not valid

std::string restcgi::date_time::iso_string (  )  const

Convert to ISO 8601 format string (not cached).

            1994-11-06T08:49:37Z
            
Exceptions:
std::domain_error if null

static date_time restcgi::date_time::now (  )  [static]

Get current time.

restcgi::date_time::operator time_t (  )  const [inline]

Get time_t.

date_time restcgi::date_time::operator+ ( int  seconds  )  const [inline]

Add seconds and return result.

Exceptions:
std::invalid_argument on over/underflow

date_time& restcgi::date_time::operator+= ( int  seconds  ) 

Add seconds to this and return this.

Exceptions:
std::invalid_argument on over/underflow

date_time restcgi::date_time::operator- ( int  seconds  )  const [inline]

Subtract seconds and return result.

Exceptions:
std::invalid_argument on over/underflow

date_time& restcgi::date_time::operator-= ( int  seconds  ) 

Subtract seconds to this and return this.

Exceptions:
std::invalid_argument on over/underflow

std::string restcgi::date_time::string (  )  const

Convert to HTTP format string (not cached). Format (RFC 822, updated by RFC 1123):

            Sun, 06 Nov 1994 08:49:37 GMT
            
Exceptions:
std::domain_error if null

tm_type restcgi::date_time::tm (  )  const

Convert to time structure (not cached).

Exceptions:
std::domain_error if null

static time_t restcgi::date_time::to_time ( const tm_type tm,
bool  check_wday 
) [static]

Convert to GMT time_t.

Parameters:
tm time structure with time to convert
check_wday if true the week day will be checked for correctness
Exceptions:
std::invalid_argument if tm is not valid

static void restcgi::date_time::to_tm ( const time_t &  t,
tm_type tm 
) [static]

Convert to GMT time structure.

Exceptions:
std::invalid_argument if t is null (0)

static tm_type restcgi::date_time::to_tm ( const time_t &  t  )  [static]

Convert to GMT time structure.

Exceptions:
std::invalid_argument if t is null (0)


Generated on Fri May 15 11:27:12 2009 for restcgi by  doxygen 1.4.7