![]() |
|
|
Bdb packages | Design docs | Source docs | Guidelines | Recent releases |
|
Main Page Modules Namespace List Class Hierarchy Alphabetical List Compound List File List Compound Members File Members BdbTime Class Reference
[BdbTime]#include <BdbTime.hh>
Public Types
enum Zone { Local, UTC } Public Methods
BdbTime () BdbTime (const BdbTime &t) BdbTime (d_ULong sec_since_1901, d_ULong nsec=0) BdbTime (d_ULong year, d_ULong month, d_ULong day, d_ULong hour, d_ULong minute, d_ULong second, d_ULong nanosecond=0, Zone zone=UTC) BdbTime (d_ULong year, d_ULong month, d_ULong day, d_ULong hour, d_ULong minute, d_ULong second, d_ULong nanosecond, const RWZone &zone) BdbTime (d_ULong hour, d_ULong minute, d_ULong second, d_ULong nanosecond=0, const RWZone &zone=RWZone::utc()) BdbTime (const RWTime &t) BdbTime (const RWCString &date, const RWCString &time, const RWZone &zone=RWZone::utc()) BdbTime (const std::string &date, const std::string &time, Zone zone=UTC) BdbTime (const RWCString &datetime, const RWZone &zone=RWZone::utc()) BdbTime (const std::string &, Zone zone=UTC) BdbTime (const struct timespec &ts) BdbTime (struct tm &stm, Zone zone=UTC) ~BdbTime () BdbTime & operator= (const BdbTime &t) BdbDuration operator- (const BdbTime &t) const BdbTime & operator+= (const BdbDuration &d) BdbTime operator+ (const BdbDuration &d) const BdbTime & operator-= (const BdbDuration &d) BdbTime operator- (const BdbDuration &d) const bool operator== (const BdbTime &t) const bool operator!= (const BdbTime &t) const bool operator< (const BdbTime &t) const bool operator<= (const BdbTime &t) const bool operator> (const BdbTime &t) const bool operator>= (const BdbTime &t) const d_ULong getGmtSec () const d_ULong getGmtNsec () const int timeSpec (struct timespec *ts) const tm * tm (struct tm *stm, Zone zone) const std::string asString (const char *fmt, Zone zone) const RWTime getRWTime () const Static Public Methods
BdbTime now () bool parseTime (const std::string &sdate, const std::string &stime, Zone zone, BdbTime &time) bool parseTime (const std::string &sdatetime, Zone zone, BdbTime &time) const RWZone & getZone (const RWCString &zonename) Static Public Attributes
const BdbTime minusInfinity = BdbTime( BdbTimeConst::minusInfinity ) const BdbTime plusInfinity = BdbTime( BdbTimeConst::plusInfinity ) Private Methods
void renormalizeNanoseconds () Private Attributes
d_ULong _gmtSec d_ULong _gmtNsec Friends
BdbTime operator+ (const BdbDuration &d, const BdbTime &t) ostream & operator<< (ostream &os, const BdbTime &t) Member Enumeration Documentation
enum BdbTime::Zone
Definition at line 70 of file BdbTime.hh.
Referenced by BdbTime(), and TMto1901().
Constructor & Destructor Documentation
BdbTime::BdbTime ( )
Constructs with the current time, to the nearest second. This constructor is deprecated and may be removed in a future release. The static function BdbTime::now() should be used in preference to this in all new code, if the current time is really required.
For some reason, the original implementation did not set the _gmtNsec member, perhaps because it was not easy to get it synchronized with the Rogue Wave "now()" function's return value. Now that we use clock_gettime() directly, this could be fixed.
However, we have decided not to do this at this time, in order not to change the behavior of existing programs.
BdbTime::now() preserves the full significance available from clock_gettime().
Please note that this constructor involves a system call and is expensive! Do not default-construct BdbTimes unless you really need the current time value. If you are just declaring a time variable to fill in later, BdbTime(0) is a more performant choice.
Definition at line 184 of file BdbTime.cc.
References _gmtSec, and POSIXto1901().
Referenced by now(), operator+(), operator-(), and parseTime().
BdbTime::BdbTime ( const BdbTime & t )
Copy constructor.
Definition at line 202 of file BdbTime.cc.
BdbTime::BdbTime ( d_ULong sec_since_1901, d_ULong nsec = 0 ) [explicit]
Constructs a time from an unsigned number of seconds since the BdbTime epoch of 1901. NB: this is not the Unix epoch of 1970!
Definition at line 207 of file BdbTime.cc.
References renormalizeNanoseconds().
BdbTime::BdbTime ( d_ULong year, d_ULong month, d_ULong day, d_ULong hour, d_ULong minute, d_ULong second, d_ULong nanosecond = 0, Zone zone = UTC )
Constructs a time from a broken-down list of components of a date and time.
Definition at line 213 of file BdbTime.cc.
References _gmtNsec, _gmtSec, renormalizeNanoseconds(), tm(), TMto1901(), and Zone.
BdbTime::BdbTime ( d_ULong year, d_ULong month, d_ULong day, d_ULong hour, d_ULong minute, d_ULong second, d_ULong nanosecond, const RWZone & zone )
Constructs a time from a broken-down list of components of a date and time. Deprecated Rogue Wave version.
Definition at line 250 of file BdbTime.cc.
References _gmtNsec, _gmtSec, and renormalizeNanoseconds().
BdbTime::BdbTime ( d_ULong hour, d_ULong minute, d_ULong second, d_ULong nanosecond = 0, const RWZone & zone = RWZone::utc() )
Definition at line 268 of file BdbTime.cc.
References _gmtNsec, _gmtSec, and renormalizeNanoseconds().
BdbTime::BdbTime ( const RWTime & t )
Deprecated constructor from a Rogue Wave time.
Definition at line 281 of file BdbTime.cc.
BdbTime::BdbTime ( const RWCString & date, const RWCString & time, const RWZone & zone = RWZone::utc() )
Definition at line 286 of file BdbTime.cc.
References _gmtSec, minusInfinity, and plusInfinity.
BdbTime::BdbTime ( const std::string & date, const std::string & time, Zone zone = UTC )
Definition at line 304 of file BdbTime.cc.
References _gmtSec, minusInfinity, plusInfinity, and UTC.
BdbTime::BdbTime ( const RWCString & datetime, const RWZone & zone = RWZone::utc() )
Definition at line 328 of file BdbTime.cc.
References _gmtSec, minusInfinity, and plusInfinity.
BdbTime::BdbTime ( const std::string & , Zone zone = UTC )
Definition at line 350 of file BdbTime.cc.
References _gmtSec, minusInfinity, plusInfinity, and UTC.
BdbTime::BdbTime ( const struct timespec & ts )
Constructs from POSIX high-resolution time, as might be obtained from clock_gettime.
Definition at line 389 of file BdbTime.cc.
References POSIXto1901(), and renormalizeNanoseconds().
BdbTime::BdbTime ( struct tm & stm, Zone zone = UTC )
Constructs from POSIX "broken-down time".
- Parameters:
stm Cannot be const because it is internally provided to POSIX mktime(), which normalizes it -- see man mktime. Definition at line 376 of file BdbTime.cc.
References _gmtSec, and TMto1901().
BdbTime::~BdbTime ( ) [inline]
The destructor is non-virtual in order to keep this representational class small and suitable for processing with value semantics. Class with non-empty destructors should not be constructed with non-private inheritance from BdbTime.
Definition at line 187 of file BdbTime.hh.
Member Function Documentation
std::string BdbTime::asString ( const char * fmt, Zone zone ) const
Creates a string from the value of the BdbTime, based on a specified format specification, as for POSIX strftime(), and on a time zone. Note that this function does not provide a way to embed the "nanoseconds" part of the BdbTime, since this is not possible to express in a form recognized by strftime.
The "N" format specified does not appear to be used in the POSIX definition of strftime. It's possible it could be hijacked in a future upgrade. FIXME
This function should work for all times in the BdbTime range.
Definition at line 470 of file BdbTime.cc.
Referenced by cmd_translate_time(), main(), and printDate().
d_ULong BdbTime::getGmtNsec ( ) const [inline]
d_ULong BdbTime::getGmtSec ( ) const [inline]
RWTime BdbTime::getRWTime ( ) const [inline]
Definition at line 287 of file BdbTime.hh.
References _gmtSec.
Referenced by main().
const RWZone & BdbTime::getZone ( const RWCString & zonename ) [static]
Definition at line 703 of file BdbTime.cc.
Referenced by CdbBdbLoadList::storeObjects(), BdbCondLoadList::storeObjects(), BdbCondDdOprPurgeIContainers::translate(), BdbCondDdOprNCorrection::translate(), BdbCondDdOprMergeIContainers2::translate(), and BdbCondDdOprMergeIContainers::translate().
BdbTime BdbTime::now ( ) [static]
bool BdbTime::operator!= ( const BdbTime & t ) const [inline]
Definition at line 216 of file BdbTime.hh.
BdbTime BdbTime::operator+ ( const BdbDuration & d ) const
Definition at line 582 of file BdbTime.cc.
References BdbTime().
BdbTime & BdbTime::operator+= ( const BdbDuration & d )
Definition at line 588 of file BdbTime.cc.
References _gmtNsec, _gmtSec, BdbDuration::getNsec(), BdbDuration::getSec(), and BdbTimeConst::nsecInASec.
BdbTime BdbTime::operator- ( const BdbDuration & d ) const
Definition at line 550 of file BdbTime.cc.
References BdbTime().
BdbDuration BdbTime::operator- ( const BdbTime & t ) const
Calculates the absolute value of the difference between two times. NB: BdbDuration is an inherently unsigned quantity! This is in essence because reasonably foreseeable time differences are larger in seconds than 2^31 and so can't be represented as a signed 32 bit integer.
Definition at line 510 of file BdbTime.cc.
References _gmtNsec, _gmtSec, and BdbTimeConst::nsecInASec.
BdbTime & BdbTime::operator-= ( const BdbDuration & d )
Definition at line 556 of file BdbTime.cc.
References _gmtNsec, _gmtSec, BdbDuration::getNsec(), BdbDuration::getSec(), and BdbTimeConst::nsecInASec.
bool BdbTime::operator< ( const BdbTime & t ) const [inline]
Definition at line 221 of file BdbTime.hh.
bool BdbTime::operator<= ( const BdbTime & t ) const [inline]
Definition at line 227 of file BdbTime.hh.
BdbTime & BdbTime::operator= ( const BdbTime & t )
Definition at line 499 of file BdbTime.cc.
bool BdbTime::operator== ( const BdbTime & t ) const [inline]
Definition at line 211 of file BdbTime.hh.
bool BdbTime::operator> ( const BdbTime & t ) const [inline]
Definition at line 233 of file BdbTime.hh.
bool BdbTime::operator>= ( const BdbTime & t ) const [inline]
Definition at line 238 of file BdbTime.hh.
bool BdbTime::parseTime ( const std::string & sdatetime, Zone zone, BdbTime & time ) [static]
Determines whether a string representing a date and time can be converted successfully to a date/time in BdbTime format, i.e., in the unsigned 1901 epoch.
Note that the strings "-Infinity" and "+Infinity" are recognized by this interface, and produce BdbTime::minusInfinity and BdbTime::plusInfinity values, respectively.
Note also that 1901.01.01 00:00:00 UTC is not a treated as a valid time; 00:00:01 is the first valid time.
- Parameters:
time Returned time value; modified only if parsing is successful.
- Returns:
- Flag indicating whether parsing was successful.
Definition at line 664 of file BdbTime.cc.
References BdbTime(), minusInfinity, plusInfinity, and UTC.
bool BdbTime::parseTime ( const std::string & sdate, const std::string & stime, Zone zone, BdbTime & time ) [static]
Determines whether a string representing a date and a string representing a time can be converted successfully to a date/time in BdbTime format, i.e., in the unsigned 1901 epoch.
Note that the strings "-Infinity" and "+Infinity" are not recognized by this interface. Note also that 1901.01.01 00:00:00 UTC is not a valid time; 00:00:01 is the first valid time.
- Parameters:
time Returned time value; modified only if parsing is successful.
- Returns:
- Flag indicating whether parsing was successful.
Definition at line 628 of file BdbTime.cc.
References BdbTime(), minusInfinity, plusInfinity, and UTC.
Referenced by translate_BdbTime(), and translateTime().
void BdbTime::renormalizeNanoseconds ( ) [inline, private]
Definition at line 360 of file BdbTime.hh.
References _gmtNsec, _gmtSec, and BdbTimeConst::nsecInASec.
Referenced by BdbTime().
int BdbTime::timeSpec ( struct timespec * ts ) const
Extracts the value of the BdbTime as a POSIX.1b "struct timespec". Returns 0 on success in analogy with POSIX.1b clock_gettime(). WARNING: Must and will fail for valid BdbTime values that are more than 2^31-1 seconds before the beginning of the POSIX 1970 epoch, i.e., before around 1901.12.13 20:45:53 UTC.
There are such times in the conditions database from early SP production, before all times were renormalized into 1997+ space.
Definition at line 397 of file BdbTime.cc.
References _gmtNsec, _gmtSec, and BdbTimeConst::seconds_1901_to_1970.
struct tm * BdbTime::tm ( struct tm * stm, Zone zone ) const
Extracts the value of the BdbTime as a POSIX "struct tm" broken-down time. This requires the use of a time zone. In analogy with the POSIX.1b gmtime_r() function, a pointer to a "struct tm" to receive the data must be supplied -- so this function is thread-safe(*). Following this analogy, the function returns the supplied pointer on success, and 0 on failure.
This function should work for all times in the BdbTime range.
Definition at line 426 of file BdbTime.cc.
References fix1901_offset, and BdbTimeConst::seconds_1901_to_1970.
Referenced by asString(), and BdbTime().
Friends And Related Function Documentation
BdbTime operator+ ( const BdbDuration & d, const BdbTime & t1 ) [friend]
Definition at line 722 of file BdbTime.cc.
ostream& operator<< ( ostream & os, const BdbTime & t ) [friend]
Definition at line 727 of file BdbTime.cc.
Member Data Documentation
d_ULong BdbTime::_gmtNsec [private]
Definition at line 299 of file BdbTime.hh.
Referenced by BdbTime(), getGmtNsec(), operator+=(), operator-(), operator-=(), operator<(), operator<=(), operator=(), operator==(), renormalizeNanoseconds(), and timeSpec().
d_ULong BdbTime::_gmtSec [private]
Definition at line 298 of file BdbTime.hh.
Referenced by BdbTime(), getGmtSec(), getRWTime(), operator+=(), operator-(), operator-=(), operator<(), operator<=(), operator=(), operator==(), renormalizeNanoseconds(), and timeSpec().
const BdbTime BdbTime::minusInfinity = BdbTime( BdbTimeConst::minusInfinity ) [static]
const BdbTime BdbTime::plusInfinity = BdbTime( BdbTimeConst::plusInfinity ) [static]
The documentation for this class was generated from the following files:
- /BdbTime/BdbTime.hh
- /BdbTime/BdbTime.cc
BaBar Public Site | SLAC | News | Links | Who's Who | Contact Us
Page Owner: Jacek Becla
Last Update: October 04, 2002