Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   File Members  

BdbTime Class Reference

#include <BdbTime.hh>

List of all members.

Public Types

enum  Zone { Local, UTC }

Public Member Functions

 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 (const std::string &date, const std::string &time, Zone zone=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

Static Public Member Functions

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)

Static Public Attributes

const BdbTime minusInfinity = BdbTime( BdbTimeConst::minusInfinity )
const BdbTime plusInfinity = BdbTime( BdbTimeConst::plusInfinity )

Friends

BdbTime operator+ (const BdbDuration &d, const BdbTime &t)
std::ostream & operator<< (std::ostream &os, const BdbTime &t)


Member Enumeration Documentation

enum BdbTime::Zone
 

Enumeration values:
Local 
UTC 

Definition at line 56 of file BdbTime.hh.

Referenced by CdbBdbLoadList::storeObjects().


Constructor & Destructor Documentation

BdbTime::BdbTime  
 

(Deprecated) 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 194 of file BdbTime.cc.

Referenced by now(), operator+(), operator-(), and parseTime().

BdbTime::BdbTime const BdbTime &    t
 

Copy constructor.

Definition at line 212 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 217 of file BdbTime.cc.

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.

This uses definitions inherited from the old RogueWave implementation of BdbTime. Thus "year" is the calendar year C.E. (e.g., 2003), and "month" is the month in the range {1..12}. Note that these differ from the POSIX broken-down time (struct tm) definitions, where 2003 C.E. is represented as 103, and the month is in the range {0..11}.

Definition at line 223 of file BdbTime.cc.

References tm().

BdbTime::BdbTime const std::string &    date,
const std::string &    time,
Zone    zone = UTC
 

(Deprecated - use parseTime()) Constructs a BdbTime from a string date and a string time.

The use of this constructor is strongly discouraged, as it does not have a means of reliably reporting parsing errors (BaBar does not use C++ exceptions). Use BdbTime::parseTime() instead (which this is implemented over).

Definition at line 261 of file BdbTime.cc.

References getGmtNsec(), getGmtSec(), and parseTime().

BdbTime::BdbTime const std::string &   ,
Zone    zone = UTC
[explicit]
 

(Deprecated - use parseTime()) Constructs a BdbTime from a single date-time string, in which the date and time must be given separated by whitespace. Otherwise identical to the above constructor.

The use of this constructor is strongly discouraged, as it does not have a means of reliably reporting parsing errors (BaBar does not use C++ exceptions). Use BdbTime::parseTime() instead (which this is implemented over).

Definition at line 279 of file BdbTime.cc.

References getGmtNsec(), getGmtSec(), and parseTime().

BdbTime::BdbTime const struct timespec &    ts
 

Constructs from POSIX high-resolution time, as might be obtained from clock_gettime.

Definition at line 308 of file BdbTime.cc.

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 295 of file BdbTime.cc.

BdbTime::~BdbTime   [inline]
 

The destructor is non-virtual in order to keep this representational class small and suitable for processing with value semantics. Classes with non-empty destructors should not be constructed with non-private inheritance from BdbTime.

Definition at line 156 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 396 of file BdbTime.cc.

References tm().

Referenced by main(), operator<<(), and CdbTimeUtils::time2string2().

d_ULong BdbTime::getGmtNsec   const [inline]
 

Definition at line 214 of file BdbTime.hh.

Referenced by BdbTime(), CdbBdbSPartitionP::close(), CdbBdbSSimpleClusterP::createIncrement(), CdbBdbSPartitionP::createIncrement(), CdbBdbSTimeLineP< V >::dump(), CdbBdbSRevCollectionP::dump(), CdbBdbSPartitionInterval::dump(), CdbBdbSOiCollectionP::dump(), CdbBdbSIncrement::dump(), CdbBdbSCi::dump(), CdbSQLApiCondition::findObject(), CdbBdbSCondition::findObject(), main(), operator<<(), CdbBdbSMetaDataP::rebuild(), CdbBdbSOiCollectionP::replace(), CdbBdbSCondition::storeObject(), CdbTimeUtils::time2string(), CdbTimeUtils::time2string2(), and CdbTimeUtils::to_nsec().

d_ULong BdbTime::getGmtSec   const [inline]
 

Definition at line 213 of file BdbTime.hh.

Referenced by bdb_to_time_t(), BdbTime(), CdbBdbSPartitionP::close(), CdbBdbSSimpleClusterP::createIncrement(), CdbBdbSPartitionP::createIncrement(), CdbBdbSTimeLineP< V >::dump(), CdbBdbSRevCollectionP::dump(), CdbBdbSPartitionInterval::dump(), CdbBdbSOiCollectionP::dump(), CdbBdbSIncrement::dump(), CdbBdbSCi::dump(), CdbRooInit::event(), CdbBdbInit::event(), CdbSQLApiCondition::findObject(), CdbBdbSCondition::findObject(), main(), operator<<(), CdbBdbSMetaDataP::rebuild(), CdbBdbSOiCollectionP::replace(), CdbBdbSCondition::storeObject(), CdbTimeUtils::time2string(), and CdbTimeUtils::to_nsec().

