World Ocean Simulation System (WOSS) library
woss::Time Class Reference

a class for time date manipulation More...

#include <time-definitions.h>

Collaboration diagram for woss::Time:
Collaboration graph

Public Member Functions

 Time ()
 
 Time (struct tm *time)
 
 Time (int day, int month, int year, int hours=0, int mins=0, int seconds=1)
 
 Time (const Time &copy)
 
 ~Time ()
 
TimesetMonth (int m)
 
TimesetDay (int d)
 
TimesetYear (int y)
 
TimesetHours (int h)
 
TimesetMinutes (int m)
 
TimesetSeconds (int s)
 
bool isValid () const
 
int getMonth () const
 
int getDay () const
 
int getHours () const
 
int getYear () const
 
int getMinutes () const
 
int getSeconds () const
 
 operator time_t () const
 
Timeoperator= (const Time &copy)
 
friend::std::ostream & operator<< (::std::ostream &os, const Time &instance)
 

Static Public Member Functions

static void setDebug (bool flag)
 

Protected Attributes

struct tm timeinfo
 
time_t raw_time
 

Static Protected Attributes

static bool debug = false
 

Friends

const Time operator+ (const Time &left, const time_t right)
 
const Time operator- (const Time &left, const time_t right)
 
double operator- (const Time &left, const Time &right)
 
Timeoperator+= (Time &left, time_t right)
 
Timeoperator-= (Time &left, time_t right)
 
bool operator== (const Time &left, const Time &right)
 
bool operator!= (const Time &left, const Time &right)
 
bool operator> (const Time &left, const Time &right)
 
bool operator< (const Time &left, const Time &right)
 
bool operator<= (const Time &left, const Time &right)
 
bool operator>= (const Time &left, const Time &right)
 

Detailed Description

a class for time date manipulation

Time class offers the possibility to store and manipulate date time. A time date consists of a day, month, year, hours, minutes and seconds.

Constructor & Destructor Documentation

◆ Time() [1/4]

Time::Time ( )

Default Time constructor. Object is not valid

References raw_time, and timeinfo.

◆ Time() [2/4]

Time::Time ( struct tm *  time)

Time constructor

Parameters
timestruct tm from ctime library

References raw_time, and timeinfo.

◆ Time() [3/4]

Time::Time ( int  day,
int  month,
int  year,
int  hours = 0,
int  mins = 0,
int  seconds = 1 
)

Time constructor

Parameters
dayday value. Should be between 1 and 31
monthmonth value. Should be between 1 and 12
yearyear value.
hourshours value. Should be between 0 and 23
minsminutes value. Should be between 0 and 59
secondsseconds value. Should be between 0 and 59

References raw_time, and timeinfo.

◆ Time() [4/4]

Time::Time ( const Time copy)

Time copy constructor

Parameters
copyTimeArr to be copied

References raw_time, and timeinfo.

◆ ~Time()

woss::Time::~Time ( )
inline

Time destructor. It is not virtual, since this class is not meant to be inherited from

Member Function Documentation

◆ getDay()

int woss::Time::getDay ( ) const
inline

Returns day value

Returns
day value between 1 and 31

References timeinfo.

◆ getHours()

int woss::Time::getHours ( ) const
inline

Returns hours value

Returns
hours value between 0 and 23

References timeinfo.

◆ getMinutes()

int woss::Time::getMinutes ( ) const
inline

Returns minutes value

Returns
minutes value between 0 and 59

References timeinfo.

◆ getMonth()

int woss::Time::getMonth ( ) const
inline

Returns month value

Returns
month value between 1 and 12

References timeinfo.

◆ getSeconds()

int woss::Time::getSeconds ( ) const
inline

Returns seconds value

Returns
seconds value between 0 and 59

References timeinfo.

◆ getYear()

int woss::Time::getYear ( ) const
inline

Returns year value

Returns
year value

References timeinfo.

◆ isValid()

◆ operator time_t()

woss::Time::operator time_t ( ) const
inline

time_t operator

Returns
the time_t

◆ operator<<()

friend::std::ostream & woss::Time::operator<< ( ::std::ostream &  os,
const Time instance 
)

<< operator

Parameters
osleft operand ostream reference
instanceright operand const Time reference
Returns
os reference after the operation

◆ operator=()

