OnixS C++ Eurex T7 Market and Reference Data Interface (EMDI, RDI, EOBI) Handlers  7.0.3
API documentation
TimeSpan.h
Go to the documentation of this file.
1 /*
2 * Copyright Onix Solutions Limited [OnixS]. All rights reserved.
3 *
4 * This software owned by Onix Solutions Limited [OnixS] and is protected by copyright law
5 * and international copyright treaties.
6 *
7 * Access to and use of the software is governed by the terms of the applicable OnixS Software
8 * Services Agreement (the Agreement) and Customer end user license agreements granting
9 * a non-assignable, non-transferable and non-exclusive license to use the software
10 * for it's own data processing purposes under the terms defined in the Agreement.
11 *
12 * Except as otherwise granted within the terms of the Agreement, copying or reproduction of any part
13 * of this source code or associated reference material to any other location for further reproduction
14 * or redistribution, and any amendments to this copyright notice, are expressly prohibited.
15 *
16 * Any reproduction or redistribution for sale or hiring of the Software not in accordance with
17 * the terms of the Agreement is a violation of copyright law.
18 */
19 #pragma once
20 
22 #include <string>
23 
24 namespace OnixS
25 {
26  namespace Eurex
27  {
28  namespace MarketData
29  {
30  /// Time span formats supported.
31  struct ONIXS_EUREX_EMDI_API TimeSpanFormats
32  {
33  enum Enum
34  {
35  /// HH:MM:SS.
37 
38  /// HH:MM:SS.sss.
40 
41  /// HH:MM:SS.sssssssss.
42  SDHHMMSSnsec
43  };
44  };
45 
46  /// Time span format.
48 
49  /// Represents time interval. Used primarily to
50  /// present time-only stamps and to measure time
51  /// intervals between two timestamps.
52  class ONIXS_EUREX_EMDI_API TimeSpan
53  {
54  public:
55  /// Initializes zero span.
56  TimeSpan();
57 
58  /// Initializes with given set of values.
59  /// Input parameters are treated as quantities,
60  /// but not as a time stamp. Therefore, there's
61  /// no requirement to fit in a certain range like
62  /// hours must fit into [0, 24) range. After
63  /// initialization time span will be normalized.
64  TimeSpan (int hours, int minutes, int seconds, int nanoseconds = 0);
65 
66  /// Initializes with given set of values.
67  /// Input parameters are treated as quantities,
68  /// but not as a time stamp. Therefore, there's
69  /// no requirement to fit in a certain range like
70  /// hours must fit into [0, 24) range. After
71  /// initialization time span will be normalized.
72  TimeSpan (int days, int hours, int minutes, int seconds, int nanoseconds);
73 
74  /// Initializes time interval from total number
75  /// seconds and its fractional (nanosecond) part.
76  TimeSpan (long long totalSeconds, int nanoseconds);
77 
78  /// Initializes as clone of other instance.
79  TimeSpan (const TimeSpan& other);
80 
81  /// Whole number of seconds in time interval.
82  long long totalSeconds() const;
83 
84  /// Days component of time interval.
85  /// Whole number of days in time interval.
86  int days() const;
87 
88  /// Hours component of time interval.
89  /// Values are in range from -23 through 23.
90  int hours() const;
91 
92  /// Minutes component of time interval.
93  /// Values are in range from -59 through 59.
94  int minutes() const;
95 
96  /// Seconds component of time interval.
97  /// Values are in range from -59 through 59.
98  int seconds() const;
99 
100  /// Milliseconds component of time interval.
101  /// Values are in range from -999 through 999.
102  int milliseconds() const;
103 
104  /// Microseconds component of time interval.
105  /// Values are in range from -999999 through 999999.
106  int microseconds() const;
107 
108  /// Nanoseconds component of time interval.
109  /// Values are in range from -999999999 through 999999999.
110  int nanoseconds() const;
111 
112  /// Compares with other instance for equality.
113  bool operator == (const TimeSpan& other) const;
114 
115  /// Compares with other instance for in-equality.
116  bool operator != (const TimeSpan& other) const;
117 
118  /// Checks whether time interval less than other one.
119  bool operator < (const TimeSpan& other) const;
120 
121  /// Checks whether time interval greater than other one.
122  bool operator >(const TimeSpan& other) const;
123 
124  /// Adds time interval to current one.
125  TimeSpan& operator += (const TimeSpan& other);
126 
127  /// Subtracts time interval from current one.
128  TimeSpan& operator -= (const TimeSpan& other);
129 
130  /// Re-assigns time interval from other one.
131  TimeSpan& operator = (const TimeSpan& other);
132 
133  /// Serializes time stamp into text presentation
134  /// using specified time-span presentation format.
135  void toString (std::string& str, TimeSpanFormat format = TimeSpanFormats::SDHHMMSSnsec) const;
136 
137  /// Serializes time stamp into text presentation
138  /// using specified time-span presentation format.
139  std::string toString (TimeSpanFormat format = TimeSpanFormats::SDHHMMSSnsec) const;
140 
141  /// De-serializes time interval from its text presentation.
142  static TimeSpan deserialize (const std::string& str);
143 
144  /// Time interval of zero length.
145  static const TimeSpan Zero;
146 
147  private:
148  long long seconds_;
149  int nanoseconds_;
150  };
151 
152  inline long long TimeSpan::totalSeconds() const
153  {
154  return seconds_;
155  }
156 
157  inline int TimeSpan::nanoseconds() const
158  {
159  return nanoseconds_;
160  }
161 
162  inline std::string TimeSpan::toString (TimeSpanFormat format) const
163  {
164  std::string str;
165 
166  toString (str, format);
167 
168  return str;
169  }
170  }
171  }
172 }
TimeSpanFormats::Enum TimeSpanFormat
Time span format.
Definition: TimeSpan.h:47
bool operator<(const Decimal &l, const Decimal &r)
Definition: Decimal.cpp:124
bool operator==(const FieldValueRef &ref, const std::string &str)
Definition: Group.h:25
long long totalSeconds() const
Whole number of seconds in time interval.
Definition: TimeSpan.h:152
static const TimeSpan Zero
Time interval of zero length.
Definition: TimeSpan.h:145
Time span formats supported.
Definition: TimeSpan.h:31
bool operator!=(const FieldValueRef &ref, const std::string &str)
void toString(std::string &str, TimeSpanFormat format=TimeSpanFormats::SDHHMMSSnsec) const
Definition: TimeSpan.cpp:214
bool operator>(const Decimal &l, const Decimal &r)
Definition: Decimal.cpp:129