BdbTime BdbTime::now   [static]
 

Constructs and returns a BdbTime representing the current time. This interface, unlike the deprecated default constructor, returns a BdbTime set to the full resolution available from clock_gettime(). Note that this may vary between platforms and even operating system versions.

Definition at line 538 of file BdbTime.cc.

References BdbTime().

Referenced by CdbRooInit::beginJob(), CdbBdbInit::beginJob(), CdbMySQLOrigin::close_partition(), CdbBdbSSlaveRegistryP::create(), CdbMySQLFolder::create_folder(), CdbMySQLOrigin::create_partition(), CdbMySQLCondition::create_revision(), CdbMySQLFolder::include_condition(), CdbMySQL::initialize_master_origin(), CdbMySQLOrigin::instantiate_partition(), and main().

bool BdbTime::operator!= const BdbTime &    t const [inline]
 

Definition at line 185 of file BdbTime.hh.

BdbTime BdbTime::operator+ const BdbDuration   d const
 

Definition at line 508 of file BdbTime.cc.

References BdbTime().

BdbTime & BdbTime::operator+= const BdbDuration   d
 

Definition at line 514 of file BdbTime.cc.

References BdbDuration::getNsec(), BdbDuration::getSec(), and BdbTimeConst::nsecInASec.

BdbTime BdbTime::operator- const BdbDuration   d const
 

Definition at line 476 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 436 of file BdbTime.cc.

References _gmtNsec, _gmtSec, and BdbTimeConst::nsecInASec.

BdbTime & BdbTime::operator-= const BdbDuration   d
 

Definition at line 482 of file BdbTime.cc.

References BdbDuration::getNsec(), BdbDuration::getSec(), and BdbTimeConst::nsecInASec.

bool BdbTime::operator< const BdbTime &    t const [inline]
 

Definition at line 190 of file BdbTime.hh.

References _gmtNsec, and _gmtSec.

bool BdbTime::operator<= const BdbTime &    t const [inline]
 

Definition at line 196 of file BdbTime.hh.

References _gmtNsec, and _gmtSec.

BdbTime & BdbTime::operator= const BdbTime &    t
 

Definition at line 425 of file BdbTime.cc.

References _gmtNsec, and _gmtSec.

bool BdbTime::operator== const BdbTime &    t const [inline]
 

Definition at line 180 of file BdbTime.hh.

References _gmtNsec, and _gmtSec.

bool BdbTime::operator> const BdbTime &    t const [inline]
 

Definition at line 202 of file BdbTime.hh.

bool BdbTime::operator>= const BdbTime &    t const [inline]
 

Definition at line 207 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.

Equivalent to a call to parseTime( const std::string& sdate, const std::string& stime, Zone zone, BdbTime& time ) with the date and time set from the first and second whitespace- delimited tokens in the sdatetime string and subsequent text ignored.

This is a less precise parsing method than the above.

Parameters:
time Returned time value; modified only if parsing is successful.
Returns:
Flag indicating whether parsing was successful.

Definition at line 592 of file BdbTime.cc.

References minusInfinity, parseTime(), and plusInfinity.

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 1901.01.01 00:00:00 UTC is not a valid time; 00:00:01 is the first valid time.

Date is parsed using strptime formats "%D" and "%d%b%Y", controlled by BdbTimeInput, with the first one that succeeds taking precedence. Time is parsed with formats "%T" and "%R". These are quite a restricted set compared to those originally accepted by the Rogue Wave implementation first used here.

