UCommon
ucommon::DateTimeString Class Reference

A DateTime string class. More...

#include <datetime.h>

Inheritance diagram for ucommon::DateTimeString:
Collaboration diagram for ucommon::DateTimeString:

Public Types

enum  mode_t { DATE , TIME , BOTH }
 Specify string buffer mode. More...
 

Public Member Functions

const char * c_str (void) const
 Extract char from string.
 
 DateTimeString (const char *pointer, size_t size=0)
 Construct a date and time from ISO string buffer.
 
 DateTimeString (const DateTimeString &object)
 Create a datetime object from another object.
 
 DateTimeString (const time_t time)
 Construct a date and time from C libraray time_t type.
 
 DateTimeString (const tm_t *tm)
 Construct a date and time from C library time structure.
 
 DateTimeString (int year, unsigned month, unsigned day, int hour=0, int minute=0, int second=0)
 Construct a date and time object from explicit date and time values.
 
 DateTimeString (mode_t string=DateTimeString::BOTH)
 Construct a new date and time object with current date and time.
 
 operator const char * (void) const
 Cast to string.
 
void set (mode_t string)
 Set the string mode.
 
void set (void)
 Set (update) the date and time with current date and time.
 
virtual ~DateTimeString ()
 Destroy date time string.
 
- Public Member Functions inherited from ucommon::DateTime
 DateTime ()
 Construct a new date and time object with current date and time.
 
 DateTime (const char *pointer, size_t size=0)
 Construct a date and time from ISO string buffer.
 
 DateTime (const DateTime &object)
 Create a datetime object from another object.
 
 DateTime (const time_t time)
 Construct a date and time from C library time_t type.
 
 DateTime (const tm_t *tm)
 Construct a date and time from C library time structure.
 
 DateTime (int year, unsigned month, unsigned day, int hour=0, int minute=0, int second=0)
 Construct a date and time object from explicit date and time values.
 
stringref_t format (const char *strftime) const
 Return date and time formatted using strftime format values.
 
time_t get (void) const
 Get C library time_t type if object in C library epoch range.
 
bool is_valid (void) const
 Test if object is valid.
 
 operator bool () const
 Test is date and time is valid for is() operator.
 
 operator double () const
 Convert date and time to julian day number.
 
 operator long () const
 Casting operator to return date as number.
 
bool operator! () const
 Check if date and time is not valid.
 
bool operator!= (const DateTime &datetime) const
 Compare date and time with another date and time to see if not same.
 
const DateTime operator+ (long seconds) const
 Add seconds to datetime in an expression.
 
DateTimeoperator++ ()
 Add a day from the current date and time.
 
DateTimeoperator+= (long seconds)
 Add seconds to the current datetime object.
 
long operator- (const DateTime &datetime)
 Operator to compute number of days between two dates.
 
const DateTime operator- (long seconds) const
 Subtract seconds from datetime in an expression.
 
DateTimeoperator-- ()
 Subtract a day from the current date and time.
 
DateTimeoperator-= (long seconds)
 Subtract seconds from current datetime object.
 
bool operator< (const DateTime &datetime) const
 Compare date and time with another date and time to see if earlier.
 
bool operator<= (const DateTime &datetime) const
 Compare date and time with another date and time to see if earlier or the same.
 
DateTimeoperator= (const DateTime &datetime)
 Assign date and time from another datetime object.
 
bool operator== (const DateTime &datetime) const
 Compare date and time with another date and time to see if the same.
 
bool operator> (const DateTime &datetime) const
 Compare date and time with another date and time to see if later.
 
bool operator>= (const DateTime &datetime) const
 Compare date and time with another date and time to see if later or the same.
 
const char * put (char *buffer) const
 Get a ISO formatted date and time string for current object.
 
void set (void)
 Set (update) the date and time with current date and time.
 
virtual ~DateTime ()
 Destroy date and time object.
 
- Public Member Functions inherited from ucommon::Date
 Date ()
 Construct a new julian date with today's date.
 
 Date (const char *pointer, size_t size=0)
 Create a julian date from a ISO date string of a specified size.
 
 Date (const Date &object)
 Create a julian date object from another object.
 
 Date (const struct tm *object)
 Create a julian date from a local or gmt date and time.
 
 Date (int year, unsigned month, unsigned day)
 Create a julian date from an arbitrary year, month, and day.
 
 Date (time_t value)
 Create a julian date from a time_t type.
 
