OnixS C++ ICE Binary Order Entry Handler 1.1.1
API Documentation
Loading...
Searching...
No Matches
TimeSpan Class Reference

Public Types

typedef Int64 Ticks
typedef Int32 Days
typedef Int32 Hours
typedef Int32 Minutes
typedef Int32 Seconds
typedef Int32 Milliseconds
typedef Int32 Microseconds
typedef Int32 Nanoseconds

Public Member Functions

std::string toString (TimeSpanFormat::Enum=TimeSpanFormat::SDHHMMSSnsec) const
constexpr TimeSpan (Ticks ticks=0) noexcept
 TimeSpan (Days days, Hours hours, Minutes minutes, Seconds seconds, Nanoseconds nanoseconds) noexcept
 TimeSpan (Hours hours, Minutes minutes, Seconds seconds, Nanoseconds nanoseconds) noexcept
Days days () const noexcept
Hours hours () const noexcept
Minutes minutes () const noexcept
Seconds seconds () const noexcept
Milliseconds milliseconds () const noexcept
Microseconds microseconds () const noexcept
Nanoseconds nanoseconds () const noexcept
Ticks ticks () const noexcept
TimeSpanoperator+= (const TimeSpan &other) noexcept
TimeSpanoperator-= (const TimeSpan &other) noexcept
void swap (TimeSpan &other) noexcept

Static Public Member Functions

static TimeSpan fromStr (const std::string &)
static TimeSpan fromStr (StrRef)

Detailed Description

Used primarily to present time-only stamps and to time intervals between two timestamps.

Definition at line 146 of file Time.h.

Member Typedef Documentation

◆ Days

typedef Int32 Days

Integral type for number of days.

Definition at line 153 of file Time.h.

◆ Hours

typedef Int32 Hours

Integral type for number of hours.

Definition at line 156 of file Time.h.

◆ Microseconds

Integral type for number of microseconds.

Definition at line 168 of file Time.h.

◆ Milliseconds

Integral type for number of milliseconds.

Definition at line 165 of file Time.h.

◆ Minutes

typedef Int32 Minutes

Integral type for number of minutes.

Definition at line 159 of file Time.h.

◆ Nanoseconds

typedef Int32 Nanoseconds

Integral type for number of nanoseconds.

Definition at line 171 of file Time.h.

◆ Seconds

typedef Int32 Seconds

Integral type for number of seconds.

Definition at line 162 of file Time.h.

◆ Ticks

typedef Int64 Ticks

Integral type presenting internal ticks.

Definition at line 150 of file Time.h.

Constructor & Destructor Documentation

◆ TimeSpan() [1/3]

TimeSpan ( Ticks ticks = 0)
inlineexplicitconstexprnoexcept

Initializes the timespan from the given number of ticks.

Definition at line 178 of file Time.h.

179 : ticks_(ticks)
180 {
181 }

◆ TimeSpan() [2/3]

TimeSpan ( Days days,
Hours hours,
Minutes minutes,
Seconds seconds,
Nanoseconds nanoseconds )
inlinenoexcept

Initializes with the given set of values.

Input parameters are treated as quantities, but not as a time stamp. Therefore, there's no requirement to fit in a certain range like hours must fit into [0, 24) range. After initialization time span will be normalized.

Definition at line 190 of file Time.h.

191 : ticks_(
192 numericCast<Ticks>(days) *
193 TimeTraits::nanosecondsPerDay() +
194 numericCast<Ticks>(hours) *
195 TimeTraits::nanosecondsPerHour() +
196 numericCast<Ticks>(minutes) *
197 TimeTraits::nanosecondsPerMinute() +
198 numericCast<Ticks>(seconds) *
199 TimeTraits::nanosecondsPerSecond() +
200 nanoseconds)
201 {
202 }

◆ TimeSpan() [3/3]

TimeSpan ( Hours hours,
Minutes minutes,
Seconds seconds,
Nanoseconds nanoseconds )
inlinenoexcept

Initializes with the given set of values.

Input parameters are treated as quantities, but not as a time stamp. Therefore, there's no requirement to fit in a certain range like hours must fit into [0, 24) range. After initialization time span will be normalized.

Definition at line 211 of file Time.h.

212 : ticks_(
213 numericCast<Ticks>(hours) *
214 TimeTraits::nanosecondsPerHour() +
215 numericCast<Ticks>(minutes) *
216 TimeTraits::nanosecondsPerMinute() +
217 numericCast<Ticks>(seconds) *
218 TimeTraits::nanosecondsPerSecond() +
219 nanoseconds)
220 {
221 }

Member Function Documentation

◆ days()

Days days ( ) const
inlinenoexcept
Returns
the Days component of the time interval.

Definition at line 224 of file Time.h.

