00001 #ifndef CDB_TIME_UTILS_HH 00002 #define CDB_TIME_UTILS_HH 00003 00004 // File and Version Information: 00005 // $Id: CdbTimeUtils.hh,v 1.4 2005/10/25 17:25:29 gapon Exp $ 00006 00007 #include "CdbBase/CdbCommon.hh" 00008 00009 #include "BdbTime/BdbTime.hh" 00010 00011 #include <string> 00012 00013 /// A utility class for manipulations with objects of the BdbTime class 00014 /** 00015 * This is a collection of most common operations with BdbTime done in 00016 * in the context of CDB API, its implementations, and its clients. 00017 */ 00018 class CdbTimeUtils { 00019 00020 public: 00021 00022 /// Translate a string into an object of BdbTime 00023 /** 00024 * This utility method would attempt to translate the specified string into 00025 * an object of the BdbTime class if this is possible. A non zero pointer onto 00026 * a string is expected. 00027 * 00028 * NOTE; Unlike the standard method of translating time available through 00029 * 00030 * BdbTime::parseTime() 00031 * 00032 * the current one will also recognize an internal numeric format of time. 00033 * 00034 * If the translation will be successfull then the resulting flag would be set 00035 * to "true" and the reference would be properly initialized. Otherwise 00036 * the reference would not be affected. 00037 * 00038 * @return a boolen flag indicating the result of the translation. 00039 */ 00040 static bool string2time( BdbTime& theTime, /**< the value to be initialized */ 00041 const char* theString /**< the input string */ 00042 ); 00043 00044 /// Translate a string into an object of BdbTime 00045 /** 00046 * A variation of the above explained method. 00047 */ 00048 static bool string2time( BdbTime& theTime, 00049 const std::string& theString 00050 ); 00051 00052 /// Translate an object of BdbTime into a string 00053 /** 00054 * The method would return a string with an internal representation of time: 00055 * 00056 * <seconds>.<nanoseconds> 00057 * 00058 * The only exception of this rule is for the value of BdbTime::minusInfinity and 00059 * BdbTime::plusInfinity. By default they would be printed as: 00060 * 00061 * " -Infinity " 00062 * " +Infinity " 00063 * 00064 * unless an optional flag "forceInternalFormat" is set to "true". 00065 * 00066 * By default the resulting string will be of afixed length: 11+1+11=23 characters 00067 * unless an optional flag "packedFormat" is set to "true". 00068 * 00069 * @return a string representation of the input object. 00070 */ 00071 static std::string time2string( const BdbTime& theTime, /**< the input object to be translated */ 00072 bool forceInternalFormat = false, /**< the format control flag for "infinity" values */ 00073 bool packedFormat = false /**< the format control flag */ 00074 ); 00075 00076 /// Translate an object of BdbTime into a string 00077 /** 00078 * The method would return a string with an internal representation of time 00079 * followed by its human readable string: 00080 * 00081 * 3123456789.0987654321 : Wed 15 Jan 2005 10:11:00 (local timezone) 0 ns 00082 * 00083 * @see CdbTimeUtils::time2string() 00084 */ 00085 static std::string time2string2( const BdbTime& theTime, /**< the input object to be translated */ 00086 BdbTime::Zone theTimeZone = BdbTime::Local, /**< the way we're interpreting the time */ 00087 bool forceInternalFormat = false, /**< the format control flag for "infinity" values */ 00088 bool packedFormat = false /**< the format control flag */ 00089 ); 00090 /// Get the current timestamp 00091 /** 00092 * This utility function would produce a string with the current timestamp 00093 * in the following format: 00094 * 00095 * monthDay_hour::minute::sec.milisec 00096 */ 00097 static std::string get_current_timestamp( ); 00098 00099 /// Translate a 64-bit number of nanoseconds into an object of BdbTime 00100 /** 00101 * A number on the input is supposed to be a previously packed value of 00102 * a BdbTime object. 00103 * 00104 * The overflow is returned as BdbTime::plusInfinity 00105 */ 00106 static BdbTime from_nsec( unsigned long long theNumber ); 00107 00108 /// Translate an object of BdbTime class into a 64-bit number of nanoseconds 00109 /** 00110 * A number on the input is supposed to be a previously packed value of 00111 * a BdbTime object. 00112 */ 00113 static unsigned long long to_nsec( const BdbTime& theTime ); 00114 }; 00115 00116 #endif // CDB_TIME_UTILS_HH
1.3-rc3