unsigned day (void) const
 Get the day of the month of the date.
 
unsigned dow (void) const
 Get the day of the week (0-7).
 
long get (void) const
 Get the date as a number for the object or 0 if invalid.
 
bool is_valid (void) const
 Check if date is valid.
 
unsigned month (void) const
 Get the month of the date (1-12).
 
 operator bool () const
 Check if julian date is valid for is() expression.
 
 operator long () const
 Casting operator to return date as number.
 
bool operator! () const
 Check if julian date is not valid.
 
bool operator!= (const Date &date) const
 Compare julian dates if not same date.
 
stringref_t operator() () const
 Expression operator to return an ISO date string for the current julian date.
 
long operator* () const
 Access julian value.
 
const Date operator+ (long days) const
 Add days to julian date in an expression.
 
Dateoperator++ ()
 Increment date by one day.
 
Dateoperator+= (long offset)
 Increment date by offset.
 
long operator- (const Date &date)
 Operator to compute number of days between two dates.
 
const Date operator- (long days) const
 Subtract days from a julian date in an expression.
 
Dateoperator-- ()
 Decrement date by one day.
 
Dateoperator-= (long offset)
 Decrement date by offset.
 
bool operator< (const Date &date) const
 Compare julian date if earlier than another date.
 
bool operator<= (const Date &date) const
 Compare julian date if earlier than or equal to another date.
 
Dateoperator= (const Date &date)
 Assign date from another date object.
 
bool operator== (const Date &date) const
 Compare julian dates if same date.
 
bool operator> (const Date &date) const
 Compare julian date if later than another date.
 
bool operator>= (const Date &date) const
 Compare julian date if later than or equal to another date.
 
const char * put (char *buffer) const
 Get a ISO string representation of the date (yyyy-mm-dd).
 
void set (const char *pointer, size_t size=0)
 Set the julian date based on an ISO date string of specified size.
 
void set (void)
 Set (update) the date with current date.
 
time_t timeref (void) const
 Get a time_t for the julian date if in time_t epoch.
 
int year (void) const
 Get the year of the date.
 
virtual ~Date ()
 Destroy julian date object.
 
- Public Member Functions inherited from ucommon::Time
long get (void) const
 Get current time in seconds from midnight.
 
int hour (void) const
 Get hours from midnight.
 
bool is_valid (void) const
 Check if time object had valid value.
 
int minute (void) const
 Get minutes from current hour.
 
 operator bool () const
 Check if time object has valid value for is() operator.
 
 operator long () const
 Get time in seconds.
 
bool operator! () const
 Check if time object has valid value for ! operator.
 
bool operator!= (const Time &time) const
 Compare time with another time to see if not same time.
 
stringref_t operator() () const
 Convert to standard 24 hour time string.
 
long operator* () const
 Get object time in seconds.
 
const Time operator+ (long seconds) const
 Add seconds to the current time, wrap if 24 hours.
 
Timeoperator++ ()
 Incrememnt time by 1 second, wrap on 24 hour period.
 
Timeoperator+= (long seconds)
 Increment time by specified seconds.
 
long operator- (const Time &reference)
 Get difference (in seconds) between two times.
 
const Time operator- (long seconds) const
 Subtract seconds to the current time, wrap if 24 hours.
 
Timeoperator-- ()
 Decrement time by 1 second, wrap on 24 hour period.
 
Timeoperator-= (long seconds)
 Decrement time by specified seconds.
 
bool operator< (const Time &time) const
 Compare time if earlier than another time.
 
bool operator<= (const Time &time) const
 Compare time if earlier than or equal to another time.
 
Timeoperator= (const Time &time)
 Assign a time as a copy of another time.
 
bool operator== (const Time &time) const
 Compare time with another time to see if same time.
 
bool operator> (const Time &time) const
 Compare time if later than another time.
 
bool operator>= (const Time &time) const
 Compare time if later than or equal to another time.
 
const char * put (char *buffer) const
 Get a hh:mm:ss formatted string for current time.
 
int second (void) const
 Get seconds from current minute.
 
void set (const char *pointer, size_t size=0)
 Set time from a hh:mm:ss formatted string.
 
void set (int hour, int minute=0, int second=0)
 
