OnixS ICE iMpact Multicast Price Feed Handler C++ library 8.18.0
API documentation
Loading...
Searching...
No Matches
Time.h
Go to the documentation of this file.
1/*
2 * Copyright (c) Onix Solutions Limited. All rights reserved.
3 *
4 * This software owned by Onix Solutions Limited 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
22#include "Export.h"
23
24#include <iosfwd>
25#include <string>
26
27namespace OnixS { namespace ICE { namespace iMpact { namespace MarketData {
28
30struct ONIXS_ICEMDH_EXPORT TimeSpanFormats
31{
44};
45
48
52class ONIXS_ICEMDH_EXPORT TimeSpan
53{
54public:
57
64 TimeSpan(int hours, int minutes, int seconds, int nanoseconds = 0);
65
72 TimeSpan(int days, int hours, int minutes, int seconds, int nanoseconds);
73
77
79 TimeSpan(const TimeSpan& other);
80
82 long long totalSeconds() const;
83
86 int days() const;
87
90 int hours() const;
91
94 int minutes() const;
95
98 int seconds() const;
99
102 int milliseconds() const;
103
106 int microseconds() const;
107
110 int nanoseconds() const;
111
113 bool operator==(const TimeSpan& other) const;
114
116 bool operator!=(const TimeSpan& other) const;
117
119 bool operator<(const TimeSpan& other) const;
120
122 bool operator>(const TimeSpan& other) const;
123
126
129
132
135 void toString(std::string& str, TimeSpanFormat format = TimeSpanFormats::SDHHMMSSnsec) const;
136
139 std::string toString(TimeSpanFormat format = TimeSpanFormats::SDHHMMSSnsec) const;
140
142 static TimeSpan deserialize(const std::string& str);
143
145 static TimeSpan deserialize(unsigned long long presentation, TimeSpanFormat format);
146
148 static const TimeSpan Zero;
149
150private:
151 long long seconds_;
152 int nanoseconds_;
153};
154
155inline long long TimeSpan::totalSeconds() const
156{
157 return seconds_;
158}
159
160inline int TimeSpan::nanoseconds() const
161{
162 return nanoseconds_;
163}
164
165inline std::string TimeSpan::toString(TimeSpanFormat format) const
166{
167 std::string str;
168
169 toString(str, format);
170
171 return str;
172}
173
175ONIXS_ICEMDH_EXPORT std::ostream& operator<<(std::ostream&, const TimeSpan&);
176
178struct ONIXS_ICEMDH_EXPORT Months
179{
199
201 static Enum deserialize(const char*);
202
204 static const char* toString(Enum);
205};
206
209
211struct ONIXS_ICEMDH_EXPORT DaysOfWeek
212{
225
227 static Enum deserialize(const char*);
228
230 static const char* toString(Enum);
231};
232
235
239class ONIXS_ICEMDH_EXPORT YearMonth
240{
241public:
244
249 YearMonth(unsigned int year, Month month);
250
252 YearMonth(const YearMonth& other);
253
256 unsigned int year() const;
257
260 Month month() const;
261
263 bool operator==(const YearMonth&) const;
264
266 bool operator!=(const YearMonth&) const;
267
268 // Re-initializes instance as copy of other one.
270
272 std::string toString() const;
273
275 void toString(std::string&) const;
276
279 static YearMonth deserialize(unsigned long long);
280
281protected:
283 struct NoVerify
284 {
285 };
286
289 YearMonth(unsigned int, Month, const NoVerify&);
290
291private:
292 unsigned int year_;
293 Month month_;
294};
295
296inline unsigned int YearMonth::year() const
297{
298 return year_;
299}
300
302{
303 return month_;
304}
305
306inline std::string YearMonth::toString() const
307{
308 std::string str;
309
310 toString(str);
311
312 return str;
313}
314
316ONIXS_ICEMDH_EXPORT std::ostream& operator<<(std::ostream&, const YearMonth&);
317
319class ONIXS_ICEMDH_EXPORT Date : public YearMonth
320{
321public:
324
329 Date(unsigned int year, Month month, unsigned int day);
330
332 Date(const Date& other);
333
336 unsigned int day() const;
337
339 bool operator==(const Date& other) const;
340
342 bool operator!=(const Date& other) const;
343
345 bool operator<(const Date& other) const;
346
348 bool operator>(const Date& other) const;
349
352
355
357 Date& operator=(const Date& other);
358
360 std::string toString() const;
361
363 void toString(std::string&) const;
364
367 static Date deserialize(unsigned long long);
368
369private:
370 unsigned int day_;
371
373 Date(unsigned int year, Month month, unsigned int day, const NoVerify&);
374};
375
376inline unsigned int Date::day() const
377{
378 return day_;
379}
380
381inline std::string Date::toString() const
382{
383 std::string str;
384
385 toString(str);
386
387 return str;
388}
389
391ONIXS_ICEMDH_EXPORT TimeSpan operator-(const Date& left, const Date& right);
392
394ONIXS_ICEMDH_EXPORT std::ostream& operator<<(std::ostream&, const Date&);
395
397struct ONIXS_ICEMDH_EXPORT TimestampFormats
398{
410};
411
414
416class ONIXS_ICEMDH_EXPORT Timestamp
417{
418public:
421
427 Timestamp(unsigned year, Month month, unsigned day);
428
435 unsigned year,
436 Month month,
437 unsigned day,
438 unsigned hour,
439 unsigned minute,
440 unsigned second,
441 unsigned nanosecond
442 );
443
445 Timestamp(const Timestamp& other);
446
450
452 unsigned int year() const;
453
455 Month month() const;
456
458 unsigned int day() const;
459
461 unsigned int hour() const;
462
464 unsigned int minute() const;
465
467 unsigned int second() const;
468
470 unsigned int millisecond() const;
471
473 unsigned int microsecond() const;
474
476 unsigned int nanosecond() const;
477
480
482 void date(Date&) const;
483
485 TimeSpan time() const;
486
489
491 bool operator==(const Timestamp& other) const;
492
494 bool operator!=(const Timestamp& other) const;
495
497 bool operator<(const Timestamp& other) const;
498
500 bool operator>(const Timestamp& other) const;
501
504
507
510
513 static Timestamp now();
514
518
522
525 void toString(std::string& str, TimestampFormat format = TimestampFormats::YYYYMMDDHHMMSSnsec) const;
526
528 static Timestamp deserialize(const std::string&);
529
532 static Timestamp deserialize(unsigned long long presentation, TimestampFormat format);
533
534private:
535 friend ONIXS_ICEMDH_EXPORT TimeSpan operator-(const Timestamp& left, const Timestamp& right);
536
538 TimeSpan sinceEpoch_;
539};
540
541inline unsigned int Timestamp::hour() const
542{
543 return static_cast<unsigned int>(sinceEpoch_.hours());
544}
545
546inline unsigned int Timestamp::minute() const
547{
548 return static_cast<unsigned int>(sinceEpoch_.minutes());
549}
550
551inline unsigned int Timestamp::second() const
552{
553 return static_cast<unsigned int>(sinceEpoch_.seconds());
554}
555
556inline unsigned int Timestamp::millisecond() const
557{
558 return static_cast<unsigned int>(sinceEpoch_.milliseconds());
559}
560
561inline unsigned int Timestamp::microsecond() const
562{
563 return static_cast<unsigned int>(sinceEpoch_.microseconds());
564}
565
566inline unsigned int Timestamp::nanosecond() const
567{
568 return static_cast<unsigned int>(sinceEpoch_.nanoseconds());
569}
570
571inline std::string Timestamp::toString(TimestampFormat format) const
572{
573 std::string str;
574
575 toString(str, format);
576
577 return str;
578}
579
581ONIXS_ICEMDH_EXPORT TimeSpan operator-(const Timestamp& left, const Timestamp& right);
582
584ONIXS_ICEMDH_EXPORT std::ostream& operator<<(std::ostream&, const Timestamp&);
585
586}}}} // namespace OnixS::ICE::iMpact::MarketData
Represents date without time component.
Definition Time.h:320
std::string toString() const
Serializes date into YYYYMMDD presentation.
Definition Time.h:381
Date(unsigned int year, Month month, unsigned int day)
bool operator>(const Date &other) const
Checks whether given date is greater than other one.
Date & operator+=(TimeSpan &span)
Adds time interval to the date.
unsigned int day() const
Definition Time.h:376
Date(const Date &other)
Initializes as copy of other date.
void toString(std::string &) const
Serializes date into YYYYMMDD presentation.
Date & operator=(const Date &other)
Re-initializes instance as copy of other one.
Date & operator-=(TimeSpan &span)
Subtracts time interval from the date.
bool operator<(const Date &other) const
Checks whether given date is less than other one.
bool operator!=(const Date &other) const
Compares with other for inequality.
bool operator==(const Date &other) const
Compares with other for equality.
static Date deserialize(unsigned long long)
Date()
Initializes as Jan 1, 0001.
TimeSpan(int days, int hours, int minutes, int seconds, int nanoseconds)
static TimeSpan deserialize(unsigned long long presentation, TimeSpanFormat format)
De-serializes time-span from presentation as it's used by the ICE.
TimeSpan & operator=(const TimeSpan &other)
Re-assigns time interval from other one.
static TimeSpan deserialize(const std::string &str)
De-serializes time interval from its text presentation.
TimeSpan(const TimeSpan &other)
Initializes as clone of other instance.
bool operator<(const TimeSpan &other) const
Checks whether time interval less than other one.
long long totalSeconds() const
Whole number of seconds in time interval.
Definition Time.h:155
TimeSpan(long long totalSeconds, int nanoseconds)
TimeSpan & operator+=(const TimeSpan &other)
Adds time interval to current one.
bool operator==(const TimeSpan &other) const
Compares with other instance for equality.
static const TimeSpan Zero
Time interval of zero length.
Definition Time.h:148
void toString(std::string &str, TimeSpanFormat format=TimeSpanFormats::SDHHMMSSnsec) const
bool operator!=(const TimeSpan &other) const
Compares with other instance for in-equality.
TimeSpan & operator-=(const TimeSpan &other)
Subtracts time interval from current one.
TimeSpan(int hours, int minutes, int seconds, int nanoseconds=0)
bool operator>(const TimeSpan &other) const
Checks whether time interval greater than other one.
Represents timestamp without time-zone information.
Definition Time.h:417
Timestamp(unsigned year, Month month, unsigned day, unsigned hour, unsigned minute, unsigned second, unsigned nanosecond)
static Timestamp deserialize(unsigned long long presentation, TimestampFormat format)
Month month() const
Month component of timestamp.
Timestamp(const Timestamp &other)
Initializes as copy of other instance.
Timestamp()
Initializes as Jan 1, 0001, 00:00:00.
unsigned int hour() const
Hour component of timestamp.
Definition Time.h:541
unsigned int millisecond() const
Millisecond component of timestamp.
Definition Time.h:556
Timestamp(unsigned year, Month month, unsigned day)
bool operator<(const Timestamp &other) const
Checks whether timestamp is less than other one.
friend TimeSpan operator-(const Timestamp &left, const Timestamp &right)
Calculates time interval between two timestamps.
static Timestamp deserialize(const std::string &)
De-serializes timestamp from text presentation.
unsigned int day() const
Day component of timestamp.
DayOfWeek dayOfWeek() const
Returns day of the week.
Timestamp date() const
Returns timestamp without time part.
bool operator==(const Timestamp &other) const
Compares with other instance for equality.
TimeSpan time() const
Return time part of timestamp.
Timestamp & operator-=(const TimeSpan &span)
Subtracts time interval from given timestamp.
std::string toString(TimestampFormat format=TimestampFormats::YYYYMMDDHHMMSSnsec) const
Definition Time.h:571
void toString(std::string &str, TimestampFormat format=TimestampFormats::YYYYMMDDHHMMSSnsec) const
unsigned int nanosecond() const
Nanosecond component of timestamp.
Definition Time.h:566
Timestamp & operator=(const Timestamp &other)
Re-initializes as copy of other timestamp.
bool operator!=(const Timestamp &other) const
Compares with other instance for inequality.
Timestamp & operator+=(const TimeSpan &span)
Adds time interval to given timestamp.
unsigned int minute() const
Minute component of timestamp.
Definition Time.h:546
void date(Date &) const
Returns date component of timestamp.
unsigned int microsecond() const
Microsecond component of timestamp.
Definition Time.h:561
bool operator>(const Timestamp &other) const
Checks whether timestamp is greater than other one.
unsigned int second() const
Second component of timestamp.
Definition Time.h:551
unsigned int year() const
Year component of timestamp.
bool operator!=(const YearMonth &) const
Compares with other instance for inequality.
std::string toString() const
Serializes into text (YYYYMM) presentation.
Definition Time.h:306
YearMonth & operator=(const YearMonth &other)
bool operator==(const YearMonth &) const
Compares with other instance for equality.
void toString(std::string &) const
Serializes into text (YYYYMM) presentation.
YearMonth()
Initializes instance as Jan, 0001.
static YearMonth deserialize(unsigned long long)
YearMonth(unsigned int year, Month month)
YearMonth(unsigned int, Month, const NoVerify &)
YearMonth(const YearMonth &other)
Initializes as copy of other instance.
Months::Enum Month
Identifies months in year.
Definition Time.h:208
TimestampFormats::Enum TimestampFormat
Timestamp format.
Definition Time.h:413
DaysOfWeek::Enum DayOfWeek
Identifies day within week.
Definition Time.h:234
TimeSpan operator-(const Date &left, const Date &right)
Calculates time interval between two given dates.
std::ostream & operator<<(std::ostream &, const Error &)
Make it printable to formatted C++ I/O streams.
TimeSpanFormats::Enum TimeSpanFormat
Time span format.
Definition Time.h:47
Identifies day within week.
Definition Time.h:212
static Enum deserialize(const char *)
Deserializes value from text presentation.
static const char * toString(Enum)
Returns text presentation for given value.
Identifies months in year.
Definition Time.h:179
static Enum deserialize(const char *)
Deserializes value from text presentation.
static const char * toString(Enum)
Returns text presentation for given value.
Time span formats supported.
Definition Time.h:31
Enum
Time span formats supported.
Definition Time.h:34
Collection of timestamp formats supported.
Definition Time.h:398
@ YYYYMMDDHHMMSSmsec
YYYYMMDD-HH:MM:SS.sss.
Definition Time.h:405
@ YYYYMMDDHHMMSSnsec
YYYYMMDD-HH:MM:SS.sssssssss.
Definition Time.h:408