OnixS CME Drop Copy Handler C++ library 5.7.1
API documentation
Loading...
Searching...
No Matches
Time.h
Go to the documentation of this file.
1// Copyright Onix Solutions Limited [OnixS]. All rights reserved.
2//
3// This software owned by Onix Solutions Limited [OnixS] and is protected by copyright law
4// and international copyright treaties.
5//
6// Access to and use of the software is governed by the terms of the applicable OnixS Software
7// Services Agreement (the Agreement) and Customer end user license agreements granting
8// a non-assignable, non-transferable and non-exclusive license to use the software
9// for it's own data processing purposes under the terms defined in the Agreement.
10//
11// Except as otherwise granted within the terms of the Agreement, copying or reproduction of any
12// part of this source code or associated reference material to any other location for further
13// reproduction or redistribution, and any amendments to this copyright notice, are expressly
14// 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 "OnixS/CME/DropCopy/Export.h"
24
25#include <string>
26
27namespace OnixS { namespace CME { namespace DropCopy {
28
30struct ONIXS_CME_DROP_COPY_EXPORT TimeSpanFormats
31{
43};
44
47
49struct ONIXS_CME_DROP_COPY_EXPORT Subseconds
50{
51 enum Enum
52 {
55
58
61 };
62};
63
66
70class ONIXS_CME_DROP_COPY_EXPORT TimeSpan
71{
72public:
75
83
91
95
97 TimeSpan(const TimeSpan& other);
98
100 Int64 totalSeconds() const;
101
103 Int64 totalSubseconds(Subsecond subsecondType) const;
104
107 Int32 days() const;
108
111 Int32 hours() const;
112
115 Int32 minutes() const;
116
119 Int32 seconds() const;
120
124
128
131 Int32 nanoseconds() const;
132
134 bool operator==(const TimeSpan& other) const;
135
137 bool operator!=(const TimeSpan& other) const;
138
140 bool operator<(const TimeSpan& other) const;
141
143 bool operator>(const TimeSpan& other) const;
144
147
150
153
156 void toString(std::string& str, TimeSpanFormat format = TimeSpanFormats::SDHHMMSSnsec) const;
157
160 std::string toString(TimeSpanFormat format = TimeSpanFormats::SDHHMMSSnsec) const;
161
163 static TimeSpan deserialize(const std::string& str);
164
166 static const TimeSpan Zero;
167
168private:
169 Int64 seconds_;
170 Int32 nanoseconds_;
171};
172
174{
175 return seconds_;
176}
177
179{
180 return nanoseconds_;
181}
182
183inline std::string TimeSpan::toString(TimeSpanFormat format) const
184{
185 std::string str;
186 toString(str, format);
187 return str;
188}
189
191struct ONIXS_CME_DROP_COPY_EXPORT Months
192{
212
214 static Enum deserialize(const char*);
215
217 static const char* toString(Enum);
218};
219
222
224struct ONIXS_CME_DROP_COPY_EXPORT DaysOfWeek
225{
238
240 static Enum deserialize(const char*);
241
243 static const char* toString(Enum);
244};
245
248
250struct ONIXS_CME_DROP_COPY_EXPORT WeekCodes
251{
263
265 static Enum deserialize(const char*);
266
268 static const char* toString(Enum);
269};
270
273
277class ONIXS_CME_DROP_COPY_EXPORT YearMonth
278{
279public:
282
289
296
303
305 YearMonth(const YearMonth& other);
306
309 UInt32 year() const
310 {
311 return year_;
312 }
313
316 Month month() const
317 {
318 return month_;
319 }
320
323 UInt32 day() const
324 {
325 return day_;
326 }
327
331 {
332 return week_;
333 }
334
337 bool hasDay() const
338 {
339 return day_ != 0;
340 }
341
344 bool hasWeek() const
345 {
346 return week_ != WeekCodes::Invalid;
347 }
348
350 bool operator==(const YearMonth&) const;
351
353 bool operator!=(const YearMonth&) const;
354
359 bool operator<(const YearMonth& other) const;
360
365 bool operator>(const YearMonth& other) const;
366
367 // Re-initializes instance as copy of other one.
369
371 std::string toString() const;
372
374 void toString(std::string&) const;
375
379
380private:
381 // Year component.
382 UInt32 year_;
383
384 // Month component.
385 Month month_;
386
387 // Day component.
388 UInt32 day_;
389
390 // Week component.
391 WeekCode week_;
392};
393
394inline std::string YearMonth::toString() const
395{
396 std::string str;
397 toString(str);
398 return str;
399}
400
402struct ONIXS_CME_DROP_COPY_EXPORT TimestampFormats
403{
418};
419
422
424struct ONIXS_CME_DROP_COPY_EXPORT SinceEpochUnits
425{
426 enum Enum
427 {
430 };
431};
432
435
437class ONIXS_CME_DROP_COPY_EXPORT Timestamp
438{
439public:
442
449
456 UInt32 year,
457 Month month,
458 UInt32 day,
459 UInt32 hour,
463 );
464
466 Timestamp(const Timestamp& other);
467
469 UInt32 year() const;
470
472 Month month() const;
473
475 UInt32 day() const;
476
478 UInt32 hour() const;
479
481 UInt32 minute() const;
482
484 UInt32 second() const;
485
488
491
494
497
499 TimeSpan time() const;
500
503
505 bool operator==(const Timestamp& other) const;
506
508 bool operator!=(const Timestamp& other) const;
509
511 bool operator<(const Timestamp& other) const;
512
514 bool operator>(const Timestamp& other) const;
515
518
521
524
527 static Timestamp now();
528
531 static void now(Timestamp&);
532
536
539 static void utcNow(Timestamp&);
540
544
547 void
549
552
557
562
565
566private:
567 friend ONIXS_CME_DROP_COPY_EXPORT TimeSpan
568 operator-(const Timestamp& left, const Timestamp& right);
569
573
576 UInt64 sinceEpoch_;
577};
578
579inline std::string Timestamp::toString(TimestampFormat format) const
580{
581 std::string str;
582 toString(str, format);
583 return str;
584}
585
587ONIXS_CME_DROP_COPY_EXPORT TimeSpan operator-(const Timestamp& left, const Timestamp& right);
588
589}}}
Provides efficient way of accessing text-based FIX field values.
Definition String.h:324
TimeSpan()
Initializes zero span.
TimeSpan(Int32 hours, Int32 minutes, Int32 seconds, Int32 nanoseconds=0)
TimeSpan & operator=(const TimeSpan &other)
Re-assigns time interval from other one.
Int64 totalSeconds() const
Whole number of seconds in time interval.
Definition Time.h:173
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.
TimeSpan & operator+=(const TimeSpan &other)
Adds time interval to current one.
bool operator==(const TimeSpan &other) const
Compares with other instance for equality.
Int32 nanoseconds() const
Definition Time.h:178
static const TimeSpan Zero
Time interval of zero length.
Definition Time.h:166
Int64 totalSubseconds(Subsecond subsecondType) const
Whole number of subseconds in time interval.
void toString(std::string &str, TimeSpanFormat format=TimeSpanFormats::SDHHMMSSnsec) const
TimeSpan(Int32 days, Int32 hours, Int32 minutes, Int32 seconds, Int32 nanoseconds)
TimeSpan(Int64 totalSeconds, Int32 nanoseconds)
bool operator!=(const TimeSpan &other) const
Compares with other instance for in-equality.
TimeSpan & operator-=(const TimeSpan &other)
Subtracts time interval from current one.
bool operator>(const TimeSpan &other) const
Checks whether time interval greater than other one.
Represents timestamp without time-zone information.
Definition Time.h:438
Timestamp(UInt32 year, Month month, UInt32 day, UInt32 hour, UInt32 minute, UInt32 second, UInt32 nanosecond)
UInt32 minute() const
Minute component of timestamp.
UInt64 toUnixTimestamp(SinceEpochUnit unit) const
Month month() const
Month component of timestamp.
UInt32 day() const
Day component of timestamp.
UInt32 second() const
Second component of timestamp.
Timestamp(const Timestamp &other)
Initializes as copy of other instance.
static Timestamp deserialize(const StringRef &)
De-serializes timestamp from text presentation.
Timestamp()
Initializes as Jan 1, 1970, 00:00:00.
static void utcNow(Timestamp &)
static Timestamp maxTimestamp()
Returns the maximal possible timestamp (year 2554)
static void now(Timestamp &)
static Timestamp fromUnixTimestamp(UInt64 sinceEpoch, SinceEpochUnit unit)
UInt32 hour() const
Hour component of timestamp.
UInt32 millisecond() const
Millisecond component of timestamp.
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.
UInt32 nanosecond() const
Nanosecond component of timestamp.
DayOfWeek dayOfWeek() const
Returns day of the week.
Timestamp date() const
Returns timestamp without time part.
UInt32 microsecond() const
Microsecond component of timestamp.
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:579
void toString(std::string &str, TimestampFormat format=TimestampFormats::YYYYMMDDHHMMSSnsec) const
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.
bool operator>(const Timestamp &other) const
Checks whether timestamp is greater than other one.
UInt32 year() const
Year component of timestamp.
Timestamp(UInt32 year, Month month, UInt32 day)
bool operator!=(const YearMonth &) const
Compares with other instance for inequality.
std::string toString() const
Serializes into text (YYYYMM/YYYYMMDD/YYYYMMWW) presentation.
Definition Time.h:394
YearMonth & operator=(const YearMonth &other)
YearMonth(UInt32 year, Month month)
YearMonth(UInt32 year, Month month, WeekCode week)
static YearMonth deserialize(const StringRef &)
bool operator==(const YearMonth &) const
Compares with other instance for equality.
YearMonth(UInt32 year, Month month, UInt32 day)
void toString(std::string &) const
Serializes into text (YYYYMM/YYYYMMDD/YYYYMMWW) presentation.
YearMonth()
Initializes instance as Jan, 0001.
WeekCode week() const
Definition Time.h:330
YearMonth(const YearMonth &other)
Initializes as copy of other instance.
bool operator<(const YearMonth &other) const
bool operator>(const YearMonth &other) const
Months::Enum Month
Identifies months in year.
Definition Time.h:221
SinceEpochUnits::Enum SinceEpochUnit
Since epoch units format.
Definition Time.h:434
unsigned int UInt32
Definition Numeric.h:33
long long Int64
Definition Numeric.h:35
TimeSpan operator-(const Timestamp &left, const Timestamp &right)
Calculates time interval between two timestamps.
TimestampFormats::Enum TimestampFormat
Timestamp format.
Definition Time.h:421
Subseconds::Enum Subsecond
Time span format.
Definition Time.h:65
DaysOfWeek::Enum DayOfWeek
Identifies days in week.
Definition Time.h:247
unsigned long long UInt64
Definition Numeric.h:36
TimeSpanFormats::Enum TimeSpanFormat
Time span format.
Definition Time.h:46
WeekCodes::Enum WeekCode
Identifies week number within month.
Definition Time.h:272
Identifies day within week.
Definition Time.h:225
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:192
static Enum deserialize(const char *)
Deserializes value from text presentation.
static const char * toString(Enum)
Returns text presentation for given value.
Since epoch time units supported.
Definition Time.h:425
Subseconds formats supported.
Definition Time.h:50
Time span formats supported.
Definition Time.h:31
@ SDHHMMSSnsec
HH:MM:SS.sssssssss.
Definition Time.h:41
Collection of timestamp formats supported.
Definition Time.h:403
@ YYYYMMDDHHMMSSmsec
YYYYMMDD-HH:MM:SS.sss.
Definition Time.h:413
@ YYYYMMDDHHMMSS
YYYYMMDD-HH:MM:SS.
Definition Time.h:410
@ YYYYMMDDHHMMSSnsec
YYYYMMDD-HH:MM:SS.sssssssss.
Definition Time.h:416
Identifies week number within month.
Definition Time.h:251
static Enum deserialize(const char *)
Deserializes value from text presentation.
static const char * toString(Enum)
Returns text presentation for given value.