OnixS BME SENAF Handler C++ library 2.3.0
API documentation
Loading...
Searching...
No Matches
Time.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
5 * copyright law and international copyright treaties.
6 *
7 * Access to and use of the software is governed by the terms of the applicable
8 * ONIXS Software Services Agreement (the Agreement) and Customer end user
9 * license agreements granting a non-assignable, non-transferable and
10 * non-exclusive license to use the software for it's own data processing
11 * purposes under the terms defined in the Agreement.
12 *
13 * Except as otherwise granted within the terms of the Agreement, copying or
14 * reproduction of any part of this source code or associated reference material
15 * to any other location for further reproduction or redistribution, and any
16 * amendments to this copyright notice, are expressly prohibited.
17 *
18 * Any reproduction or redistribution for sale or hiring of the Software not in
19 * accordance with the terms of the Agreement is a violation of copyright law.
20 */
21
22#pragma once
23
24#include <OnixS/Senaf/MarketData/Export.h>
25
26#include <string>
27
28namespace OnixS { namespace Senaf { namespace MarketData {
29
31struct ONIXS_BME_SENAF_EXPORT TimeSpanFormats
32{
45};
46
49
53class ONIXS_BME_SENAF_EXPORT TimeSpan
54{
55public:
58
65 TimeSpan(int hours, int minutes, int seconds, int nanoseconds = 0);
66
73 TimeSpan(int days, int hours, int minutes, int seconds, int nanoseconds);
74
78
80 TimeSpan(const TimeSpan& other);
81
83 long long totalSeconds() const;
84
87 int days() const;
88
91 int hours() const;
92
95 int minutes() const;
96
99 int seconds() const;
100
103 int milliseconds() const;
104
107 int microseconds() const;
108
111 int nanoseconds() const;
112
114 bool operator==(const TimeSpan& other) const;
115
117 bool operator!=(const TimeSpan& other) const;
118
120 bool operator<(const TimeSpan& other) const;
121
123 bool operator>(const TimeSpan& other) const;
124
127
130
133
136 void toString(std::string& str, TimeSpanFormat format = TimeSpanFormats::SDHHMMSSnsec) const;
137
140 std::string toString(TimeSpanFormat format = TimeSpanFormats::SDHHMMSSnsec) const;
141
143 static TimeSpan deserialize(const std::string& str);
144
146 static TimeSpan deserialize(unsigned long long presentation, TimeSpanFormat format);
147
149 static const TimeSpan Zero;
150
151private:
152 long long seconds_;
153 int nanoseconds_;
154};
155
156inline long long TimeSpan::totalSeconds() const
157{
158 return seconds_;
159}
160
161inline int TimeSpan::nanoseconds() const
162{
163 return nanoseconds_;
164}
165
166inline std::string TimeSpan::toString(TimeSpanFormat format) const
167{
168 std::string str;
169
170 toString(str, format);
171
172 return str;
173}
174
176struct ONIXS_BME_SENAF_EXPORT Months
177{
197
199 static Enum deserialize(const char*);
200
202 static const char* toString(Enum);
203};
204
207
209struct ONIXS_BME_SENAF_EXPORT DaysOfWeek
210{
223
225 static Enum deserialize(const char*);
226
228 static const char* toString(Enum);
229};
230
233
237class ONIXS_BME_SENAF_EXPORT YearMonth
238{
239public:
242
247 YearMonth(unsigned int year, Month month);
248
250 YearMonth(const YearMonth& other);
251
254 unsigned int year() const;
255
258 Month month() const;
259
261 bool operator==(const YearMonth&) const;
262
264 bool operator!=(const YearMonth&) const;
265
266 // Re-initializes instance as copy of other one.
268
270 std::string toString() const;
271
273 void toString(std::string&) const;
274
277 static YearMonth deserialize(unsigned long long);
278
279protected:
281 struct NoVerify
282 {
283 };
284
287 YearMonth(unsigned int, Month, const NoVerify&);
288
289private:
290 unsigned int year_;
291 Month month_;
292};
293
294inline unsigned int YearMonth::year() const
295{
296 return year_;
297}
298
300{
301 return month_;
302}
303
304inline std::string YearMonth::toString() const
305{
306 std::string str;
307
308 toString(str);
309
310 return str;
311}
312
314class ONIXS_BME_SENAF_EXPORT Date : public YearMonth
315{
316public:
319
324 Date(unsigned int year, Month month, unsigned int day);
325
327 Date(const Date& other);
328
331 unsigned int day() const;
332
334 bool operator==(const Date& other) const;
335
337 bool operator!=(const Date& other) const;
338
340 bool operator<(const Date& other) const;
341
343 bool operator>(const Date& other) const;
344
347
350
352 Date& operator=(const Date& other);
353
355 std::string toString() const;
356
358 void toString(std::string&) const;
359
362 static Date deserialize(unsigned long long);
363
364private:
365 unsigned int day_;
366
368 Date(unsigned int year, Month month, unsigned int day, const NoVerify&);
369};
370
371inline unsigned int Date::day() const
372{
373 return day_;
374}
375
376inline std::string Date::toString() const
377{
378 std::string str;
379
380 toString(str);
381
382 return str;
383}
384
386ONIXS_BME_SENAF_EXPORT TimeSpan operator-(const Date& left, const Date& right);
387
389struct ONIXS_BME_SENAF_EXPORT TimestampFormats
390{
402};
403
406
408class ONIXS_BME_SENAF_EXPORT Timestamp
409{
410public:
413
419 Timestamp(unsigned year, Month month, unsigned day);
420
427 unsigned year,
428 Month month,
429 unsigned day,
430 unsigned hour,
431 unsigned minute,
432 unsigned second,
433 unsigned nanosecond
434 );
435
437 Timestamp(const Timestamp& other);
438
442
444 unsigned int year() const;
445
447 Month month() const;
448
450 unsigned int day() const;
451
453 unsigned int hour() const;
454
456 unsigned int minute() const;
457
459 unsigned int second() const;
460
462 unsigned int millisecond() const;
463
465 unsigned int microsecond() const;
466
468 unsigned int nanosecond() const;
469
472
474 void date(Date&) const;
475
477 TimeSpan time() const;
478
481
483 bool operator==(const Timestamp& other) const;
484
486 bool operator!=(const Timestamp& other) const;
487
489 bool operator<(const Timestamp& other) const;
490
492 bool operator>(const Timestamp& other) const;
493
496
499
502
505 static Timestamp now();
506
510
514
517 void toString(std::string& str, TimestampFormat format = TimestampFormats::YYYYMMDDHHMMSSnsec) const;
518
520 static Timestamp deserialize(const std::string&);
521
524 static Timestamp deserialize(unsigned long long presentation, TimestampFormat format);
525
526private:
527 friend ONIXS_BME_SENAF_EXPORT TimeSpan operator-(const Timestamp& left, const Timestamp& right);
528
530 TimeSpan sinceEpoch_;
531};
532
533inline unsigned int Timestamp::hour() const
534{
535 return static_cast<unsigned int>(sinceEpoch_.hours());
536}
537
538inline unsigned int Timestamp::minute() const
539{
540 return static_cast<unsigned int>(sinceEpoch_.minutes());
541}
542
543inline unsigned int Timestamp::second() const
544{
545 return static_cast<unsigned int>(sinceEpoch_.seconds());
546}
547
548inline unsigned int Timestamp::millisecond() const
549{
550 return static_cast<unsigned int>(sinceEpoch_.milliseconds());
551}
552
553inline unsigned int Timestamp::microsecond() const
554{
555 return static_cast<unsigned int>(sinceEpoch_.microseconds());
556}
557
558inline unsigned int Timestamp::nanosecond() const
559{
560 return static_cast<unsigned int>(sinceEpoch_.nanoseconds());
561}
562
563inline std::string Timestamp::toString(TimestampFormat format) const
564{
565 std::string str;
566
567 toString(str, format);
568
569 return str;
570}
571
573ONIXS_BME_SENAF_EXPORT TimeSpan operator-(const Timestamp& left, const Timestamp& right);
574
575}}} // namespace OnixS::Senaf::MarketData
Represents date without time component.
Definition Time.h:315
std::string toString() const
Serializes date into YYYYMMDD presentation.
Definition Time.h:376
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:371
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 Senaf.
TimeSpan()
Initializes zero span.
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:156
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:149
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:409
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:533
unsigned int millisecond() const
Millisecond component of timestamp.
Definition Time.h:548
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:563
void toString(std::string &str, TimestampFormat format=TimestampFormats::YYYYMMDDHHMMSSnsec) const
unsigned int nanosecond() const
Nanosecond component of timestamp.
Definition Time.h:558
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:538
void date(Date &) const
Returns date component of timestamp.
unsigned int microsecond() const
Microsecond component of timestamp.
Definition Time.h:553
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:543
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:304
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.
unsigned int year() const
Definition Time.h:294
Months::Enum Month
Identifies months in year.
Definition Time.h:206
TimestampFormats::Enum TimestampFormat
Timestamp format.
Definition Time.h:405
DaysOfWeek::Enum DayOfWeek
Identifies day within week.
Definition Time.h:232
TimeSpan operator-(const Date &left, const Date &right)
Calculates time interval between two given dates.
TimeSpanFormats::Enum TimeSpanFormat
Time span format.
Definition Time.h:48
Identifies day within week.
Definition Time.h:210
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:177
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:32
Enum
Time span formats supported.
Definition Time.h:35
@ SDHHMMSSnsec
HH:MM:SS.sssssssss.
Definition Time.h:43
Collection of timestamp formats supported.
Definition Time.h:390
@ YYYYMMDDHHMMSSmsec
YYYYMMDD-HH:MM:SS.sss.
Definition Time.h:397
@ YYYYMMDDHHMMSSnsec
YYYYMMDD-HH:MM:SS.sssssssss.
Definition Time.h:400