OnixS C++ FIX Engine 4.13.0
API Documentation
Loading...
Searching...
No Matches
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
22#include <string>
23
24#include <OnixS/FIXEngine/ABI.h>
26
27namespace OnixS {
28namespace FIX {
29typedef Amount Year;
30typedef Amount Day;
31
32typedef Amount Hour;
33typedef Amount Minute;
34typedef Amount Second;
35
40
59
66
89
92{
93public:
96
99 TotalSeconds seconds,
101
103 Timestamp(
104 TotalSeconds seconds,
106
110 Hour hour = 0, Minute minute = 0, Second second = 0,
112
118
120 explicit Timestamp(TotalNanoseconds unixTimestampNanoseconds);
121
123 Year year() const;
124
127
130 Day day() const;
131
133 void date(YearMonthDay &) const;
134
137 Hour hour() const;
138
141 Minute minute() const;
142
145 Second second() const;
146
149 Millisecond millisecond() const;
150
153 Microsecond microsecond() const;
154
157 Nanosecond nanosecond() const;
158
161 Picosecond picosecond() const;
162
165
167 bool operator == (const Timestamp &) const;
168
170 bool operator != (const Timestamp &) const;
171
173 bool operator < (const Timestamp &) const;
174
176 Timestamp & operator += (const TimeSpan &);
177
179 Timestamp & operator -= (const TimeSpan &);
180
182 TimeSpan operator - (const Timestamp &);
183
186 std::string
187 toString(
190
193 void
195 std::string & str,
198
201
206 static Timestamp utc();
207
212 static Timestamp local();
213
216 static
219 const std::string &,
222
223private:
224 friend class TimeManager;
225
226 TotalSeconds totalSeconds_;
227 Picosecond picoseconds_;
228};
229
230inline
233 : totalSeconds_(totalSeconds),
234 picoseconds_(subseconds * static_cast<Picosecond>(TimeDetails::PicosecondsPerNanosecond))
235{
236}
237
238inline
241 : totalSeconds_(totalSeconds),
242 picoseconds_(subseconds)
243{
244}
245
246inline
249{
250 return totalSeconds_;
251}
252
253inline
256{
257 return static_cast<Millisecond>(picoseconds_ / TimeDetails::PicosecondsPerMillisecond);
258}
259
260inline
263{
264 return static_cast<Microsecond>(picoseconds_ / TimeDetails::PicosecondsPerMicrosecond);
265}
266
267inline
270{
271 return static_cast<Nanosecond>(picoseconds_ / TimeDetails::PicosecondsPerNanosecond);
272}
273
274inline
277{
278 return picoseconds_;
279}
280
281inline
282std::string
284 TimestampFormat::Enum format) const
285{
286 std::string str;
287
288 toString(str, format);
289
290 return str;
291}
292}
293}
#define ONIXS_FIXENGINE_API
Definition ABI.h:45
The time span related functionality.
Definition TimeSpan.h:94
Microsecond microsecond() const
The current microsecond.
Definition Timestamp.h:262
static Timestamp parse(const std::string &, TimestampFormat::Enum=TimestampFormat::YYYYMMDDHHMMSSNsec)
Parses the timestamp from its text presentation assuming it's in the specified format ("YYYYMMDD-HH:M...
static Timestamp local()
Returns the current local time.
Year year() const
The current year.
Timestamp(Year year, Month::Enum month, Day day, Hour hour=0, Minute minute=0, Second second=0, Nanosecond nanosecond=0)
Initializes date-time from all details.
TotalNanoseconds toUnixNanosecondTimestamp() const
Returns the nanosecond timestamp since the Unix epoch.
Day day() const
The current day of month.
Timestamp(Year year, Month::Enum month, Day day, Hour hour, Minute minute, Second second, Picosecond picosecond)
Initializes date-time from all details.
Timestamp()
Constructs an uninitialized instance.
friend class TimeManager
Definition Timestamp.h:224
Minute minute() const
The current minute.
Hour hour() const
The current hour.
void date(YearMonthDay &) const
Returns the date part of the timestamp.
void toString(std::string &str, TimestampFormat::Enum=TimestampFormat::YYYYMMDDHHMMSSNsec) const
Appends the timestamp text presentation in the requested format ("YYYYMMDD-HH:MM:SS....
Nanosecond nanosecond() const
The current nanosecond.
Definition Timestamp.h:269
Second second() const
The current second.
std::string toString(TimestampFormat::Enum=TimestampFormat::YYYYMMDDHHMMSSNsec) const
Returns the timestamp text presentation in the requested format ("YYYYMMDD-HH:MM:SS....
Definition Timestamp.h:283
TotalSeconds totalSeconds() const
The total number of seconds since Jan 1, 0001, 00:00:00.
Definition Timestamp.h:248
Timestamp(TotalNanoseconds unixTimestampNanoseconds)
Initializes from nanoseconds since Jan 1, 1970, 00:00:00 (Unix epoch).
Millisecond millisecond() const
The current millisecond.
Definition Timestamp.h:255
Month::Enum month() const
The current month.
static Timestamp utc()
Returns the current UTC time.
Picosecond picosecond() const
The current picosecond.
Definition Timestamp.h:276
HugeAmount Picosecond
Definition Timestamp.h:39
UInt64 HugeAmount
Definition TimeSpan.h:32
HugeInterval TotalNanoseconds
Definition TimeSpan.h:50
UInt32 Amount
Definition TimeSpan.h:31
Amount Millisecond
Definition Timestamp.h:36
Amount Day
Definition Timestamp.h:30
Amount Microsecond
Definition Timestamp.h:37
Amount Second
Definition Timestamp.h:34
Amount Year
Definition Timestamp.h:29
Amount Nanosecond
Definition Timestamp.h:38
Amount Minute
Definition Timestamp.h:33
Amount Hour
Definition Timestamp.h:32
HugeInterval TotalSeconds
Definition TimeSpan.h:47
Defines all the months in the year.
Definition Timestamp.h:42
Time related constants.
Definition TimeSpan.h:54
static const Picoseconds PicosecondsPerMicrosecond
Definition TimeSpan.h:67
static const Picoseconds PicosecondsPerNanosecond
Definition TimeSpan.h:66
static const Picoseconds PicosecondsPerMillisecond
Definition TimeSpan.h:68
The collection of timestamp formats supported.
Definition Timestamp.h:68
@ YYYYMMDDHHMMSSPsec
Indicates the timestamp in the "YYYYMMDD-HH:MM:SS.ssssssssssss" format.
Definition Timestamp.h:86
@ YYYYMMDDHHMMSS
Indicates the timestamp in the "YYYYMMDD-HH:MM:SS" format.
Definition Timestamp.h:74
@ YYYYMMDDHHMMSSMsec
Indicates the timestamp in the "YYYYMMDD-HH:MM:SS.sss" format.
Definition Timestamp.h:77
@ YYYYMMDDHHMMSSUsec
Indicates the timestamp in the "YYYYMMDD-HH:MM:SS.ssssss" format.
Definition Timestamp.h:80
@ YYYYMMDD
Indicates the timestamp in the "YYYYMMDD" format.
Definition Timestamp.h:71
@ YYYYMMDDHHMMSSNsec
Indicates the timestamp in the "YYYYMMDD-HH:MM:SS.sssssssss" format.
Definition Timestamp.h:83
Year, month, day fields.
Definition Timestamp.h:61