BOSS 8.0.0
BESIII Offline Software System
Loading...
Searching...
No Matches
facilities::Timestamp Class Reference

#include <Timestamp.h>

Public Member Functions

 Timestamp ()
 Timestamp (long int seconds, int nano=0, int tzOffset=0)
 Timestamp (double julian)
 Constructor for Julian date. Must be GMT.
 Timestamp (const std::string &str, int tzOffset=0)
 Timestamp (int year, int month, int day, int hour=0, int minute=0, int second=0, int nano=0)
 Construct absolute time with specified fields.
std::string getString () const
 Return string representation of time, not including nanoseconds;.
double getJulian () const
 Return julian date.
double getNano () const
long int getClibTime () const
bool operator< (const Timestamp &other) const
bool operator> (const Timestamp &other) const
bool operator<= (const Timestamp &other) const
bool operator>= (const Timestamp &other) const
Timestampoperator= (const Timestamp &other)
bool operator== (const Timestamp &other) const
bool operator!= (const Timestamp &other) const
 Timestamp ()
 Timestamp (long int seconds, int nano=0, int tzOffset=0)
 Timestamp (double julian)
 Constructor for Julian date. Must be GMT.
 Timestamp (const std::string &str, int tzOffset=0)
 Timestamp (int year, int month, int day, int hour=0, int minute=0, int second=0, int nano=0)
 Construct absolute time with specified fields.
std::string getString () const
 Return string representation of time, not including nanoseconds;.
double getJulian () const
 Return julian date.
double getNano () const
long int getClibTime () const
bool operator< (const Timestamp &other) const
bool operator> (const Timestamp &other) const
bool operator<= (const Timestamp &other) const
bool operator>= (const Timestamp &other) const
Timestampoperator= (const Timestamp &other)
bool operator== (const Timestamp &other) const
bool operator!= (const Timestamp &other) const
 Timestamp ()
 Timestamp (long int seconds, int nano=0, int tzOffset=0)
 Timestamp (double julian)
 Constructor for Julian date. Must be GMT.
 Timestamp (const std::string &str, int tzOffset=0)
 Timestamp (int year, int month, int day, int hour=0, int minute=0, int second=0, int nano=0)
 Construct absolute time with specified fields.
std::string getString () const
 Return string representation of time, not including nanoseconds;.
double getJulian () const
 Return julian date.
double getNano () const
long int getClibTime () const
bool operator< (const Timestamp &other) const
bool operator> (const Timestamp &other) const
bool operator<= (const Timestamp &other) const
bool operator>= (const Timestamp &other) const
Timestampoperator= (const Timestamp &other)
bool operator== (const Timestamp &other) const
bool operator!= (const Timestamp &other) const

Protected Attributes

time_t m_time
 internal binary rep of time; count seconds from Jan 1, 1970
int m_nano
 Save fractional seconds separately (associated with m_time).

Detailed Description

Timestamp class, valid for dates from 1970 through 2037

Supports comparisons

Input to constructors may be Julian date seconds since start of 1970, Jan. 1 with optional nanosecond field individual fields (year, month, etc.) string format

yyyy-mm-dd hh:mm:ss 1969 < yyyy < 2038 where 0 < mm < 13 0 < dd < 32 -1 < hh < 24 -1 < mm < 60 -1 < ss < 60

o only the first three fields are required. Omitted trailing fields will be interpreted as equal to 0. o by default : will be used to delimit fields, but user may specify an alternative in most circumstances o leading zeros are optional

Definition at line 49 of file Calibration/facilities/include/facilities/Timestamp.h.

Constructor & Destructor Documentation

◆ Timestamp() [1/15]

facilities::Timestamp::Timestamp ( )

Default constructor builds object representing current time, expressed in GMT

Definition at line 20 of file Timestamp.cxx.

20: m_nano( 0 ) { m_time = time( 0 ); }
Double_t time
int m_nano
Save fractional seconds separately (associated with m_time).
time_t m_time
internal binary rep of time; count seconds from Jan 1, 1970

Referenced by operator!=(), operator<(), operator<=(), operator=(), operator==(), operator>(), and operator>=().

◆ Timestamp() [2/15]

facilities::Timestamp::Timestamp ( long int seconds,
int nano = 0,
int tzOffset = 0 )

Count seconds from the creation-according-to-unix, start of 1970 Optional third argument is offset in seconds from GMT (e.g., PST is +28800)

Definition at line 27 of file Timestamp.cxx.

28 : m_time( (time_t)seconds ), m_nano( nano ) {
29 if ( ( nano >= inverseNanoInt ) || ( nano < 0 ) || ( seconds < 0 ) )
30 throw BadTimeInput( "facilities::Timestamp bad nano argument" );
31 seconds += tzOffset;
32 }

◆ Timestamp() [3/15]