Time & Time::operator= ( const Time copy)

Assignment operator

Parameters
copyconst reference to a Time object to be copied
Returns
Time reference to this

References raw_time, and timeinfo.

◆ setDay()

Time & woss::Time::setDay ( int  d)
inline

Sets day

Parameters
dday value. Should be between 1 and 31
Returns
reference to *this

References raw_time, and timeinfo.

◆ setDebug()

static void woss::Time::setDebug ( bool  flag)
inlinestatic

Sets debug flag for all instances

Parameters
flagdebug bool

References debug.

◆ setHours()

Time & woss::Time::setHours ( int  h)
inline

Sets hours

Parameters
mhours value. Should be between 0 and 23
Returns
reference to *this

References raw_time, and timeinfo.

◆ setMinutes()

Time & woss::Time::setMinutes ( int  m)
inline

Sets minutes

Parameters
mminutes value. Should be between 0 and 59
Returns
reference to *this

References raw_time, and timeinfo.

◆ setMonth()

Time & woss::Time::setMonth ( int  m)
inline

Sets month

Parameters
mmonth value. Should be between 1 and 12
Returns
reference to *this

References raw_time, and timeinfo.

◆ setSeconds()

Time & woss::Time::setSeconds ( int  s)
inline

Sets seconds

Parameters
sseconds value. Should be between 0 and 59
Returns
reference to *this

References raw_time, and timeinfo.

◆ setYear()

Time & woss::Time::setYear ( int  y)
inline

Sets year

Parameters
yyear value
Returns
reference to *this

References raw_time, and timeinfo.

Friends And Related Function Documentation

◆ operator!=

bool operator!= ( const Time left,
const Time right 
)
friend

Inequality operator

Parameters
leftleft operand const reference
rightright operand const reference
Returns
true if left != right, false otherwise

◆ operator+

const Time operator+ ( const Time left,
const time_t  right 
)
friend

Sum operator

Parameters
leftleft operand const reference
rightright operand const reference
Returns
a new const instance holding the operation result

◆ operator+=

Time & operator+= ( Time left,
time_t  right 
)
friend

Compound assignment sum operator

Parameters
leftleft operand reference
rightright operand const time_t representing seconds
Returns
left reference after the operation

◆ operator- [1/2]

double operator- ( const Time left,
const Time right 
)
friend

Subtraction operator

Parameters
leftleft operand const reference
rightright operand const reference
Returns
time difference in seconds

◆ operator- [2/2]

const Time operator- ( const Time left,
const time_t  right 
)
friend

Subtraction operator

Parameters
leftleft operand const reference
rightright operand const reference
Returns
a new const instance holding the operation result

◆ operator-=

Time & operator-= ( Time left,
time_t  right 
)
friend

Compound assignment subtraction operator

Parameters
leftleft operand reference
rightright operand const time_t representing seconds
Returns
left reference after the operation

◆ operator<

bool operator< ( const Time left,
const Time right 
)
friend

Less than operator

Parameters
leftleft operand const reference
rightright operand const reference
Returns
true if left < right, false otherwise

◆ operator<=

bool operator<= ( const Time left,
const Time right 
)
friend

Less than or equal to operator

Parameters
leftleft operand const reference
rightright operand const reference
Returns
true if left <= right, false otherwise

◆ operator==

bool operator== ( const Time left,
const Time right 
)
friend

Equality operator

Parameters
leftleft operand const reference
rightright operand const reference
Returns
true if left == right, false otherwise

◆ operator>

bool operator> ( const Time left,
const Time right 
)
friend

Greater than operator

Parameters
leftleft operand const reference
rightright operand const reference
Returns
true if left > right, false otherwise

◆ operator>=

bool operator>= ( const Time left,
const Time right 
)
friend

Greater than or equal to operator

Parameters
leftleft operand const reference
rightright operand const reference
Returns
true if left >= right, false otherwise

Member Data Documentation

◆ debug

bool Time::debug = false
staticprotected

Debug flag

Referenced by setDebug().

◆ raw_time

time_t woss::Time::raw_time
protected

Number of seconds corresponding to date time timeinfo

Referenced by isValid(), woss::operator+=(), woss::operator-=(), operator=(), setDay(), setHours(), setMinutes(), setMonth(), setSeconds(), setYear(), and Time().

◆ timeinfo


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