Streaming C++ API
sb::Timestamp Class Reference

Class for representing moments in time and intervals at millisecond granularity. More...

#include <Timestamp.hpp>

Public Member Functions

 Timestamp ()
 Create a default Timestamp. More...
 
Timestamp operator- () const
 Negate an interval to return an interval. More...
 
Timestamp operator- (const Timestamp &rhs) const
 Subtract two Timestamps to return an interval. More...
 
Timestamp operator+ (const Timestamp &rhs) const
 Add a Timestamp and an interval to get a Timestamp. More...
 
Timestampoperator+= (const Timestamp &rhs)
 Increment the Timestamp by the interval. More...
 
Timestampoperator-= (const Timestamp &rhs)
 Decrement the Timestamp by the interval. More...
 
template<typename T >
Timestamp operator* (T rhs) const
 Multiply a Timestamp representing an interval by a constant. More...
 
template<typename T >
Timestampoperator*= (T rhs)
 Multiply a Timestamp representing an interval by a constant. More...
 
template<typename T >
Timestamp operator/ (T rhs) const
 Divide a Timestamp representing an interval by a constant. More...
 
template<typename T >
Timestampoperator/= (T rhs)
 Divide a Timestamp representing an interval by a constant. More...
 
double operator/ (Timestamp rhs) const
 Divide two Timestamps representing an interval to find their quotient. More...
 
Timestamp operator% (const Timestamp &rhs) const
 Modulo a Timestamp by an interval. More...
 
Timestamp operator%= (const Timestamp &rhs)
 Modulo a Timestamp by an interval. More...
 
bool operator< (const Timestamp &rhs) const
 Return true if this Timestamp is before rhs. More...
 
bool operator<= (const Timestamp &rhs) const
 Return true if this Timestamp is before or at the same time as rhs. More...
 
bool operator== (const Timestamp &rhs) const
 Return true if this Timestamp is at the same time as rhs. More...
 
bool operator!= (const Timestamp &rhs) const
 Return true if this Timestamp is not at the same time as rhs. More...
 
bool operator>= (const Timestamp &rhs) const
 Return true if this Timestamp is after or at the same time as rhs. More...
 
bool operator> (const Timestamp &rhs) const
 Return true if this Timestamp is after rhs. More...
 
bool isInterval () const
 Return true if this Timestamp is an interval. More...
 
long long toMsecs () const
 Return the time as milliseconds. More...
 
long long toSecs () const
 Return the time as seconds. More...
 
int compare (const Timestamp &other) const
 compare 2 timestamps return less than zero this < other return greater than zero this > other return 0 if they are the same More...
 
double getSecond () const
 Return seconds after the minute. More...
 
double getMillisecond () const
 Return milliseconds after the second. More...
 
int getMinute () const
 Return minutes after hour. More...
 
int getHour () const
 Return hours since midnight. More...
 
int getDayOfWeek () const
 Return day since Sunday. More...
 
int getDayOfMonth () const
 Return day of month. More...
 
int getMonth () const
 Return month since January. More...
 
int getYear () const
 Return year. More...
 
void setSecond (double seconds)
 Set seconds after the minute. More...
 
void setMinute (int minutes)
 Set minutes after the hour. More...
 
void setHour (int hours)
 Set hours since midnight. More...
 
void setDayOfMonth (int day_of_month)
 Set day of month. More...
 
void setMonth (int month)
 Set month since January. More...
 
void setYear (int year)
 Set year. More...
 
std::string as_string (bool displayTimezone=true) const
 Return a human readable string rep of this Timestamp. More...
 

Static Public Member Functions

static Timestamp now ()
 Return a Timestamp representing the current moment in time. More...
 
static Timestamp milliseconds (long long milliseconds)
 Create a time from a count of milliseconds. More...
 
template<typename T >
static Timestamp seconds (T seconds)
 Create a time from a count of seconds. More...
 
static Timestamp seconds (double seconds)
 Create a time from a count of seconds. More...
 
template<typename T >
static Timestamp minutes (T minutes)
 Construct an interval from minutes. More...
 
static Timestamp minutes (double minutes)
 Construct an interval from minutes. More...
 
