Design Pattern Examples
Overview of object-oriented design patterns
DateTime Class Reference

Represents a timestamp composed of a date and a time encoded in a time_t value. Provides ways of getting the current time and to format the time in a string. More...

#include <DateTime.h>

Collaboration diagram for DateTime:
Collaboration graph

Public Member Functions

 DateTime ()
 Default constructor.
 
 DateTime (time_t _timestamp)
 Constructor that takes a time_t.
 
 DateTime (const DateTime &e)
 Copy constructor. Construct from another DateTime.
 
DateTimeoperator= (const DateTime &e)
 Copy operator. Copy from another DateTime.
 
std::string ToString ()
 Format the DateTime as a string. The format is "standard" (in this case, preset to 02/22/2023 10:26:12 AM, local time).
 

Static Public Member Functions

static DateTime Now ()
 Return the current date and time.
 

Private Attributes

time_t timestamp
 

Detailed Description

Represents a timestamp composed of a date and a time encoded in a time_t value. Provides ways of getting the current time and to format the time in a string.

Definition at line 20 of file lusplus/helpers/DateTime.h.

Constructor & Destructor Documentation

◆ DateTime() [1/3]

DateTime ( )
inline

Default constructor.

Definition at line 29 of file lusplus/helpers/DateTime.h.

Referenced by DateTime::Now().

◆ DateTime() [2/3]

DateTime ( time_t  _timestamp)
inline

Constructor that takes a time_t.

Parameters
_timestampThe time to use in this DateTime.

Definition at line 37 of file lusplus/helpers/DateTime.h.

◆ DateTime() [3/3]

DateTime ( const DateTime e)
inline

Copy constructor. Construct from another DateTime.

Parameters
eAnother DateTime object.

Definition at line 42 of file lusplus/helpers/DateTime.h.

Member Function Documentation

◆ Now()

DateTime Now ( )
static

Return the current date and time.

Returns
Returns a DateTime object containing the current date and time.

Definition at line 35 of file DateTime.cpp.

References DateTime::DateTime().

◆ operator=()

DateTime & operator= ( const DateTime e)
inline

Copy operator. Copy from another DateTime.

Parameters
eAnother DateTime object.
Returns
Returns reference to this DateTime.

Definition at line 48 of file lusplus/helpers/DateTime.h.

References DateTime::timestamp.

◆ ToString()

std::string ToString ( )

Format the DateTime as a string. The format is "standard" (in this case, preset to 02/22/2023 10:26:12 AM, local time).

Returns
String containing the date and time.

Definition at line 17 of file DateTime.cpp.

References Helpers::makelocaltime(), and DateTime::timestamp.

Member Data Documentation

◆ timestamp

time_t timestamp
private

Definition at line 23 of file lusplus/helpers/DateTime.h.

Referenced by DateTime::operator=(), and DateTime::ToString().


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