facilities::Timestamp::Timestamp ( double julian)

Constructor for Julian date. Must be GMT.

Definition at line 35 of file Timestamp.cxx.

35 {
36 double secs;
37 secs = ( julian - julian1970 ) * secPerDay;
38
39 if ( ( fabs( secs ) > maxInt ) || ( secs < 0 ) )
40 throw BadTimeInput( "Julian time not in range [1970, 2037]" );
41
42 m_time = (long int)secs;
43
44 // In case time is negative, truncation will go the "wrong way".
45 // Want m_time always <= secs
46 if ( m_time > secs ) m_time--;
47 m_nano = (int)( ( secs - m_time ) / inverseNano );
48 }

◆ Timestamp() [4/15]

facilities::Timestamp::Timestamp ( const std::string & str,
int tzOffset = 0 )

Create a timestamp from an ascii string of standard form yyyy-mm-dd hh:mm:ss where only the first three fields are required.

If the string is invalid, object will represent unix creation time. If the string represents a time in a timezone other than GMT, tzOffset should represent time zone offset relative to GMT in seconds so if local time is, for example, PST, tzOffset should be 28800

Definition at line 51 of file Timestamp.cxx.

51 : m_nano( 0 ) {
52 m_time = toBinary( str );
53 m_time += tzOffset;
54 }

◆ Timestamp() [5/15]

facilities::Timestamp::Timestamp ( int year,
int month,
int day,
int hour = 0,
int minute = 0,
int second = 0,
int nano = 0 )

Construct absolute time with specified fields.

Definition at line 57 of file Timestamp.cxx.

59 : m_nano( nano ) {
60 struct tm fields;
61
62 // check input
63 // for now don't bother checking whether, e.g., someone
64 // specified April 31
65 if ( ( month < 1 ) || ( month > 12 ) || ( day < 1 ) || ( day > 31 ) || ( hour < 0 ) ||
66 ( hour > 23 ) || ( minute < 0 ) || ( minute > 59 ) || ( second < 0 ) ||
67 ( second >= 60 ) || ( year < 1970 ) || ( year > 2037 ) || ( nano < 0 ) ||
68 ( nano >= inverseNanoInt ) )
69 throw BadTimeInput( "facilities::Timestamp Bad subfield" );
70
71 fields.tm_year = year - 1900;
72 fields.tm_mon = month - 1;
73 fields.tm_mday = day;
74 fields.tm_hour = hour;
75 fields.tm_min = minute;
76 fields.tm_sec = (long int)second;
77 fields.tm_wday = -1;
78 fields.tm_yday = -1;
79
80 // let system figure out whether daylight savings time is in effect
81 fields.tm_isdst = 0;
82
83 // m_time = timegm(&fields);
84 m_time = mktime( &fields ) - Timestamp::s_tz.m_tzseconds;
85 }

◆ Timestamp() [6/15]

facilities::Timestamp::Timestamp ( )

Default constructor builds object representing current time, expressed in GMT

◆ Timestamp() [7/15]

facilities::Timestamp::Timestamp ( long int seconds,
int nano = 0,
int tzOffset = 0 )

Count seconds from the creation-according-to-unix, start of 1970 Optional third argument is offset in seconds from GMT (e.g., PST is +28800)

◆ Timestamp() [8/15]

facilities::Timestamp::Timestamp ( double julian)

Constructor for Julian date. Must be GMT.

◆ Timestamp() [9/15]

facilities::Timestamp::Timestamp ( const std::string & str,
int tzOffset = 0 )

Create a timestamp from an ascii string of standard form yyyy-mm-dd hh:mm:ss where only the first three fields are required.

If the string is invalid, object will represent unix creation time. If the string represents a time in a timezone other than GMT, tzOffset should represent time zone offset relative to GMT in seconds so if local time is, for example, PST, tzOffset should be 28800

◆ Timestamp() [10/15]

facilities::Timestamp::Timestamp ( int year,
int month,
int day,
int hour = 0,
int minute = 0,
int second = 0,
int nano = 0 )

Construct absolute time with specified fields.

◆ Timestamp() [11/15]

facilities::Timestamp::Timestamp ( )

Default constructor builds object representing current time, expressed in GMT

◆ Timestamp() [12/15]

facilities::Timestamp::Timestamp ( long int seconds,
int nano = 0,
int tzOffset = 0 )

Count seconds from the creation-according-to-unix, start of 1970 Optional third argument is offset in seconds from GMT (e.g., PST is +28800)

◆ Timestamp() [13/15]

facilities::Timestamp::Timestamp ( double julian)

Constructor for Julian date. Must be GMT.

◆ Timestamp() [14/15]

facilities::Timestamp::Timestamp ( const std::string & str,
int tzOffset = 0 )

Create a timestamp from an ascii string of standard form yyyy-mm-dd hh:mm:ss where only the first three fields are required.

