Jpp
Public Member Functions | Private Attributes | Friends | List of all members
JSYSTEM::JDateAndTime Struct Reference

Auxililary class to get date and time. More...

#include <JDate.hh>

Public Member Functions

 JDateAndTime ()
 Default constructor. More...
 
 JDateAndTime (const time_t t1)
 Constructor. More...
 
const tm * operator-> () const
 Smart pointer. More...
 
int getSeconds () const
 seconds after the minute [0-59] More...
 
int getMinutes () const
 minutes after the hour [0-59] More...
 
int getHour () const
 hours after midnight [0-23] More...
 
int getDay () const
 day of the month [1-31] More...
 
int getMonth () const
 month of the year [1-12] More...
 
int getYear () const
 year a.d. More...
 
 operator std::string () const
 Type conversion operator. More...
 
std::string toString () const
 Get ASCII formatted date and time. More...
 
const JDateAndTime & operator() () const
 Set date and time. More...
 
void set () const
 Set to actual time. More...
 
void set (const time_t t1) const
 Set to given time. More...
 
double getElapsedTime (const JDateAndTime &object) const
 Get elapsed time since given date and time. More...
 

Private Attributes

time_t ts
 
tm * tp
 

Friends

std::ostream & operator<< (std::ostream &out, const JDateAndTime &object)
 Write date and time to output. More...
 

Detailed Description

Auxililary class to get date and time.

Definition at line 59 of file JDate.hh.

Constructor & Destructor Documentation

◆ JDateAndTime() [1/2]

JSYSTEM::JDateAndTime::JDateAndTime ( )
inline

Default constructor.

Definition at line 63 of file JDate.hh.

64  {
65  set();
66  }

◆ JDateAndTime() [2/2]

JSYSTEM::JDateAndTime::JDateAndTime ( const time_t  t1)
inline

Constructor.

Parameters
t1time

Definition at line 74 of file JDate.hh.

75  {
76  set(t1);
77  }

Member Function Documentation

◆ operator->()

const tm* JSYSTEM::JDateAndTime::operator-> ( ) const
inline

Smart pointer.

Returns
pointer to time structure

Definition at line 85 of file JDate.hh.

86  {
87  return tp;
88  }

◆ getSeconds()

int JSYSTEM::JDateAndTime::getSeconds ( ) const
inline

seconds after the minute [0-59]

Definition at line 91 of file JDate.hh.

◆ getMinutes()

int JSYSTEM::JDateAndTime::getMinutes ( ) const
inline

minutes after the hour [0-59]

Definition at line 92 of file JDate.hh.

◆ getHour()

int JSYSTEM::JDateAndTime::getHour ( ) const
inline

hours after midnight [0-23]

Definition at line 93 of file JDate.hh.

◆ getDay()

int JSYSTEM::JDateAndTime::getDay ( ) const
inline

day of the month [1-31]

Definition at line 94 of file JDate.hh.

◆ getMonth()

int JSYSTEM::JDateAndTime::getMonth ( ) const
inline

month of the year [1-12]

Definition at line 95 of file JDate.hh.

◆ getYear()

int JSYSTEM::JDateAndTime::getYear ( ) const
inline

year a.d.

Definition at line 96 of file JDate.hh.

◆ operator std::string()

JSYSTEM::JDateAndTime::operator std::string ( ) const
inline

Type conversion operator.

Returns
ASCII formatted date and time

Definition at line 104 of file JDate.hh.

105  {
106  return toString();
107  }

◆ toString()

std::string JSYSTEM::JDateAndTime::toString ( ) const
inline

Get ASCII formatted date and time.

Returns
ASCII formatted date and time

Definition at line 115 of file JDate.hh.

116  {
117  const std::string buffer = ctime(&ts);
118 
119  // remove the last character (carriage return) from the date string
120 
121  return buffer.substr(0, buffer.length() - 1);
122  }

◆ operator()()

const JDateAndTime& JSYSTEM::JDateAndTime::operator() ( ) const
inline

Set date and time.

Returns
date and time

Definition at line 130 of file JDate.hh.

131  {
132  set();
133 
134  return *this;
135  }

◆ set() [1/2]

void JSYSTEM::JDateAndTime::set ( ) const
inline

Set to actual time.

Definition at line 141 of file JDate.hh.

142  {
143  time(&ts);
144 
145  tp = localtime(&ts);
146  }

◆ set() [2/2]

void JSYSTEM::JDateAndTime::set ( const time_t  t1) const
inline

Set to given time.

Parameters
t1time

Definition at line 154 of file JDate.hh.

155  {
156  ts = t1;
157  tp = localtime(&t1);
158  }

◆ getElapsedTime()

double JSYSTEM::JDateAndTime::getElapsedTime ( const JDateAndTime &  object) const
inline

Get elapsed time since given date and time.

Parameters
objectdate and time
Returns
time [s]

Definition at line 167 of file JDate.hh.

168  {
169  return difftime(this->ts, object.ts);
170  }

Friends And Related Function Documentation

◆ operator<<

std::ostream& operator<< ( std::ostream &  out,
const JDateAndTime &  object 
)
friend

Write date and time to output.

Parameters
outoutput stream
objectdate and time
Returns
output stream

Definition at line 180 of file JDate.hh.

181  {
182  return out << object.toString();
183  }

Member Data Documentation

◆ ts

time_t JSYSTEM::JDateAndTime::ts
mutableprivate

Definition at line 187 of file JDate.hh.

◆ tp

tm* JSYSTEM::JDateAndTime::tp
mutableprivate

Definition at line 188 of file JDate.hh.


The documentation for this struct was generated from the following file:
JSYSTEM::JDateAndTime::tp
tm * tp
Definition: JDate.hh:188
JSYSTEM::JDateAndTime::toString
std::string toString() const
Get ASCII formatted date and time.
Definition: JDate.hh:115
JSYSTEM::JDateAndTime::ts
time_t ts
Definition: JDate.hh:187
JSYSTEM::JDateAndTime::set
void set() const
Set to actual time.
Definition: JDate.hh:141