template<typename T >
static Timestamp hours (T hours)
 Construct an interval from hours. More...
 
static Timestamp hours (double hours)
 Construct an interval from hours. More...
 
template<typename T >
static Timestamp days (T days)
 Construct an interval from days. More...
 
static Timestamp days (double days)
 Construct an interval from days. More...
 
template<typename T >
static Timestamp weeks (T weeks)
 Construct an interval from weeks. More...
 
static Timestamp weeks (double weeks)
 Construct an interval from weeks. More...
 

Static Public Attributes

static const int MIN_YEAR = 1400
 
static const int MAX_YEAR = 9999
 
static const int MIN_MONTH = 1
 
static const int MAX_MONTH = 12
 
static const int MIN_DAY = 1
 
static const int MAX_DAY = 31
 
static const int MIN_HOUR = 0
 
static const int MAX_HOUR = 23
 
static const int MIN_MINUTE = 0
 
static const int MAX_MINUTE = 59
 
static const int MIN_SECOND = 0
 
static const int MAX_SECOND = 59
 

Detailed Description

Class for representing moments in time and intervals at millisecond granularity.

Constructor & Destructor Documentation

◆ Timestamp()

sb::Timestamp::Timestamp ( )
inline

Create a default Timestamp.

Will initialized to 00:00:00 1 Jan 1970.

Member Function Documentation

◆ as_string()

std::string sb::Timestamp::as_string ( bool  displayTimezone = true) const

Return a human readable string rep of this Timestamp.

◆ compare()

int sb::Timestamp::compare ( const Timestamp other) const
inline

compare 2 timestamps return less than zero this < other return greater than zero this > other return 0 if they are the same

◆ days() [1/2]

static Timestamp sb::Timestamp::days ( double  days)
inlinestatic

Construct an interval from days.

◆ days() [2/2]

template<typename T >
static Timestamp sb::Timestamp::days ( days)
inlinestatic

Construct an interval from days.

◆ getDayOfMonth()

int sb::Timestamp::getDayOfMonth ( ) const

Return day of month.

◆ getDayOfWeek()

int sb::Timestamp::getDayOfWeek ( ) const

Return day since Sunday.

◆ getHour()

int sb::Timestamp::getHour ( ) const

Return hours since midnight.

◆ getMillisecond()

double sb::Timestamp::getMillisecond ( ) const

Return milliseconds after the second.

◆ getMinute()

int sb::Timestamp::getMinute ( ) const

Return minutes after hour.

◆ getMonth()

int sb::Timestamp::getMonth ( ) const

Return month since January.

◆ getSecond()

double sb::Timestamp::getSecond ( ) const

Return seconds after the minute.

◆ getYear()

int sb::Timestamp::getYear ( ) const

Return year.

◆ hours() [1/2]

static Timestamp sb::Timestamp::hours ( double  hours)
inlinestatic

Construct an interval from hours.

◆ hours() [2/2]

template<typename T >
static Timestamp sb::Timestamp::hours ( hours)
inlinestatic

Construct an interval from hours.

◆ isInterval()

bool sb::Timestamp::isInterval ( ) const
inline

Return true if this Timestamp is an interval.

◆ milliseconds()

static Timestamp sb::Timestamp::milliseconds ( long long  milliseconds)
inlinestatic

Create a time from a count of milliseconds.

◆ minutes() [1/2]

static Timestamp sb::Timestamp::minutes ( double  minutes)
inlinestatic

Construct an interval from minutes.

◆ minutes() [2/2]

template<typename T >
static Timestamp sb::Timestamp::minutes ( minutes)
inlinestatic

Construct an interval from minutes.

◆ now()

static Timestamp sb::Timestamp::now ( )
static

Return a Timestamp representing the current moment in time.

◆ operator!=()

bool sb::Timestamp::operator!= ( const Timestamp rhs) const
inline

Return true if this Timestamp is not at the same time as rhs.

◆ operator%()

Timestamp sb::Timestamp::operator% ( const Timestamp rhs) const
inline

Modulo a Timestamp by an interval.

◆ operator%=()