If the string is invalid, object will represent unix creation time. If the string represents a time in a timezone other than GMT, tzOffset should represent time zone offset relative to GMT in seconds so if local time is, for example, PST, tzOffset should be 28800

◆ Timestamp() [15/15]

facilities::Timestamp::Timestamp ( int year,
int month,
int day,
int hour = 0,
int minute = 0,
int second = 0,
int nano = 0 )

Construct absolute time with specified fields.

Member Function Documentation

◆ getClibTime() [1/3]

long int facilities::Timestamp::getClibTime ( ) const
inline

◆ getClibTime() [2/3]

long int facilities::Timestamp::getClibTime ( ) const
inline

◆ getClibTime() [3/3]

long int facilities::Timestamp::getClibTime ( ) const
inline

◆ getJulian() [1/3]

double facilities::Timestamp::getJulian ( ) const

Return julian date.

Definition at line 94 of file Timestamp.cxx.

94 {
95 double julian = ( m_time + m_nano / inverseNano ) / secPerDay;
96 julian += julian1970;
97 return julian;
98 }

◆ getJulian() [2/3]

double facilities::Timestamp::getJulian ( ) const

Return julian date.

◆ getJulian() [3/3]

double facilities::Timestamp::getJulian ( ) const

Return julian date.

◆ getNano() [1/3]

double facilities::Timestamp::getNano ( ) const
inline

Definition at line 85 of file Calibration/facilities/include/facilities/Timestamp.h.

85{ return m_nano; }

◆ getNano() [2/3]

double facilities::Timestamp::getNano ( ) const
inline

◆ getNano() [3/3]

double facilities::Timestamp::getNano ( ) const
inline

◆ getString() [1/3]

std::string facilities::Timestamp::getString ( ) const

Return string representation of time, not including nanoseconds;.

Definition at line 87 of file Timestamp.cxx.

87 {
88 std::string str;
89
90 toString( m_time, str );
91 return str;
92 }

Referenced by rdbModel::Column::interpret(), lookup(), main(), operator<<(), calibUtil::Metadata::registerCalib(), and soonest().

◆ getString() [2/3]

std::string facilities::Timestamp::getString ( ) const

Return string representation of time, not including nanoseconds;.

◆ getString() [3/3]

std::string facilities::Timestamp::getString ( ) const

Return string representation of time, not including nanoseconds;.

◆ operator!=() [1/3]

bool facilities::Timestamp::operator!= ( const Timestamp & other) const
inline

Definition at line 109 of file Calibration/facilities/include/facilities/Timestamp.h.

109{ return ( !( *this == other ) ); }

◆ operator!=() [2/3]

bool facilities::Timestamp::operator!= ( const Timestamp & other) const
inline

Definition at line 109 of file InstallArea/x86_64-el9-gcc13-dbg/include/facilities/Timestamp.h.

109{ return ( !( *this == other ) ); }

◆ operator!=() [3/3]

bool facilities::Timestamp::operator!= ( const Timestamp & other) const
inline

Definition at line 109 of file InstallArea/x86_64-el9-gcc13-opt/include/facilities/Timestamp.h.

109{ return ( !( *this == other ) ); }

◆ operator<() [1/3]

bool facilities::Timestamp::operator< ( const Timestamp & other) const
inline

Definition at line 88 of file Calibration/facilities/include/facilities/Timestamp.h.

88 {
89 return ( ( m_time < other.m_time ) ||
90 ( ( m_time == other.m_time ) && ( m_nano < other.m_nano ) ) );
91 }
Index other(Index i, Index j)

◆ operator<() [2/3]

bool facilities::Timestamp::operator< ( const Timestamp & other) const
inline

Definition at line 88 of file InstallArea/x86_64-el9-gcc13-dbg/include/facilities/Timestamp.h.

88 {
89 return ( ( m_time < other.m_time ) ||
90 ( ( m_time == other.m_time ) && ( m_nano < other.m_nano ) ) );
91 }

◆ operator<() [3/3]

bool facilities::Timestamp::operator< ( const Timestamp & other) const
inline

Definition at line 88 of file InstallArea/x86_64-el9-gcc13-opt/include/facilities/Timestamp.h.

88 {
89 return ( ( m_time < other.m_time ) ||
90 ( ( m_time == other.m_time ) && ( m_nano < other.m_nano ) ) );
91 }

◆ operator<=() [1/3]

bool facilities::Timestamp::operator<= ( const Timestamp & other) const
inline

Definition at line 95 of file Calibration/facilities/include/facilities/Timestamp.h.

95{ return ( !( other < ( *this ) ) ); }

◆ operator<=() [2/3]

bool facilities::Timestamp::operator<= ( const Timestamp & other) const
inline

Definition at line 95 of file InstallArea/x86_64-el9-gcc13-dbg/include/facilities/Timestamp.h.

