OnixS C++ Eurex T7 Market and Reference Data Interface (EMDI, RDI, EOBI) Handlers  7.2.2
API documentation
Timestamp.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  /// Defines all the months in the year.
31  struct ONIXS_EUREX_EMDI_API Month
32  {
33  /// Defines all the months in the year.
34  enum Enum
35  {
41  May,
48  December
49  };
50  };
51 
52  /// Year, month, day fields.
53  struct ONIXS_EUREX_EMDI_API YearMonthDay
54  {
55  unsigned year;
57  unsigned day;
58  };
59 
60  /// Collection of timestamp formats supported.
61  struct ONIXS_EUREX_EMDI_API TimestampFormat
62  {
63  enum Enum
64  {
65  /// Indicates timestamp in "YYYYMMDD" format.
67 
68  /// Indicates timestamp in "YYYYMMDD-HH:MM:SS" format.
70 
71  /// Indicates timestamp in "YYYYMMDD-HH:MM:SS.sss" format.
73 
74  /// Indicates timestamp in "YYYYMMDD-HH:MM:SS.sssssssss" format.
75  YYYYMMDDHHMMSSNsec
76  };
77  };
78 
79  /// Represents timestamp without time-zone information.
80  class ONIXS_EUREX_EMDI_API Timestamp
81  {
82  public:
83  /// Initializes as Jan 1, 0001, 00:00:00.
84  Timestamp();
85 
86  /// Initializes date-time from all details.
87  Timestamp (
88  unsigned int year, Month::Enum month, unsigned int day,
89  unsigned int hour = 0, unsigned int minute = 0, unsigned int second = 0,
90  unsigned int nanosecond = 0);
91 
92  /// Year component of timestamp
93  unsigned year() const;
94 
95  /// Month component of timestamp
96  Month::Enum month() const;
97 
98  /// day of month component of timestamp
99  /// Valid values are 1 through 31.
100  unsigned int day() const;
101 
102  /// Returns date part of timestamp.
103  void date (YearMonthDay&) const;
104 
105  /// Hour component of timestamp.
106  /// Valid values are 0 through 23.
107  unsigned int hour() const;
108 
109  /// Minute component of timestamp
110  /// Valid values are 0 through 59.
111  unsigned int minute() const;
112 
113  /// Second component of timestamp
114  /// Valid values are 0 through 59.
115  unsigned int second() const;
116 
117  /// Millisecond component of timestamp
118  /// Valid values are 0 through 999.
119  unsigned int millisecond() const;
120 
121  /// Microsecond component of timestamp
122  /// Valid values are 0 through 999999.
123  unsigned int microsecond() const;
124 
125  /// Nanosecond component of timestamp
126  /// Valid values are 0 through 999999999.
127  unsigned int nanosecond() const;
128 
129  /// Time span since Jan 1, 0001, 00:00:00.
130  const TimeSpan& sinceEpoch() const;
131 
132  /// Epoch
133  static Timestamp epoch();
134 
135  /// Compares instance with another one.
136  bool operator == (const Timestamp&) const;
137 
138  /// Compares instance with another one.
139  bool operator != (const Timestamp&) const;
140 
141  /// Tests whether instance is less than another one.
142  bool operator < (const Timestamp&) const;
143 
144  /// Returns timestamp text presentation in requested
145  /// format ("YYYYMMDD-HH:MM:SS.sssssssss" by default).
146  std::string
147  toString (
150 
151  /// Appends timestamp text presentation in requested
152  /// format ("YYYYMMDD-HH:MM:SS.sssssssss" by default).
153  void
154  toString (
155  std::string& str,
158 
159  /// Returns the current UTC time.
160  ///
161  /// @note Timestamp resolution depends on
162  /// capabilities of an operating system.
163  static Timestamp utcNow();
164 
165  /// Returns the current local time.
166  ///
167  /// @note Timestamp resolution depends on
168  /// capabilities of an operating system.
169  static Timestamp now();
170 
171  /// Parses timestamp from its text presentation assuming it's in
172  /// specified format ("YYYYMMDD-HH:MM:SS.sssssssss" by default).
173  static
174  Timestamp
175  parse (
176  const std::string&,
179 
180  /// Parses timestamp from its numeric presentation
181  static
182  Timestamp
183  parse (
184  unsigned long long presentation,
185  TimestampFormat::Enum format);
186 
187  private:
188  Timestamp (long long totalSeconds, int subseconds);
189 
190  friend class TimeManager;
191  TimeSpan sinceEpoch_;
192  };
193 
194  inline
196  long long totalSeconds, int subseconds)
197  : sinceEpoch_(totalSeconds, subseconds)
198 
199  {
200  }
201 
202  inline
203  unsigned int
205  {
206  return sinceEpoch_.milliseconds();
207  }
208 
209  inline
210  unsigned int
212  {
213  return sinceEpoch_.microseconds();
214  }
215 
216  inline
217  unsigned int
219  {
220  return sinceEpoch_.nanoseconds();
221  }
222 
223  inline
224  const TimeSpan&
226  {
227  return sinceEpoch_;
228  }
229 
230  inline
231  std::string
233  TimestampFormat::Enum format) const
234  {
235  std::string str;
236 
237  toString (str, format);
238 
239  return str;
240  }
241 
242  inline
243  TimeSpan
245  const Timestamp& left,
246  const Timestamp& right)
247  {
248  TimeSpan res(left.sinceEpoch());
249  return res -= right.sinceEpoch();
250  }
251  }
252  }
253 }
254 
255 
256 
257 
258 
259 
260 
Indicates timestamp in "YYYYMMDD-HH:MM:SS.sss" format.
Definition: Timestamp.h:72
bool operator<(const Decimal &l, const Decimal &r)
Definition: Decimal.cpp:124
unsigned int millisecond() const
Definition: Timestamp.h:204
bool operator==(const FieldValueRef &ref, const std::string &str)
unsigned int microsecond() const
Definition: Timestamp.h:211
Defines all the months in the year.
Definition: Timestamp.h:31
Enum
Defines all the months in the year.
Definition: Timestamp.h:34
Year, month, day fields.
Definition: Timestamp.h:53
Definition: Defines.h:30
TimeSpan operator-(const Timestamp &left, const Timestamp &right)
Definition: Timestamp.h:244
Indicates timestamp in "YYYYMMDD" format.
Definition: Timestamp.h:66
std::string toString(TimestampFormat::Enum=TimestampFormat::YYYYMMDDHHMMSSNsec) const
Definition: Timestamp.h:232
unsigned int nanosecond() const
Definition: Timestamp.h:218
Collection of timestamp formats supported.
Definition: Timestamp.h:61
Represents timestamp without time-zone information.
Definition: Timestamp.h:80
Indicates timestamp in "YYYYMMDD-HH:MM:SS" format.
Definition: Timestamp.h:69
const TimeSpan & sinceEpoch() const
Time span since Jan 1, 0001, 00:00:00.
Definition: Timestamp.h:225
Indicates timestamp in "YYYYMMDD-HH:MM:SS.sssssssss" format.
Definition: Timestamp.h:75
bool operator!=(const FieldValueRef &ref, const std::string &str)
Timestamp()
Initializes as Jan 1, 0001, 00:00:00.
Definition: Timestamp.cpp:38