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