BOSS 7.0.5
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
 

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/facilities-00-00-04/facilities/Timestamp.h.

Constructor & Destructor Documentation

◆ Timestamp() [1/10]

facilities::Timestamp::Timestamp ( )

Default constructor builds object representing current time, expressed in GMT

Definition at line 19 of file Timestamp.cxx.

19 : m_nano(0) {
20 m_time = time(0);
21 }
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

◆ Timestamp() [2/10]

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 28 of file Timestamp.cxx.

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

◆ Timestamp() [3/10]

facilities::Timestamp::Timestamp ( double  julian)

Constructor for Julian date. Must be GMT.

Definition at line 37 of file Timestamp.cxx.

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

◆ Timestamp() [4/10]

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 53 of file Timestamp.cxx.

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

◆ Timestamp() [5/10]

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 59 of file Timestamp.cxx.

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

◆ Timestamp() [6/10]

facilities::Timestamp::Timestamp ( )

Default constructor builds object representing current time, expressed in GMT

◆ Timestamp() [7/10]

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/10]

facilities::Timestamp::Timestamp ( double  julian)

Constructor for Julian date. Must be GMT.

◆ Timestamp() [9/10]

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/10]

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/2]

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

◆ getClibTime() [2/2]

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

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

88{return m_time;}

◆ getJulian() [1/2]

double facilities::Timestamp::getJulian ( ) const

Return julian date.

Definition at line 99 of file Timestamp.cxx.

99 {
100 double julian = (m_time + m_nano/inverseNano)/secPerDay;
101 julian += julian1970;
102 return julian;
103 }

◆ getJulian() [2/2]

double facilities::Timestamp::getJulian ( ) const

Return julian date.

◆ getNano() [1/2]

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

◆ getNano() [2/2]

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

Definition at line 87 of file InstallArea/include/facilities/facilities/Timestamp.h.

87{return m_nano;}

◆ getString() [1/2]

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

Return string representation of time, not including nanoseconds;.

Definition at line 92 of file Timestamp.cxx.

92 {
93 std::string str;
94
95 toString(m_time, str);
96 return str;
97 }

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

◆ getString() [2/2]

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

Return string representation of time, not including nanoseconds;.

◆ operator!=() [1/2]

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

Definition at line 118 of file Calibration/facilities/facilities-00-00-04/facilities/Timestamp.h.

118 {
119 return (!(*this == other));
120 }

◆ operator!=() [2/2]

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

Definition at line 118 of file InstallArea/include/facilities/facilities/Timestamp.h.

118 {
119 return (!(*this == other));
120 }

◆ operator<() [1/2]

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

Definition at line 90 of file Calibration/facilities/facilities-00-00-04/facilities/Timestamp.h.

90 {
91 return ((m_time < other.m_time) ||
92 ((m_time == other.m_time) && (m_nano < other.m_nano)));
93 }
Index other(Index i, Index j)
Definition: EvtCyclic3.cc:118

◆ operator<() [2/2]

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

Definition at line 90 of file InstallArea/include/facilities/facilities/Timestamp.h.

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

◆ operator<=() [1/2]

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

Definition at line 100 of file Calibration/facilities/facilities-00-00-04/facilities/Timestamp.h.

100 {
101 return ( !(other < (*this)) );
102 }

◆ operator<=() [2/2]

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

Definition at line 100 of file InstallArea/include/facilities/facilities/Timestamp.h.

100 {
101 return ( !(other < (*this)) );
102 }

◆ operator=() [1/2]

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

Definition at line 109 of file Calibration/facilities/facilities-00-00-04/facilities/Timestamp.h.

109 {
110 m_time = other.m_time; m_nano = other.m_nano;
111 return *this;
112 }

◆ operator=() [2/2]

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

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

109 {
110 m_time = other.m_time; m_nano = other.m_nano;
111 return *this;
112 }

◆ operator==() [1/2]

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

Definition at line 114 of file Calibration/facilities/facilities-00-00-04/facilities/Timestamp.h.

114 {
115 return ((m_time == other.m_time) && (m_nano == other.m_nano));
116 }

◆ operator==() [2/2]

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

Definition at line 114 of file InstallArea/include/facilities/facilities/Timestamp.h.

114 {
115 return ((m_time == other.m_time) && (m_nano == other.m_nano));
116 }

◆ operator>() [1/2]

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

Definition at line 95 of file Calibration/facilities/facilities-00-00-04/facilities/Timestamp.h.

95 {
96 return (other < (*this));
97
98 }

◆ operator>() [2/2]

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

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

95 {
96 return (other < (*this));
97
98 }

◆ operator>=() [1/2]

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

Definition at line 104 of file Calibration/facilities/facilities-00-00-04/facilities/Timestamp.h.

104 {
105 return ( !( (*this) < other ) );
106 }

◆ operator>=() [2/2]

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

Definition at line 104 of file InstallArea/include/facilities/facilities/Timestamp.h.

104 {
105 return ( !( (*this) < other ) );
106 }

Member Data Documentation

◆ m_nano

int facilities::Timestamp::m_nano
protected

Save fractional seconds separately (associated with m_time)

Definition at line 156 of file Calibration/facilities/facilities-00-00-04/facilities/Timestamp.h.

Referenced by getJulian(), getNano(), operator<(), operator=(), operator==(), 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 153 of file Calibration/facilities/facilities-00-00-04/facilities/Timestamp.h.

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


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