225 {
226 return
227 numericCast<Days>
228 (ticks_ /
229 TimeTraits::nanosecondsPerDay());
230 }

◆ fromStr() [1/2]

TimeSpan fromStr ( const std::string & str)
inlinestatic

De-serializes the timespan from the given string according to the specified pattern.

Exceptions
std::runtime_errorif the de-serialization is impossible.

Definition at line 866 of file Time.h.

867{
868 return fromStr(StrRef{str});;
869}
T fromStr(const std::string &s)
Definition Helpers.h:142

◆ fromStr() [2/2]

TimeSpan fromStr ( StrRef str)
inlinestatic

Definition at line 872 of file Time.h.

873{
874 TimeSpan ts;
875
876 const bool result = Messaging::fromStr(ts, str);
877
878 if(!result)
879 throw std::runtime_error("Error parsing TimeSpan, invalid value: '" + toStr(str) + "'.");
880
881 return ts;
882}
std::string toStr(Order::PriceOptional value)
Definition Order.cpp:34

◆ hours()

Hours hours ( ) const
inlinenoexcept
Returns
the Hours component of the time interval.

Values are in range from -23 through 23.

Definition at line 235 of file Time.h.

236 {
237 return
238 numericCast<Hours>(
239 (ticks_ /
240 TimeTraits::nanosecondsPerHour()) %
241 TimeTraits::hoursPerDay()
242 );
243 }

◆ microseconds()

Microseconds microseconds ( ) const
inlinenoexcept
Returns
the Microseconds component of the time interval.

Values are in range from -999999 through 999999.

Definition at line 287 of file Time.h.

288 {
289 return
290 numericCast<Microseconds>
291 ((ticks_ /
292 TimeTraits::nanosecondsPerMicrosecond()) %
293 TimeTraits::microsecondsPerSecond()
294 );
295 }

◆ milliseconds()

Milliseconds milliseconds ( ) const
inlinenoexcept
Returns
the Milliseconds component of the time interval.

Values are in range from -999 through 999.

Definition at line 274 of file Time.h.

275 {
276 return
277 numericCast<Milliseconds>
278 ((ticks_ /
279 TimeTraits::nanosecondsPerMillisecond()) %
280 TimeTraits::millisecondsPerSecond()
281 );
282 }

◆ minutes()

Minutes minutes ( ) const
inlinenoexcept
Returns
the Minutes component of the time interval.

Values are in range from -59 through 59.

Definition at line 248 of file Time.h.

249 {
250 return
251 numericCast<Minutes>(
252 (ticks_ /
253 TimeTraits::nanosecondsPerMinute()) %
254 TimeTraits::minutesPerHour()
255 );
256 }

◆ nanoseconds()

Nanoseconds nanoseconds ( ) const
inlinenoexcept
Returns
the Nanoseconds component of the time interval.

Values are in range from -999999999 through 999999999.

Definition at line 300 of file Time.h.

301 {
302 return
303 numericCast<Nanoseconds>
304 (ticks_ %
305 TimeTraits::nanosecondsPerSecond());
306 }

◆ operator+=()

TimeSpan & operator+= ( const TimeSpan & other)
inlinenoexcept

Adds the given time interval.

Definition at line 318 of file Time.h.

319 {
320 ticks_ += other.ticks_;
321
322 return *this;
323 }

◆ operator-=()

TimeSpan & operator-= ( const TimeSpan & other)
inlinenoexcept

Subtracts the given time interval.

Definition at line 326 of file Time.h.

327 {
328 ticks_ -= other.ticks_;
329
330 return *this;
331 }

◆ seconds()

Seconds seconds ( ) const
inlinenoexcept
Returns
the Seconds component of the time interval.

Values are in range from -59 through 59.

Definition at line 261 of file Time.h.

262 {
263 return
264 numericCast<Seconds>(
265 (ticks_ /
266 TimeTraits::nanosecondsPerSecond()) %
267 TimeTraits::secondsPerMinute()
268 );
269 }

◆ swap()

void swap ( TimeSpan & other)
inlinenoexcept

Swaps.

Definition at line 334 of file Time.h.

335 {
336 std::swap(ticks_, other.ticks_);
337 }

◆ ticks()

Ticks ticks ( ) const
inlinenoexcept
Returns
the number of ticks in the time interval.

Ticks are the lowest time quantity used to measure time intervals. In the current implementation ticks are nanoseconds.

Definition at line 312 of file Time.h.

313 {
314 return ticks_;
315 }

◆ toString()

std::string toString ( TimeSpanFormat::Enum format = TimeSpanFormat::SDHHMMSSnsec) const
inline
Returns
a human-readable presentation.

Definition at line 886 of file Time.h.

887{
888 return toStr(*this, format);
889}