MCS  0.3.3-alpha7
mcs::DateTime Class Reference

A class to hold date time information. More...

#include <mcs.hh>

Public Member Functions

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

Private Member Functions

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

Static Private Member Functions

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

Private Attributes

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

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 2865 of file mcs.hh.

Constructor & Destructor Documentation

◆ DateTime()

mcs::DateTime::DateTime ( )

Constructor.

Definition at line 161 of file Data.cc.

Member Function Documentation

◆ getTime()

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.

◆ now()

void mcs::DateTime::now ( )

Set the current datetime value.

Definition at line 179 of file Data.cc.

◆ operator string()

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

Wrapper to sval().

Definition at line 2998 of file mcs.hh.

◆ operator struct tm()

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

Wrapper to tval().

Definition at line 2991 of file mcs.hh.

◆ operator time_t()

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

Wrapper to tval().

Definition at line 2983 of file mcs.hh.

◆ operator=() [1/3]

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

Wrapper to settval(time_t)

Definition at line 2944 of file mcs.hh.

◆ operator=() [2/3]

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

Wrapper to setsval(string)

Definition at line 2954 of file mcs.hh.

◆ operator=() [3/3]

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

Wrapper to settmval()

Definition at line 2975 of file mcs.hh.

◆ parseTime()

const char * mcs::DateTime::parseTime ( const char *  s,
struct tm *  tm 
)
staticprivate

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:

  • tm_mday;
  • tm_mon;
  • tm_year;
  • tm_sec;
  • tm_min;
  • tm_hour;

Definition at line 60 of file Data.cc.

◆ setMysqlBuffer()

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.

◆ setsval()

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

Parse a string to extract a datetime value.

Definition at line 229 of file Data.cc.

◆ setTimeMode()

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 converting from/to a string representation;
  • when converting from/to a broken down representation (that is a struct tm);
  • when converting from/to a MYSQL_TIME structure;

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.

◆ settmval()

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

Assign a struct tm value.

Actually the only used fields are:

  • tm_sec (seconds, 0:59);
  • tm_min (minutes, 0:59);
  • tm_hour (hours, 0:23);
  • tm_mday (day of the month, 1:31);
  • tm_mon (month, 0:11);
  • tm_year, (number of years since 1900);
  • tm_isdst (flag indicating whether DST is in effect at the time described, 0:1).
See also
setTimeMode().

Definition at line 244 of file Data.cc.

◆ settval()

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

Assign a time_t value.

Definition at line 186 of file Data.cc.

◆ sval()

string mcs::DateTime::sval ( ) const

Retrieve a string representation of the datetime value.

Definition at line 281 of file Data.cc.

◆ tmval()

struct tm mcs::DateTime::tmval ( ) const

Retrieve a struct tm object.

Definition at line 266 of file Data.cc.

◆ to_MYSQL_TIME()

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.

◆ tval()

time_t mcs::DateTime::tval ( ) const

Retrieve a time_t value.

Definition at line 260 of file Data.cc.

Member Data Documentation

◆ mysql

MYSQL_TIME* mcs::DateTime::mysql
private

Pointer to linked MYSQL_TIME structure.

Definition at line 2875 of file mcs.hh.

◆ time

time_t mcs::DateTime::time
private

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

Definition at line 2869 of file mcs.hh.

◆ timemode

enum TimeMode mcs::DateTime::timemode
private

Operational time mode.

Definition at line 2872 of file mcs.hh.


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

mcslogo

MCS (My Customizable Server) ver. 0.3.3-alpha7
Documentation generated on Mon May 28 07:39:41 UTC 2018