By default times are interpreted as UTC (a logical alternative might be the local time zone. If an invalid date or time string is supplied, the BdbTime time will be set to -Infinity. If the date string is set to "+Infinity" or "-Infinity", the time string will be ignored and the BdbTime will be set to the corresponding value.

Parameters:
time Returned time value; modified only if parsing is successful.
Returns:
Flag indicating whether parsing was successful.

Definition at line 554 of file BdbTime.cc.

References BdbTime(), minusInfinity, BdbTimeInput::parseDate(), BdbTimeInput::parseTime(), plusInfinity, BdbTimeInput::Status, BdbTimeInput::Success, and tm().

Referenced by BdbTime(), CdbRooInit::beginJob(), CdbBdbInit::beginJob(), parseTime(), CdbBdbLoadList::storeObjects(), CdbTimeUtils::string2time(), and testString().

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 316 of file BdbTime.cc.

References 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 345 of file BdbTime.cc.

References BdbTimeConst::seconds_1901_to_1970.

Referenced by asString(), BdbTime(), main(), and parseTime().


Friends And Related Function Documentation

BdbTime operator+ const BdbDuration   d,
const BdbTime &    t1
[friend]
 

Definition at line 625 of file BdbTime.cc.

std::ostream& operator<< std::ostream &    os,
const BdbTime &    t
[friend]
 

Definition at line 630 of file BdbTime.cc.


Member Data Documentation

const BdbTime BdbTime::minusInfinity = BdbTime( BdbTimeConst::minusInfinity ) [static]
 

Definition at line 47 of file BdbTime.cc.

Referenced by CdbRooRoConfigElementR::accessIsAllowed(), CdbBdbSConfigElement::accessIsAllowed(), CdbBdbSConfigCollectionP::CdbBdbSConfigCollectionP(), CdbBdbSMetaDataP::close(), CdbMySQLOrigin::close_partition(), CdbBdbSPartitionBaseP::closeCell(), CdbSQLApiView::configIterator(), CdbMySQLCondition::create_revision(), CdbSQLApiDatabase::created(), CdbBdbWView::created(), CdbBdbWFolder::created(), CdbBdbWDatabase::created(), CdbBdbWCondition::created(), CdbBdbSIncrementCollection::createIncrement(), CdbRooRoRevCollectionR::find(), CdbBdbSRevCollectionP::find(), CdbSQLApiCondition::findObject(), CdbRooRoCondition::findObject(), CdbBdbSCondition::findObject(), CdbSQLApiDatabase::id(), CdbBdbWDatabase::id(), CdbMySQL::initialize_master_origin(), CdbRooRoRevCollectionR::insert(), CdbBdbSRevCollectionP::insert(), CdbBdbSConfigCollectionP::insert(), CdbMySQLOrigin::instantiate_partition(), CdbMySQL::instantiate_slave_origin(), CdbRooRoTimeLineR< V >::iterator(), CdbBdbSTimeLineP< V >::iterator(), main(), CdbBdbWView::minValidity(), CdbSQLApiCondition::modified(), CdbRooRoCondition::modified(), CdbMySQLCondition::modified(), CdbBdbWCondition::modified(), CdbBdbSCondition::modified(), operator<<(), parseTime(), CdbBdbWCondition::registered(), CdbBrowserTool::run(), CdbMySQLConditionAtFolder::set_config(), CdbEnvironmentImpl::setTruncateTime(), CdbTimeUtils::time2string(), CdbMySQLPartition::update(), and CdbBdbSPartitionP::update().

const BdbTime BdbTime::plusInfinity = BdbTime( BdbTimeConst::plusInfinity ) [static]
 

Definition at line 48 of file BdbTime.cc.

Referenced by CdbBdbSConfigCollectionP::CdbBdbSConfigCollectionP(), CdbBdbSPartitionBaseP::closeCell(), CdbSQLApiView::configIterator(), CdbMySQLOrigin::create_partition(), CdbMySQLCondition::create_revision(), CdbSQLApiDatabase::created(), CdbRooRoDatabase::created(), CdbBdbSDatabase::created(), CdbBdbSIncrementCollection::createIncrement(), CdbRooRoView::currentStateId(), CdbRooRoRevCollectionR::dump(), CdbRooRoRevCollectionR::find(), CdbRooRoPartitionsLayoutR::find(), CdbRooRoOiCollectionR::find(), CdbBdbSRevCollectionP::find(), CdbBdbSPartitionsLayoutP::find(), CdbBdbSOiCollectionP::find(), CdbRooRoMetaDataR::findByRevision(), CdbBdbSMetaDataP::findByRevision(), CdbSQLApiCondition::findObject(), CdbRooRoCondition::findObject(), CdbBdbWCondition::findObject(), CdbBdbSCondition::findObject(), CdbRooRoMetaDataR::findRevision(), CdbBdbWCondition::findRevision(), CdbBdbSMetaDataP::findRevision(), CdbTimeUtils::from_nsec(), CdbSQLApiDatabase::id(), CdbRooRoDatabase::id(), CdbBdbSDatabase::id(), CdbMySQL::initialize_master_origin(), CdbRooRoRevCollectionR::insert(), CdbBdbSRevCollectionP::insert(), CdbBdbSConfigCollectionP::insert(), CdbMySQLOrigin::instantiate_partition(), CdbMySQL::instantiate_slave_origin(), CdbBdbSPartitionBaseP::isClosed(), CdbRooRoTimeLineR< V >::iterator(), CdbBdbSTimeLineP< V >::iterator(), CdbRooRoRevCollectionR::last(), main(), CdbBdbWView::maxValidity(), CdbSQLApiCondition::modified(), CdbRooRoCondition::modified(), operator<<(), parseTime(), CdbBdbSMetaDataP::rebuild(), CdbBrowserTool::run(), CdbMySQLConditionAtFolder::set_config(), CdbTimeUtils::time2string(), CdbMySQLPartition::update(), and CdbBdbSPartitionP::update().


The documentation for this class was generated from the following files:
Generated on Mon Dec 5 18:22:17 2005 for CDB by doxygen1.3-rc3