95{ return ( !( other < ( *this ) ) ); }

◆ operator<=() [3/3]

bool facilities::Timestamp::operator<= ( const Timestamp & other) const
inline

Definition at line 95 of file InstallArea/x86_64-el9-gcc13-opt/include/facilities/Timestamp.h.

95{ return ( !( other < ( *this ) ) ); }

◆ operator=() [1/3]

Timestamp & facilities::Timestamp::operator= ( const Timestamp & other)
inline

Definition at line 99 of file Calibration/facilities/include/facilities/Timestamp.h.

99 {
100 m_time = other.m_time;
101 m_nano = other.m_nano;
102 return *this;
103 }

◆ operator=() [2/3]

Timestamp & facilities::Timestamp::operator= ( const Timestamp & other)
inline

Definition at line 99 of file InstallArea/x86_64-el9-gcc13-dbg/include/facilities/Timestamp.h.

99 {
100 m_time = other.m_time;
101 m_nano = other.m_nano;
102 return *this;
103 }

◆ operator=() [3/3]

Timestamp & facilities::Timestamp::operator= ( const Timestamp & other)
inline

Definition at line 99 of file InstallArea/x86_64-el9-gcc13-opt/include/facilities/Timestamp.h.

99 {
100 m_time = other.m_time;
101 m_nano = other.m_nano;
102 return *this;
103 }

◆ operator==() [1/3]

bool facilities::Timestamp::operator== ( const Timestamp & other) const
inline

Definition at line 105 of file Calibration/facilities/include/facilities/Timestamp.h.

105 {
106 return ( ( m_time == other.m_time ) && ( m_nano == other.m_nano ) );
107 }

◆ operator==() [2/3]

bool facilities::Timestamp::operator== ( const Timestamp & other) const
inline

Definition at line 105 of file InstallArea/x86_64-el9-gcc13-dbg/include/facilities/Timestamp.h.

105 {
106 return ( ( m_time == other.m_time ) && ( m_nano == other.m_nano ) );
107 }

◆ operator==() [3/3]

bool facilities::Timestamp::operator== ( const Timestamp & other) const
inline

Definition at line 105 of file InstallArea/x86_64-el9-gcc13-opt/include/facilities/Timestamp.h.

105 {
106 return ( ( m_time == other.m_time ) && ( m_nano == other.m_nano ) );
107 }

◆ operator>() [1/3]

bool facilities::Timestamp::operator> ( const Timestamp & other) const
inline

Definition at line 93 of file Calibration/facilities/include/facilities/Timestamp.h.

93{ return ( other < ( *this ) ); }

◆ operator>() [2/3]

bool facilities::Timestamp::operator> ( const Timestamp & other) const
inline

Definition at line 93 of file InstallArea/x86_64-el9-gcc13-dbg/include/facilities/Timestamp.h.

93{ return ( other < ( *this ) ); }

◆ operator>() [3/3]

bool facilities::Timestamp::operator> ( const Timestamp & other) const
inline

Definition at line 93 of file InstallArea/x86_64-el9-gcc13-opt/include/facilities/Timestamp.h.

93{ return ( other < ( *this ) ); }

◆ operator>=() [1/3]

bool facilities::Timestamp::operator>= ( const Timestamp & other) const
inline

Definition at line 97 of file Calibration/facilities/include/facilities/Timestamp.h.

97{ return ( !( ( *this ) < other ) ); }

◆ operator>=() [2/3]

bool facilities::Timestamp::operator>= ( const Timestamp & other) const
inline

Definition at line 97 of file InstallArea/x86_64-el9-gcc13-dbg/include/facilities/Timestamp.h.

97{ return ( !( ( *this ) < other ) ); }

◆ operator>=() [3/3]

bool facilities::Timestamp::operator>= ( const Timestamp & other) const
inline

Definition at line 97 of file InstallArea/x86_64-el9-gcc13-opt/include/facilities/Timestamp.h.

97{ return ( !( ( *this ) < other ) ); }

Member Data Documentation

◆ m_nano

int facilities::Timestamp::m_nano
protected

Save fractional seconds separately (associated with m_time).

Definition at line 145 of file Calibration/facilities/include/facilities/Timestamp.h.

Referenced by getJulian(), getNano(), operator<(), operator=(), operator==(), Timestamp(), Timestamp(), Timestamp(), Timestamp(), and Timestamp().

◆ m_time

time_t facilities::Timestamp::m_time
protected

internal binary rep of time; count seconds from Jan 1, 1970

Definition at line 142 of file Calibration/facilities/include/facilities/Timestamp.h.

Referenced by getClibTime(), getJulian(), getString(), operator<(), operator=(), operator==(), Timestamp(), Timestamp(), Timestamp(), Timestamp(), and Timestamp().


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