void set (void)
 Set (update) the time with current time.
 
 Time ()
 Create a time from current time.
 
 Time (const char *pointer, size_t size=0)
 Create a time from a hh:mm:ss formatted time string.
 
 Time (const Time &object)
 Create a time object from another object.
 
 Time (const time_t value)
 Create a time from the time portion of a time_t.
 
 Time (const tm_t *object)
 Create a time from the time portion of a date and time object.
 
 Time (int hour, int minute, int second)
 Create a time from hours (0-23), minutes (0-59), and seconds (0-59).
 
virtual ~Time ()
 Destroy time object.
 

Protected Member Functions

virtual void update (void)
 A method to use to "post" any changed values when shadowing a mixed object class.
 
- Protected Member Functions inherited from ucommon::Date
void set (long year, long month, long day)
 

Additional Inherited Members

- Static Public Member Functions inherited from ucommon::DateTime
static tm_tgmt (const time_t *time=NULL)
 Fetch an instance of time converted to gmt.
 
static tm_tlocal (const time_t *time=NULL)
 Fetch an instance of time converted to local time.
 
static void release (tm_t *object)
 Release a struct tm object from glt or gmt.
 
- Static Public Attributes inherited from ucommon::DateTime
static const size_t sz_string
 Size of datetime string field.
 
- Static Public Attributes inherited from ucommon::Date
static const size_t sz_string
 Size of date string field.
 
- Static Public Attributes inherited from ucommon::Time
static const long c_day
 Constant for number of seconds in a day.
 
static const long c_hour
 Constant for number of seconds in a hour.
 
static const long c_week
 Constant for number of seconds in a week.
 
static const size_t sz_string
 Size of time string field.
 
- Protected Attributes inherited from ucommon::Date
long julian
 
- Protected Attributes inherited from ucommon::Time
long seconds
 

Detailed Description

A DateTime string class.

This can be used to access the date and time as a standard string without requiring an external buffer.

Author
David Sugar dyfet.nosp@m.@gnu.nosp@m.telep.nosp@m.hony.nosp@m..org

a datetime class that returns strings.

Examples
datetime.cpp.

Definition at line 869 of file datetime.h.

Member Enumeration Documentation

◆ mode_t

Specify string buffer mode.

By default we form a string with date and time.

Definition at line 876 of file datetime.h.

Constructor & Destructor Documentation

◆ DateTimeString() [1/5]

ucommon::DateTimeString::DateTimeString ( const time_t time)

Construct a date and time from C libraray time_t type.

Parameters
timetype to make date and time from.

◆ DateTimeString() [2/5]

ucommon::DateTimeString::DateTimeString ( const tm_t * tm)

Construct a date and time from C library time structure.

Parameters
tmstructure from C library (from glt or gmt).

◆ DateTimeString() [3/5]

ucommon::DateTimeString::DateTimeString ( const char * pointer,
size_t size = 0 )

Construct a date and time from ISO string buffer.

Parameters
pointerto string field holding date and time.
sizeof field if not null terminated string.

◆ DateTimeString() [4/5]

ucommon::DateTimeString::DateTimeString ( int year,
unsigned month,
unsigned day,
int hour = 0,
int minute = 0,
int second = 0 )

Construct a date and time object from explicit date and time values.

Parameters
yearof object.
monthof object (1-12).
dayof month of object (1-31).
hourof object (0-23).
minuteof object (0-59).
secondof object (0-59).

◆ DateTimeString() [5/5]

ucommon::DateTimeString::DateTimeString ( const DateTimeString & object)

Create a datetime object from another object.

Parameters
objectto copy.

Member Function Documentation

◆ c_str()

const char * ucommon::DateTimeString::c_str ( void ) const
inline

Extract char from string.

Returns
string of datetime.

Definition at line 940 of file datetime.h.

◆ operator const char *()

ucommon::DateTimeString::operator const char * ( void ) const
inline

Cast to string.

Returns
string of datetime.

Definition at line 949 of file datetime.h.

◆ set()

void ucommon::DateTimeString::set ( mode_t string)

Set the string mode.

Parameters
stringmode to use.

◆ update()

virtual void ucommon::DateTimeString::update ( void )
protectedvirtual

A method to use to "post" any changed values when shadowing a mixed object class.

This is used by DateNumber and string classes.

Reimplemented from ucommon::DateTime.


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