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