mcs::DateTime Class Reference

#include <mcs.hh>

List of all members.


Detailed Description

A class to hold date time information.

This class can be used to store a datetime value. Data are internally stored as the number of seconds elapsed since 1970-01-01 00:00:00 UTC, that is as a time_t value.

This class is also able to perform conversions between different data type related to temporal information: time_t, struct tm and string representation of a datetime.

The setTimeMode() method can be used to specify if input values should be considered to be expressed in UTC or in local time zone.

A MYSQL_TIME structure can be linked with this class that will be automatically updated each time the DateTime object is updated and vice-versa.

Definition at line 2880 of file mcs.hh.


Public Member Functions

 DateTime ()
 Constructor.
void now ()
 Set the current datetime value.
 operator string () const
 Wrapper to sval().
 operator struct tm () const
 Wrapper to tval().
 operator time_t () const
 Wrapper to tval().
DateTimeoperator= (struct tm &ltm)
 Wrapper to settmval().
DateTimeoperator= (string s)
 Wrapper to setsval(string).
DateTimeoperator= (time_t t)
 Wrapper to settval(time_t).
void setMysqlBuffer (MYSQL_TIME *mysql)
 Set a pointer to a MYSQL_TIME structure.
void setsval (string s)
 Parse a string to extract a datetime value.
void setTimeMode (enum TimeMode tm)
 Set operational time mode.
void settmval (struct tm &ltm)
 Assign a struct tm value.
void settval (time_t t)
 Assign a time_t value.
string sval () const
 Retrieve a string representation of the datetime value.
struct tm tmval () const
 Retrieve a struct tm object.
time_t tval () const
 Retrieve a time_t value.

Private Member Functions

time_t getTime () const
 Return stored time.
void to_MYSQL_TIME ()
 Update linked MYSQL_TIME structure (if any) with internal value.

Static Private Member Functions

static const char * parseTime (const char *s, struct tm *tm)
 Parse a string to extract datetime information.

Private Attributes

MYSQL_TIME * mysql
 Pointer to linked MYSQL_TIME structure.
time_t time
 Internal storage (seconds elapsed since 1970-01-01 00:00:00 UTC).
enum TimeMode timemode
 Operational time mode.

Constructor & Destructor Documentation

mcs::DateTime::DateTime (  ) 

Constructor.

Definition at line 161 of file Data.cc.


Member Function Documentation

time_t mcs::DateTime::getTime (  )  const [private]

Return stored time.

Return the time_t representation of the linked MYSQL_TIME structure. If there's no linked MYSQL_TIME structure this function simply returns the value of the "time" private field.

Definition at line 140 of file Data.cc.

void mcs::DateTime::now (  ) 

Set the current datetime value.

Definition at line 179 of file Data.cc.

mcs::DateTime::operator string (  )  const [inline]

Wrapper to sval().

Definition at line 3013 of file mcs.hh.

mcs::DateTime::operator struct tm (  )  const [inline]

Wrapper to tval().

Definition at line 3006 of file mcs.hh.

mcs::DateTime::operator time_t (  )  const [inline]

Wrapper to tval().

Definition at line 2998 of file mcs.hh.

DateTime& mcs::DateTime::operator= ( struct tm &  ltm  )  [inline]

Wrapper to settmval().

Definition at line 2990 of file mcs.hh.

DateTime& mcs::DateTime::operator= ( string  s  )  [inline]

Wrapper to setsval(string).

Definition at line 2969 of file mcs.hh.

DateTime& mcs::DateTime::operator= ( time_t  t  )  [inline]

Wrapper to settval(time_t).

Definition at line 2959 of file mcs.hh.

const char * mcs::DateTime::parseTime ( const char *  s,
struct tm *  tm 
) [static, private]

Parse a string to extract datetime information.

The parsed values will be written in the struct tm pointed by the second parameter. Only the following fields will be used:

Definition at line 60 of file Data.cc.

void mcs::DateTime::setMysqlBuffer ( MYSQL_TIME *  mysql  ) 

Set a pointer to a MYSQL_TIME structure.

The MYSQL_TIME structure pointed will be automatically updated each time the DateTime object is modified. Also any modification in the MYSQL_TIME structure will be reflected in the DateTime object's value.

Definition at line 168 of file Data.cc.

void mcs::DateTime::setsval ( string  s  ) 

Parse a string to extract a datetime value.

Definition at line 229 of file Data.cc.

void mcs::DateTime::setTimeMode ( enum TimeMode  tm  ) 

Set operational time mode.

The time mode controls the behaviour of the DateTime object in the following cases:

When the UTC mode is used each value is expressed in UTC, if the LOCAL mode is used each value is expressed in local time zone.

Definition at line 172 of file Data.cc.

void mcs::DateTime::settmval ( struct tm &  ltm  ) 

Assign a struct tm value.

Actually the only used fields are:

See also:
setTimeMode().

Definition at line 244 of file Data.cc.

void mcs::DateTime::settval ( time_t  t  ) 

Assign a time_t value.

Definition at line 186 of file Data.cc.

string mcs::DateTime::sval (  )  const

Retrieve a string representation of the datetime value.

Definition at line 281 of file Data.cc.

struct tm mcs::DateTime::tmval (  )  const [read]

Retrieve a struct tm object.

Definition at line 266 of file Data.cc.

void mcs::DateTime::to_MYSQL_TIME (  )  [private]

Update linked MYSQL_TIME structure (if any) with internal value.

Definition at line 124 of file Data.cc.

time_t mcs::DateTime::tval (  )  const

Retrieve a time_t value.

Definition at line 260 of file Data.cc.


Member Data Documentation

MYSQL_TIME* mcs::DateTime::mysql [private]

Pointer to linked MYSQL_TIME structure.

Definition at line 2890 of file mcs.hh.

time_t mcs::DateTime::time [private]

Internal storage (seconds elapsed since 1970-01-01 00:00:00 UTC).

Definition at line 2884 of file mcs.hh.

enum TimeMode mcs::DateTime::timemode [private]

Operational time mode.

Definition at line 2887 of file mcs.hh.


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

MCS (My Customizable Server) ver. 0.3.3-alpha3
Documentation generated on Thu Mar 22 13:22:23 UTC 2012