|
NCBI C++ ToolKit
|
Search Toolkit Book for CTimeSpan
#include <ncbitime.hpp>
Public Types | |
| enum | ESmartStringPrecision { eSSP_Year, eSSP_Month, eSSP_Day, eSSP_Hour, eSSP_Minute, eSSP_Second, eSSP_Millisecond, eSSP_Microsecond, eSSP_Nanosecond, eSSP_Precision1, eSSP_Precision2, eSSP_Precision3, eSSP_Precision4, eSSP_Precision5, eSSP_Precision6, eSSP_Precision7, eSSP_Default = eSSP_Day } |
| Precision for span "smart" string. Used in AsSmartString() method. More... | |
| enum | ESmartStringZeroMode { eSSZ_SkipZero, eSSZ_NoSkipZero, eSSZ_Default = eSSZ_SkipZero } |
| Which format use to zero time span output. More... | |
Public Member Functions | |
| CTimeSpan (void) | |
| Default constructor. | |
| CTimeSpan (long days, long hours, long minutes, long seconds, long nanoseconds=0) | |
| Constructor. | |
| CTimeSpan (long seconds, long nanoseconds=0) | |
| Constructor. | |
| CTimeSpan (double seconds) | |
| Constructor. | |
| CTimeSpan (const string &str, const CTimeFormat &fmt=kEmptyStr) | |
| Explicit conversion constructor for string representation of time span. | |
| CTimeSpan (const CTimeSpan &t) | |
| Copy constructor. | |
| CTimeSpan & | operator= (const CTimeSpan &t) |
| Assignment operator. | |
| CTimeSpan & | operator= (const string &str) |
| Assignment operator. | |
| CTimeSpan & | Clear (void) |
| Make the time span "empty",. | |
| ESign | GetSign (void) const |
| Get sign of time span. | |
| string | AsString (const CTimeFormat &format=kEmptyStr) const |
| Transform time span to string. | |
| operator string (void) const | |
| Return span time as string using the format returned by GetFormat(). | |
| string | AsSmartString (ESmartStringPrecision precision=eSSP_Default, ERound rounding=eTrunc, ESmartStringZeroMode zero_mode=eSSZ_Default) const |
| Transform time span to "smart" string. | |
| long | GetCompleteDays (void) const |
| Get number of complete days. | |
| long | GetCompleteHours (void) const |
| Get number of complete hours. | |
| long | GetCompleteMinutes (void) const |
| Get number of complete minutes. | |
| long | GetCompleteSeconds (void) const |
| Get number of complete seconds. | |
| long | GetNanoSecondsAfterSecond (void) const |
| Get number of nanoseconds. | |
| double | GetAsDouble (void) const |
| Return time span as number of seconds. | |
| bool | IsEmpty (void) const |
| Return TRUE is an object keep zero time span. | |
| void | Set (long seconds, long nanoseconds=0) |
| Set time span in seconds and nanoseconds. | |
| void | Set (double seconds) |
| Set time span from number of seconds (fractional value). | |
| CTimeSpan & | operator+= (const CTimeSpan &t) |
| CTimeSpan | operator+ (const CTimeSpan &t) const |
| CTimeSpan & | operator-= (const CTimeSpan &t) |
| Operator to subtract time span. | |
| CTimeSpan | operator- (const CTimeSpan &t) const |
| Operator to subtract time span. | |
| const CTimeSpan | operator- (void) const |
| Unary operator "-" (minus) to change time span sign. | |
| void | Invert (void) |
| Invert time span. Changes time span sign. | |
| bool | operator== (const CTimeSpan &t) const |
| Operator to test equality of time span. | |
| bool | operator!= (const CTimeSpan &t) const |
| Operator to test in-equality of time span. | |
| bool | operator> (const CTimeSpan &t) const |
| Operator to test if time span is greater. | |
| bool | operator< (const CTimeSpan &t) const |
| Operator to test if time span is less. | |
| bool | operator>= (const CTimeSpan &t) const |
| Operator to test if time span is greater or equal. | |
| bool | operator<= (const CTimeSpan &t) const |
| Operator to test if time span is less or equal. | |
Static Public Member Functions | |
| static void | SetFormat (const CTimeFormat &format) |
| Set the current time span format. | |
| static CTimeFormat | GetFormat (void) |
| Get the current time span format. | |
Private Member Functions | |
| int | x_Hour (void) const |
| Get hour. | |
| int | x_Minute (void) const |
| Get minute. | |
| int | x_Second (void) const |
| Get second. | |
| void | x_Init (const string &str, const CTimeFormat &format) |
| Helper method to set time value from string "str" using "format". | |
| void | x_Normalize (void) |
| Helper method to normalize stored time value. | |
Private Attributes | |
| long | m_Sec |
| Seconds part of the time span. | |
| long | m_NanoSec |
| Nanoseconds after the second. | |
Defines a class to represents a relative time span. Time span can be both positive and negative.
Throw exception of type CTimeException on errors.
Definition at line 1158 of file ncbitime.hpp.
Precision for span "smart" string. Used in AsSmartString() method.
Definition at line 1273 of file ncbitime.hpp.
Which format use to zero time span output.
Definition at line 1298 of file ncbitime.hpp.
| CTimeSpan::CTimeSpan | ( | void | ) | [inline] |
| CTimeSpan::CTimeSpan | ( | long | days, |
| long | hours, | ||
| long | minutes, | ||
| long | seconds, | ||
| long | nanoseconds = 0 |
||
| ) |
Constructor.
Construct time span given the number of days, hours, minutes, seconds, nanoseconds parts of a time span value.
| days | Day part of time. Note day starts from 1. |
| hours | Hour part of time. |
| minutes | Minute part of time. |
| seconds | Second part of time. |
| nanoseconds | Nanosecond part of time. |
Definition at line 2033 of file ncbitime.cpp.
References NStr::Int8ToString(), kNanoSecondsPerSecond, m_NanoSec, m_Sec, NCBI_THROW, and x_Normalize().
| CTimeSpan::CTimeSpan | ( | long | seconds, |
| long | nanoseconds = 0 |
||
| ) | [inline, explicit] |
Constructor.
Construct time span given the number of seconds and nanoseconds.
| seconds | Second part of time. |
| nanoseconds | Nanosecond part of time. |
Definition at line 2227 of file ncbitime.hpp.
| CTimeSpan::CTimeSpan | ( | double | seconds | ) | [inline, explicit] |
Constructor.
Construct time span from number of seconds. Please, use this constructor as rarely as possible, because after doing some arithmetical operations and conversion with it, the time span can differ at some nanoseconds from expected value.
| seconds | Second part of time. The fractional part is used to compute nanoseconds. |
Definition at line 2233 of file ncbitime.hpp.
| CTimeSpan::CTimeSpan | ( | const string & | str, |
| const CTimeFormat & | fmt = kEmptyStr |
||
| ) | [explicit] |
Explicit conversion constructor for string representation of time span.
Construct time span object from string representation of time.
| str | String representation of time span in format "fmt". |
| fmt | Format in which "str" is presented. Default value of kEmptyStr, implies the "-S.n" format. |
Definition at line 2053 of file ncbitime.cpp.
References GetFormat(), CTimeFormat::IsEmpty(), and x_Init().
| CTimeSpan::CTimeSpan | ( | const CTimeSpan & | t | ) | [inline] |
| string CTimeSpan::AsSmartString | ( | ESmartStringPrecision | precision = eSSP_Default, |
| ERound | rounding = eTrunc, |
||
| ESmartStringZeroMode | zero_mode = eSSZ_Default |
||
| ) | const |
Transform time span to "smart" string.
| precision | Enum value describing how many parts of time span should be returned. Values from eSSP_Year to eSSP_Nanosecond apparently describe part of time span which will be last in output string. Floating precision levels eSSP_PrecisionN say that maximum 'N' parts of time span will be put to output string. The parts counting begin from first non-zero value. |
| rounding | Rounding mode. By default time span will be truncated at last value |
| zero_mode | Mode to print or skip zero parts of time span which should be printed but have 0 value. Trailing and leading zeros will be never printed. |
Definition at line 2273 of file ncbitime.cpp.
References CTimeSpan(), eNegative, eRound, eSSP_Day, eSSP_Hour, eSSP_Microsecond, eSSP_Millisecond, eSSP_Minute, eSSP_Month, eSSP_Nanosecond, eSSP_Precision1, eSSP_Second, eSSP_Year, eSSZ_SkipZero, GetCompleteDays(), GetNanoSecondsAfterSecond(), GetSign(), Invert(), kMicroSecondsPerSecond, kNanoSecondsPerSecond, NStr::LongToString(), x_Hour(), x_Minute(), and x_Second().
Referenced by CStopWatch::AsSmartString().
| string CTimeSpan::AsString | ( | const CTimeFormat & | format = kEmptyStr | ) | const |
Transform time span to string.
| format | Format specifier used to convert time span to string. If "format" is not defined, then GetFormat() will be used. |
Definition at line 2205 of file ncbitime.cpp.
References abs, eNegative, f(), CTimeFormat::fFormat_Simple, GetCompleteDays(), GetCompleteHours(), GetCompleteMinutes(), GetCompleteSeconds(), CTimeFormat::GetFlags(), GetFormat(), GetNanoSecondsAfterSecond(), GetSign(), CTimeFormat::GetString(), CTimeFormat::IsEmpty(), ITERATE, kFormatEscapeSymbol, s_AddInt(), s_AddZeroPadInt(), s_AddZeroPadInt2(), x_Hour(), x_Minute(), and x_Second().
Referenced by CStopWatch::AsString(), CCgiStatistics::Compose_Timing(), CCgiTunnel2Grid::OnEndProcessRequest(), CCgi2RCgiApp::ProcessRequest(), CPeriodicTestJob::Run(), CTimeout::Set(), and sToUserFriendlyString().
| CTimeSpan & CTimeSpan::Clear | ( | void | ) | [inline] |
| double CTimeSpan::GetAsDouble | ( | void | ) | const [inline] |
Return time span as number of seconds.
Definition at line 2289 of file ncbitime.hpp.
References kNanoSecondsPerSecond.
Referenced by CThreadPool_Impl::AddTask(), CRequestRateControl::Reset(), s_ProgressCallback(), and CThreadPool_Impl::x_WaitForPredicate().
| long CTimeSpan::GetCompleteDays | ( | void | ) | const [inline] |
Get number of complete days.
Definition at line 2274 of file ncbitime.hpp.
Referenced by AsSmartString(), and AsString().
| long CTimeSpan::GetCompleteHours | ( | void | ) | const [inline] |
Get number of complete hours.
Definition at line 2277 of file ncbitime.hpp.
Referenced by AsString().
| long CTimeSpan::GetCompleteMinutes | ( | void | ) | const [inline] |
Get number of complete minutes.
Definition at line 2280 of file ncbitime.hpp.
Referenced by AsString().
| long CTimeSpan::GetCompleteSeconds | ( | void | ) | const [inline] |
Get number of complete seconds.
Definition at line 2283 of file ncbitime.hpp.
Referenced by CTime::AddTimeSpan(), AsString(), CScheduler_ExecThread_Impl::Main(), s_ProgressCallback(), CTimeout::Set(), CRequestRateControl::Sleep(), SleepUntil(), sToUserFriendlyString(), CThreadPool_ServiceThread::x_Idle(), CSyncQueue< Type, Container >::x_Lock(), CBlockingQueue< TRequest >::x_WaitForPredicate(), and CThreadPool_Impl::x_WaitForPredicate().
| CTimeFormat CTimeSpan::GetFormat | ( | void | ) | [static] |
Get the current time span format.
The default format is: "-S.n".
Definition at line 2192 of file ncbitime.cpp.
References format, CStaticTls< TValue >::GetValue(), kDefaultFormatSpan, and CTimeFormat::SetFormat().
Referenced by AsString(), and CTimeSpan().
| long CTimeSpan::GetNanoSecondsAfterSecond | ( | void | ) | const [inline] |
Get number of nanoseconds.
Definition at line 2286 of file ncbitime.hpp.
Referenced by CTime::AddTimeSpan(), AsSmartString(), AsString(), CScheduler_ExecThread_Impl::Main(), CTimeout::Set(), CRequestRateControl::Sleep(), SleepUntil(), CThreadPool_ServiceThread::x_Idle(), CSyncQueue< Type, Container >::x_Lock(), CBlockingQueue< TRequest >::x_WaitForPredicate(), and CThreadPool_Impl::x_WaitForPredicate().
| ESign CTimeSpan::GetSign | ( | void | ) | const [inline] |
Get sign of time span.
Definition at line 2253 of file ncbitime.hpp.
References eNegative, ePositive, and eZero.
Referenced by CTime::AddTimeSpan(), AsSmartString(), AsString(), CPeriodicTestJob::Run(), CTimeout::Set(), CBlockingQueue< TRequest >::x_WaitForPredicate(), and CThreadPool_Impl::x_WaitForPredicate().
| void CTimeSpan::Invert | ( | void | ) | [inline] |
Invert time span. Changes time span sign.
Definition at line 2368 of file ncbitime.hpp.
Referenced by AsSmartString(), and x_Init().
| bool CTimeSpan::IsEmpty | ( | void | ) | const [inline] |
Return TRUE is an object keep zero time span.
Definition at line 2303 of file ncbitime.hpp.
| CTimeSpan::operator string | ( | void | ) | const [inline] |
Return span time as string using the format returned by GetFormat().
Definition at line 2324 of file ncbitime.hpp.
Operator to test in-equality of time span.
Definition at line 2381 of file ncbitime.hpp.
Definition at line 2336 of file ncbitime.hpp.
Definition at line 2327 of file ncbitime.hpp.
Operator to subtract time span.
Definition at line 2352 of file ncbitime.hpp.
| const CTimeSpan CTimeSpan::operator- | ( | void | ) | const [inline] |
Unary operator "-" (minus) to change time span sign.
Definition at line 2359 of file ncbitime.hpp.
Operator to subtract time span.
Definition at line 2343 of file ncbitime.hpp.
Operator to test if time span is less.
Definition at line 2397 of file ncbitime.hpp.
Operator to test if time span is less or equal.
Definition at line 2412 of file ncbitime.hpp.
| CTimeSpan & CTimeSpan::operator= | ( | const string & | str | ) | [inline] |
Assignment operator.
Definition at line 2317 of file ncbitime.hpp.
References GetFormat(), and CException::x_Init().
Operator to test equality of time span.
Definition at line 2375 of file ncbitime.hpp.
Operator to test if time span is greater.
Definition at line 2387 of file ncbitime.hpp.
Operator to test if time span is greater or equal.
Definition at line 2406 of file ncbitime.hpp.
| void CTimeSpan::Set | ( | long | seconds, |
| long | nanoseconds = 0 |
||
| ) | [inline] |
Set time span in seconds and nanoseconds.
Definition at line 2295 of file ncbitime.hpp.
References kNanoSecondsPerSecond.
| void CTimeSpan::Set | ( | double | seconds | ) |
Set time span from number of seconds (fractional value).
Definition at line 1924 of file ncbitime.cpp.
References NStr::DoubleToString(), kNanoSecondsPerSecond, m_NanoSec, m_Sec, NCBI_THROW, and x_Normalize().
| void CTimeSpan::SetFormat | ( | const CTimeFormat & | format | ) | [static] |
Set the current time span format.
The default format is: "-S.n".
| format | An object contains string of letters describing the time format and its type. The format letters have the following meanings:
|
Definition at line 2183 of file ncbitime.cpp.
References s_TlsFormatCleanup(), and CStaticTls< TValue >::SetValue().
| int CTimeSpan::x_Hour | ( | void | ) | const [inline, private] |
Get hour.
Hours since midnight = -23..23
Definition at line 2265 of file ncbitime.hpp.
Referenced by AsSmartString(), and AsString().
| void CTimeSpan::x_Init | ( | const string & | str, |
| const CTimeFormat & | format | ||
| ) | [private] |
Helper method to set time value from string "str" using "format".
Definition at line 2062 of file ncbitime.cpp.
References Clear(), CTimeFormat::fFormat_Simple, CTimeFormat::fMatch_ShortFormat, CTimeFormat::fMatch_ShortTime, CTimeFormat::GetFlags(), CTimeFormat::GetString(), Invert(), kFormatEscapeSymbol, kFormatSymbolsSpan, len, m_NanoSec, m_Sec, NCBI_THROW, NStr::StringToLong(), and x_Normalize().
Referenced by CTimeSpan().
| int CTimeSpan::x_Minute | ( | void | ) | const [inline, private] |
Get minute.
Minutes after the hour = -59..59
Definition at line 2268 of file ncbitime.hpp.
Referenced by AsSmartString(), and AsString().
| void CTimeSpan::x_Normalize | ( | void | ) | [private] |
Helper method to normalize stored time value.
Definition at line 2168 of file ncbitime.cpp.
References kNanoSecondsPerSecond, m_NanoSec, and m_Sec.
Referenced by CTimeSpan(), Set(), and x_Init().
| int CTimeSpan::x_Second | ( | void | ) | const [inline, private] |
Get second.
Seconds after the minute = -59..59
Definition at line 2271 of file ncbitime.hpp.
Referenced by AsSmartString(), and AsString().
long CTimeSpan::m_NanoSec [private] |
Nanoseconds after the second.
Definition at line 1437 of file ncbitime.hpp.
Referenced by CTimeSpan(), operator+(), operator+=(), operator-(), operator-=(), operator<(), operator=(), operator==(), operator>(), Set(), x_Init(), and x_Normalize().
long CTimeSpan::m_Sec [private] |
Seconds part of the time span.
Definition at line 1436 of file ncbitime.hpp.
Referenced by CTimeSpan(), operator+(), operator+=(), operator-(), operator-=(), operator<(), operator=(), operator==(), operator>(), Set(), x_Init(), and x_Normalize().
1.7.5.1
Modified on Wed May 23 12:53:41 2012 by modify_doxy.py rev. 337098