Timestamp sb::Timestamp::operator%= ( const Timestamp rhs)
inline

Modulo a Timestamp by an interval.

◆ operator*()

template<typename T >
Timestamp sb::Timestamp::operator* ( rhs) const
inline

Multiply a Timestamp representing an interval by a constant.

◆ operator*=()

template<typename T >
Timestamp & sb::Timestamp::operator*= ( rhs)
inline

Multiply a Timestamp representing an interval by a constant.

◆ operator+()

Timestamp sb::Timestamp::operator+ ( const Timestamp rhs) const

Add a Timestamp and an interval to get a Timestamp.

Add two intervals to return an interval.

◆ operator+=()

Timestamp & sb::Timestamp::operator+= ( const Timestamp rhs)

Increment the Timestamp by the interval.

◆ operator-() [1/2]

Timestamp sb::Timestamp::operator- ( ) const

Negate an interval to return an interval.

Negate a timestamp to return a timestamp, even though that doesn't make much sense.

◆ operator-() [2/2]

Timestamp sb::Timestamp::operator- ( const Timestamp rhs) const

Subtract two Timestamps to return an interval.

Subtract two intervals to return an interval. Subtract an interval from a Timestamp to return a Timestamp.

◆ operator-=()

Timestamp & sb::Timestamp::operator-= ( const Timestamp rhs)

Decrement the Timestamp by the interval.

◆ operator/() [1/2]

template<typename T >
Timestamp sb::Timestamp::operator/ ( rhs) const
inline

Divide a Timestamp representing an interval by a constant.

◆ operator/() [2/2]

double sb::Timestamp::operator/ ( Timestamp  rhs) const
inline

Divide two Timestamps representing an interval to find their quotient.

◆ operator/=()

template<typename T >
Timestamp & sb::Timestamp::operator/= ( rhs)
inline

Divide a Timestamp representing an interval by a constant.

◆ operator<()

bool sb::Timestamp::operator< ( const Timestamp rhs) const
inline

Return true if this Timestamp is before rhs.

◆ operator<=()

bool sb::Timestamp::operator<= ( const Timestamp rhs) const
inline

Return true if this Timestamp is before or at the same time as rhs.

◆ operator==()

bool sb::Timestamp::operator== ( const Timestamp rhs) const
inline

Return true if this Timestamp is at the same time as rhs.

◆ operator>()

bool sb::Timestamp::operator> ( const Timestamp rhs) const
inline

Return true if this Timestamp is after rhs.

◆ operator>=()

bool sb::Timestamp::operator>= ( const Timestamp rhs) const
inline

Return true if this Timestamp is after or at the same time as rhs.

◆ seconds() [1/2]

static Timestamp sb::Timestamp::seconds ( double  seconds)
inlinestatic

Create a time from a count of seconds.

◆ seconds() [2/2]

template<typename T >
static Timestamp sb::Timestamp::seconds ( seconds)
inlinestatic

Create a time from a count of seconds.

◆ setDayOfMonth()

void sb::Timestamp::setDayOfMonth ( int  day_of_month)

Set day of month.

◆ setHour()

void sb::Timestamp::setHour ( int  hours)

Set hours since midnight.

◆ setMinute()

void sb::Timestamp::setMinute ( int  minutes)

Set minutes after the hour.

◆ setMonth()

void sb::Timestamp::setMonth ( int  month)

Set month since January.

◆ setSecond()

void sb::Timestamp::setSecond ( double  seconds)

Set seconds after the minute.

◆ setYear()

void sb::Timestamp::setYear ( int  year)

Set year.

◆ toMsecs()

long long sb::Timestamp::toMsecs ( ) const
inline

Return the time as milliseconds.

◆ toSecs()

long long sb::Timestamp::toSecs ( ) const
inline

Return the time as seconds.

◆ weeks() [1/2]

static Timestamp sb::Timestamp::weeks ( double  weeks)
inlinestatic

Construct an interval from weeks.

◆ weeks() [2/2]

template<typename T >
static Timestamp sb::Timestamp::weeks ( weeks)
inlinestatic

Construct an interval from weeks.


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