Public Member Functions | Static Public Member Functions | Public Attributes | Static Public Attributes | List of all members
FIX::DateTime Struct Reference

#include <FieldTypes.h>

Inheritance diagram for FIX::DateTime:
Inheritance graph
[legend]

Public Member Functions

 DateTime ()
 Default constructor - initializes to zero.
 
 DateTime (int date, int64_t time)
 Construct from a Julian day number and time in millis.
 
 DateTime (int year, int month, int day, int hour, int minute, int second, int millis)
 Construct from the specified components.
 
 DateTime (int year, int month, int day, int hour, int minute, int second, int fraction, int precision)
 Construct from the specified components.
 
virtual ~DateTime ()
 
int getYear () const
 Return the year portion of the date.
 
int getMonth () const
 Return the month (1-12) portion of the date.
 
int getDay () const
 Return the day of the month portion of the date.
 
int getDate () const
 Another name for the day of the month.
 
int getJulianDate () const
 Return the internal julian date.
 
int getHour () const
 Return the hour portion of the time (0-23)
 
int getMinute () const
 Return the minute portion of the time (0-59)
 
int getSecond () const
 Return the second portion of the time (0-59)
 
int getMillisecond () const
 Return the millisecond portion of the time (0-999)
 
int getMicroecond () const
 Return the microsecond portion of the time.
 
unsigned int getNanosecond () const
 Return the nanosecond portion of the time.
 
int getFraction (int precision) const
 Return the fraction portion of the time.
 
void getYMD (int &year, int &month, int &day) const
 Load the referenced values with the year, month and day portions of the date in a single operation.
 
void getHMS (int &hour, int &minute, int &second, int &millis) const
 Load the referenced values with the hour, minute, second and millisecond portions of the time in a single operation.
 
void getHMS (int &hour, int &minute, int &second, int &fraction, int precision) const
 Load the referenced values with the hour, minute, second and fraction portions of the time in a single operation.
 
int getWeekDay () const
 Calculate the weekday of the date (Sunday is 1, Saturday is 7)
 
time_t getTimeT () const
 Convert the DateTime to a time_t.
 
tm getTmUtc () const
 Convert the DateTime to a struct tm which is in UTC.
 
void setYMD (int year, int month, int day)
 Set the date portion of the DateTime.
 
void setHMS (int hour, int minute, int second, int millis)
 Set the time portion of the DateTime.
 
void setHMS (int hour, int minute, int second, int fraction, int precision)
 Set the time portion of the DateTime.
 
void setHour (int hour)
 Set the hour portion of the time.
 
void setMinute (int min)
 Set the minute portion of the time.
 
void setSecond (int sec)
 Set the seconds portion of the time.
 
void setMillisecond (int millis)
 Set the millisecond portion of the time.
 
void setMicrosecond (int micros)
 Set the microsecond portion of the time.
 
void setNanosecond (int nanos)
 Set the nanosecond portion of the time.
 
void setFraction (int fraction, int precision)
 Set the fraction portion of the time.
 
void clearDate ()
 Clear the date portion of the DateTime.
 
void clearTime ()
 Clear the time portion of the DateTime.
 
void set (int date, int64_t time)
 Set the internal date and time members.
 
void set (const DateTime &other)
 Initialize from another DateTime.
 
void operator+= (int seconds)
 Add a number of seconds to this.
 

Static Public Member Functions

static int convertToNanos (int fraction, int precision)
 Convert to internal nanos.
 
static int64_t makeHMS (int hour, int minute, int second, int nanos)
 Helper method to convert a broken down time to a number of nanoseconds since midnight.
 
static DateTime nowUtc ()
 Return the current wall-clock time as a utc DateTime.
 
static DateTime nowLocal ()
 Return the current wall-clock time as a local DateTime.
 
static DateTime fromUtcTimeT (time_t t, int millis=0)
 Convert a time_t and optional milliseconds to a DateTime.
 
static DateTime fromLocalTimeT (time_t t, int millis=0)
 
static DateTime fromUtcTimeT (time_t t, int fraction, int precision)
 
static DateTime fromLocalTimeT (time_t t, int fraction, int precision)
 
static DateTime fromTm (const tm &tm, int millis=0)
 Convert a tm and optional milliseconds to a DateTime.
 
static DateTime fromTm (const tm &tm, int fraction, int precision)
 Convert a tm and optional milliseconds to a DateTime.
 
static int julianDate (int year, int month, int day)
 Helper method to calculate a Julian day number.
 
static void getYMD (int jday, int &year, int &month, int &day)
 Convert a Julian day number to a year, month and day.
 

Public Attributes

int m_date
 
int64_t m_time
 

Static Public Attributes

static const int64_t SECONDS_PER_DAY = 86400
 Magic numbers.
 
static const int64_t SECONDS_PER_HOUR = 3600
 
static const int64_t SECONDS_PER_MIN = 60
 
static const int64_t MINUTES_PER_HOUR = 60
 
static const int64_t NANOS_PER_DAY = 86400000000000
 
static const int64_t NANOS_PER_HOUR = 3600000000000
 
static const int64_t NANOS_PER_MIN = 60000000000
 
static const int64_t NANOS_PER_SEC = 1000000000
 
static const int64_t JULIAN_19700101 = 2440588
 

Detailed Description

Definition at line 60 of file FieldTypes.h.

Constructor & Destructor Documentation

◆ DateTime() [1/4]

FIX::DateTime::DateTime ( )
inline

Default constructor - initializes to zero.

Definition at line 80 of file FieldTypes.h.

80: m_date (0), m_time (0) {}
int64_t m_time
Definition FieldTypes.h:63

Referenced by fromTm(), and fromTm().

◆ DateTime() [2/4]

FIX::DateTime::DateTime ( int  date,
int64_t  time 
)
inline

Construct from a Julian day number and time in millis.

Definition at line 83 of file FieldTypes.h.

83: m_date (date), m_time (time) {}
void set(int date, int64_t time)
Set the internal date and time members.
Definition FieldTypes.h:370

◆ DateTime() [3/4]

FIX::DateTime::DateTime ( int  year,
int  month,
int  day,
int  hour,
int  minute,
int  second,
int  millis 
)
inline

Construct from the specified components.

Definition at line 86 of file FieldTypes.h.

88 {
91 }
static const int PRECISION_FACTOR[10]
Date and Time stored as a Julian day number and number of nanoseconds since midnight.
Definition FieldTypes.h:58
static int64_t makeHMS(int hour, int minute, int second, int nanos)
Helper method to convert a broken down time to a number of nanoseconds since midnight.
Definition FieldTypes.h:454
static int julianDate(int year, int month, int day)
Helper method to calculate a Julian day number.
Definition FieldTypes.h:512

References julianDate(), m_date, m_time, makeHMS(), FIX::PRECISION_FACTOR, and set().

◆ DateTime() [4/4]

FIX::DateTime::DateTime ( int  year,
int  month,
int  day,
int  hour,
int  minute,
int  second,
int  fraction,
int  precision 
)
inline

Construct from the specified components.

Definition at line 94 of file FieldTypes.h.

96 {
100 }
static int convertToNanos(int fraction, int precision)
Convert to internal nanos.
Definition FieldTypes.h:401

References convertToNanos(), julianDate(), m_date, m_time, makeHMS(), and set().

◆ ~DateTime()

virtual FIX::DateTime::~DateTime ( )
inlinevirtual

Definition at line 102 of file FieldTypes.h.

102{}

Member Function Documentation

◆ clearDate()

void FIX::DateTime::clearDate ( )
inline

◆ clearTime()

void FIX::DateTime::clearTime ( )
inline

Clear the time portion of the DateTime.

Definition at line 364 of file FieldTypes.h.

365 {
366 m_time = 0;
367 }

References m_time.

Referenced by FIX::LocalDate::LocalDate(), FIX::LocalDate::LocalDate(), FIX::UtcDate::UtcDate(), and FIX::UtcDate::UtcDate().

◆ convertToNanos()

static int FIX::DateTime::convertToNanos ( int  fraction,
int  precision 
)
inlinestatic

Convert to internal nanos.

Definition at line 401 of file FieldTypes.h.

402 {
403 int nanos;
404
405 switch (precision)
406 {
407 case 0:
409 break;
410
411 case 1:
413 break;
414
415 case 2:
417 break;
418
419 case 3:
421 break;
422
423 case 4:
425 break;
426
427 case 5:
429 break;
430
431 case 6:
433 break;
434
435 case 7:
437 break;
438
439 case 8:
441 break;
442
443 case 9:
444 default:
446 break;
447 }
448
449 return nanos;
450 }

References FIX::PRECISION_FACTOR, and set().

Referenced by DateTime(), fromTm(), and setHMS().

◆ fromLocalTimeT() [1/2]

static DateTime FIX::DateTime::fromLocalTimeT ( time_t  t,
int  fraction,
int  precision 
)
inlinestatic

Definition at line 486 of file FieldTypes.h.

487 {
488 struct tm tm = time_localtime( &t );
489 return fromTm( tm, fraction, precision );
490 }
tm time_localtime(const time_t *t)
Definition Utility.cpp:400
static DateTime fromTm(const tm &tm, int millis=0)
Convert a tm and optional milliseconds to a DateTime.
Definition FieldTypes.h:494

References fromTm(), set(), and FIX::time_localtime().

◆ fromLocalTimeT() [2/2]

static DateTime FIX::DateTime::fromLocalTimeT ( time_t  t,
int  millis = 0 
)
inlinestatic

Definition at line 474 of file FieldTypes.h.

475 {
476 struct tm tm = time_localtime( &t );
477 return fromTm( tm, millis );
478 }

References fromTm(), set(), and FIX::time_localtime().

Referenced by nowLocal().

◆ fromTm() [1/2]

static DateTime FIX::DateTime::fromTm ( const tm tm,
int  fraction,
int  precision 
)
inlinestatic

Convert a tm and optional milliseconds to a DateTime.

Note
the tm structure is assumed to contain a date specified in UTC

Definition at line 503 of file FieldTypes.h.

504 {
506 return DateTime ( julianDate(tm.tm_year + 1900, tm.tm_mon + 1,
507 tm.tm_mday),
508 makeHMS(tm.tm_hour, tm.tm_min, tm.tm_sec, nanos) );
509 }
DateTime()
Default constructor - initializes to zero.
Definition FieldTypes.h:80

References convertToNanos(), DateTime(), julianDate(), makeHMS(), and set().

◆ fromTm() [2/2]

static DateTime FIX::DateTime::fromTm ( const tm tm,
int  millis = 0 
)
inlinestatic

Convert a tm and optional milliseconds to a DateTime.

Note
the tm structure is assumed to contain a date specified in UTC

Definition at line 494 of file FieldTypes.h.

495 {
496 return DateTime ( julianDate(tm.tm_year + 1900, tm.tm_mon + 1,
497 tm.tm_mday),
498 makeHMS(tm.tm_hour, tm.tm_min, tm.tm_sec, millis * PRECISION_FACTOR[3]) );
499 }

References DateTime(), julianDate(), makeHMS(), FIX::PRECISION_FACTOR, and set().

Referenced by fromLocalTimeT(), fromLocalTimeT(), fromUtcTimeT(), and fromUtcTimeT().

◆ fromUtcTimeT() [1/2]

static DateTime FIX::DateTime::fromUtcTimeT ( time_t  t,
int  fraction,
int  precision 
)
inlinestatic

Definition at line 480 of file FieldTypes.h.

481 {
482 struct tm tm = time_gmtime( &t );
483 return fromTm( tm, fraction, precision );
484 }
tm time_gmtime(const time_t *t)
Definition Utility.cpp:384

References fromTm(), set(), and FIX::time_gmtime().

◆ fromUtcTimeT() [2/2]

static DateTime FIX::DateTime::fromUtcTimeT ( time_t  t,
int  millis = 0 
)
inlinestatic

Convert a time_t and optional milliseconds to a DateTime.

Definition at line 468 of file FieldTypes.h.

469 {
470 struct tm tm = time_gmtime( &t );
471 return fromTm( tm, millis );
472 }

References fromTm(), set(), and FIX::time_gmtime().

Referenced by nowUtc().

◆ getDate()

int FIX::DateTime::getDate ( ) const
inline

Another name for the day of the month.

Bad name, but used because of the legacy UtcTimeStamp interface

Definition at line 130 of file FieldTypes.h.

130{ return getDay(); }
int getDay() const
Return the day of the month portion of the date.
Definition FieldTypes.h:121

References getDay().

◆ getDay()

int FIX::DateTime::getDay ( ) const
inline

Return the day of the month portion of the date.

Definition at line 121 of file FieldTypes.h.

122 {
123 int y, m, d;
124 getYMD( y, m, d );
125 return d;
126 }
void getYMD(int &year, int &month, int &day) const
Load the referenced values with the year, month and day portions of the date in a single operation.
Definition FieldTypes.h:211

References getYMD(), and set().

Referenced by getDate().

◆ getFraction()

int FIX::DateTime::getFraction ( int  precision) const
inline

Return the fraction portion of the time.

Definition at line 172 of file FieldTypes.h.

173 {
174 switch (precision)
175 {
176 case 0:
177 return (getNanosecond() / PRECISION_FACTOR[0]);
178
179 case 1:
180 return (getNanosecond() / PRECISION_FACTOR[1]);
181
182 case 2:
183 return (getNanosecond() / PRECISION_FACTOR[2]);
184
185 case 3:
186 return (getNanosecond() / PRECISION_FACTOR[3]);
187
188 case 4:
189 return (getNanosecond() / PRECISION_FACTOR[4]);
190
191 case 5:
192 return (getNanosecond() / PRECISION_FACTOR[5]);
193
194 case 6:
195 return (getNanosecond() / PRECISION_FACTOR[6]);
196
197 case 7:
198 return (getNanosecond() / PRECISION_FACTOR[7]);
199
200 case 8:
201 return (getNanosecond() / PRECISION_FACTOR[8]);
202
203 case 9:
204 default:
205 return (getNanosecond() / PRECISION_FACTOR[9]);
206 }
207 }
unsigned int getNanosecond() const
Return the nanosecond portion of the time.
Definition FieldTypes.h:166

References getNanosecond(), FIX::PRECISION_FACTOR, and set().

Referenced by getHMS().

◆ getHMS() [1/2]

void FIX::DateTime::getHMS ( int hour,
int minute,
int second,
int fraction,
int  precision 
) const
inline

Load the referenced values with the hour, minute, second and fraction portions of the time in a single operation.

Definition at line 229 of file FieldTypes.h.

230 {
231 int ticks = (int)(m_time / NANOS_PER_SEC);
236 }
static const int64_t SECONDS_PER_HOUR
Definition FieldTypes.h:67
static const int64_t SECONDS_PER_MIN
Definition FieldTypes.h:68
int getFraction(int precision) const
Return the fraction portion of the time.
Definition FieldTypes.h:172
static const int64_t MINUTES_PER_HOUR
Definition FieldTypes.h:69
static const int64_t NANOS_PER_SEC
Definition FieldTypes.h:74

References getFraction(), m_time, MINUTES_PER_HOUR, NANOS_PER_SEC, SECONDS_PER_HOUR, SECONDS_PER_MIN, and set().

◆ getHMS() [2/2]

void FIX::DateTime::getHMS ( int hour,
int minute,
int second,
int millis 
) const
inline

Load the referenced values with the hour, minute, second and millisecond portions of the time in a single operation.

Definition at line 218 of file FieldTypes.h.

219 {
220 int ticks = (int)(m_time / NANOS_PER_SEC);
225 }
int getMillisecond() const
Return the millisecond portion of the time (0-999)
Definition FieldTypes.h:154

References getMillisecond(), m_time, MINUTES_PER_HOUR, NANOS_PER_SEC, SECONDS_PER_HOUR, SECONDS_PER_MIN, and set().

Referenced by FIX::UtcTimeOnlyConvertor::convert(), FIX::UtcTimeStampConvertor::convert(), getTmUtc(), setFraction(), setHour(), setMicrosecond(), setMillisecond(), setMinute(), setNanosecond(), and setSecond().

◆ getHour()

int FIX::DateTime::getHour ( ) const
inline

Return the hour portion of the time (0-23)

Definition at line 136 of file FieldTypes.h.

137 {
138 return (int)(m_time / NANOS_PER_HOUR);
139 }
static const int64_t NANOS_PER_HOUR
Definition FieldTypes.h:72

References m_time, and NANOS_PER_HOUR.

Referenced by FIX::SessionFactory::create().

◆ getJulianDate()

int FIX::DateTime::getJulianDate ( ) const
inline

Return the internal julian date.

Definition at line 133 of file FieldTypes.h.

133{ return m_date; }

References m_date.

Referenced by FIX::TimeRange::isInSameRange().

◆ getMicroecond()

int FIX::DateTime::getMicroecond ( ) const
inline

Return the microsecond portion of the time.

Definition at line 160 of file FieldTypes.h.

161 {
162 return (getNanosecond() / PRECISION_FACTOR[6]);
163 }

References getNanosecond(), and FIX::PRECISION_FACTOR.

◆ getMillisecond()

int FIX::DateTime::getMillisecond ( ) const
inline

Return the millisecond portion of the time (0-999)

Definition at line 154 of file FieldTypes.h.

155 {
156 return (getNanosecond() / PRECISION_FACTOR[3]);
157 }

References getNanosecond(), and FIX::PRECISION_FACTOR.

Referenced by getHMS().

◆ getMinute()

int FIX::DateTime::getMinute ( ) const
inline

Return the minute portion of the time (0-59)

Definition at line 142 of file FieldTypes.h.

143 {
145 }
static const int64_t NANOS_PER_MIN
Definition FieldTypes.h:73

References m_time, MINUTES_PER_HOUR, and NANOS_PER_MIN.

Referenced by FIX::SessionFactory::create().

◆ getMonth()

int FIX::DateTime::getMonth ( ) const
inline

Return the month (1-12) portion of the date.

Definition at line 113 of file FieldTypes.h.

114 {
115 int y, m, d;
116 getYMD( y, m, d );
117 return m;
118 }

References getYMD(), and set().

◆ getNanosecond()

unsigned int FIX::DateTime::getNanosecond ( ) const
inline

Return the nanosecond portion of the time.

Definition at line 166 of file FieldTypes.h.

167 {
168 return static_cast<uint64_t>(m_time) % NANOS_PER_SEC;
169 }
unsigned __int64 uint64_t
Definition stdint_msvc.h:91

References m_time, and NANOS_PER_SEC.

Referenced by getFraction(), getMicroecond(), and getMillisecond().

◆ getSecond()

int FIX::DateTime::getSecond ( ) const
inline

Return the second portion of the time (0-59)

Definition at line 148 of file FieldTypes.h.

149 {
151 }

References m_time, NANOS_PER_SEC, and SECONDS_PER_MIN.

Referenced by FIX::SessionFactory::create().

◆ getTimeT()

time_t FIX::DateTime::getTimeT ( ) const
inline

Convert the DateTime to a time_t.

Note that this operation can overflow on 32-bit platforms when we go beyond year 2038.

Definition at line 254 of file FieldTypes.h.

255 {
258 }
static const int64_t SECONDS_PER_DAY
Magic numbers.
Definition FieldTypes.h:66
static const int64_t JULIAN_19700101
Definition FieldTypes.h:77

References JULIAN_19700101, m_date, m_time, NANOS_PER_SEC, and SECONDS_PER_DAY.

Referenced by FIX::TimeRange::isInRange(), FIX::TimeRange::isInRange(), FIX::TimeRange::isInSameRange(), and FIX::TimeRange::isInSameRange().

◆ getTmUtc()

tm FIX::DateTime::getTmUtc ( ) const
inline

Convert the DateTime to a struct tm which is in UTC.

Definition at line 261 of file FieldTypes.h.

262 {
263 int year, month, day;
264 int hour, minute, second, millis;
265 tm result = { 0 };
266
267 getYMD( year, month, day );
269
270 result.tm_year = year - 1900;
271 result.tm_mon = month - 1;
272 result.tm_mday = day;
273 result.tm_hour = hour;
274 result.tm_min = minute;
275 result.tm_sec = second;
276 result.tm_isdst = -1;
277
278 return result;
279 }
void getHMS(int &hour, int &minute, int &second, int &millis) const
Load the referenced values with the hour, minute, second and millisecond portions of the time in a si...
Definition FieldTypes.h:218

References getHMS(), getYMD(), and set().

◆ getWeekDay()

int FIX::DateTime::getWeekDay ( ) const
inline

Calculate the weekday of the date (Sunday is 1, Saturday is 7)

Definition at line 239 of file FieldTypes.h.

240 {
241 int Y, M, D;
242 getYMD (Y, M, D);
243 int m = M >= 3 ? M - 2 : M + 10;
244 int Yprime = M >= 3 ? Y : Y - 1;
245 int y = Yprime % 100;
246 int c = Yprime / 100;
247 int wd = (D + int (2.6 * m - 0.2) + y + int (y / 4) + int (c / 4) -
248 (2 * c)) % 7;
249 return 1 + (wd < 0 ? 7 + wd : wd);
250 }

References getYMD(), and set().

Referenced by FIX::TimeRange::isInRange(), FIX::TimeRange::isInRange(), FIX::TimeRange::isInRange(), and FIX::TimeRange::isInSameRange().

◆ getYear()

int FIX::DateTime::getYear ( ) const
inline

Return the year portion of the date.

Definition at line 105 of file FieldTypes.h.

106 {
107 int y, m, d;
108 getYMD( y, m, d );
109 return y;
110 }

References getYMD(), and set().

◆ getYMD() [1/2]

void FIX::DateTime::getYMD ( int year,
int month,
int day 
) const
inline

Load the referenced values with the year, month and day portions of the date in a single operation.

Definition at line 211 of file FieldTypes.h.

212 {
213 getYMD( m_date, year, month, day );
214 }

References getYMD(), m_date, and set().

Referenced by FIX::UtcTimeStampConvertor::convert(), getDay(), getMonth(), getTmUtc(), getWeekDay(), getYear(), and getYMD().

◆ getYMD() [2/2]

static void FIX::DateTime::getYMD ( int  jday,
int year,
int month,
int day 
)
inlinestatic

Convert a Julian day number to a year, month and day.

Definition at line 522 of file FieldTypes.h.

523 {
524 int a = jday + 32044;
525 int b = (4 * a + 3) / 146097;
526 int c = a - int ((b * 146097) / 4);
527 int d = (4 * c + 3) / 1461;
528 int e = c - int ((1461 * d) / 4);
529 int m = (5 * e + 2) / 153;
530 day = e - int ((153 * m + 2) / 5) + 1;
531 month = m + 3 - 12 * int (m / 10);
532 year = b * 100 + d - 4800 + int (m / 10);
533 }

References set().

◆ julianDate()

static int FIX::DateTime::julianDate ( int  year,
int  month,
int  day 
)
inlinestatic

Helper method to calculate a Julian day number.

Definition at line 512 of file FieldTypes.h.

513 {
514 int a = (14 - month) / 12;
515 int y = year + 4800 - a;
516 int m = month + 12 * a - 3;
517 return (day + int ((153 * m + 2) / 5) + y * 365 +
518 int (y / 4) - int (y / 100) + int (y / 400) - 32045);
519 }

References set().

Referenced by DateTime(), DateTime(), fromTm(), fromTm(), and setYMD().

◆ makeHMS()

static int64_t FIX::DateTime::makeHMS ( int  hour,
int  minute,
int  second,
int  nanos 
)
inlinestatic

Helper method to convert a broken down time to a number of nanoseconds since midnight.

Definition at line 454 of file FieldTypes.h.

455 {
458 second) + nanos;
459 }

References NANOS_PER_SEC, SECONDS_PER_HOUR, SECONDS_PER_MIN, and set().

Referenced by DateTime(), DateTime(), fromTm(), fromTm(), setHMS(), and setHMS().

◆ nowLocal()

DateTime FIX::DateTime::nowLocal ( )
static

Return the current wall-clock time as a local DateTime.

Definition at line 49 of file FieldTypes.cpp.

50{
51#if defined( _POSIX_SOURCE ) || defined(HAVE_GETTIMEOFDAY)
52 struct timeval tv;
53 gettimeofday (&tv, 0);
54 return fromLocalTimeT( tv.tv_sec, tv.tv_usec, 6 );
55#elif defined( HAVE_FTIME )
56 timeb tb;
57 ftime (&tb);
58 return fromLocalTimeT( tb.time, tb.millitm );
59#else
60 return fromLocalTimeT( ::time (0), 0 );
61#endif
62}
static DateTime fromLocalTimeT(time_t t, int millis=0)
Definition FieldTypes.h:474

References fromLocalTimeT(), and set().

Referenced by FIX::LocalTimeStamp::setCurrent(), FIX::LocalTimeOnly::setCurrent(), and FIX::LocalDate::setCurrent().

◆ nowUtc()

DateTime FIX::DateTime::nowUtc ( )
static

Return the current wall-clock time as a utc DateTime.

Definition at line 34 of file FieldTypes.cpp.

35{
36#if defined( _POSIX_SOURCE ) || defined(HAVE_GETTIMEOFDAY)
37 struct timeval tv;
38 gettimeofday (&tv, 0);
39 return fromUtcTimeT( tv.tv_sec, tv.tv_usec, 6 );
40#elif defined( HAVE_FTIME )
41 timeb tb;
42 ftime (&tb);
43 return fromUtcTimeT (tb.time, tb.millitm);
44#else
45 return fromUtcTimeT( ::time (0), 0 );
46#endif
47}
static DateTime fromUtcTimeT(time_t t, int millis=0)
Convert a time_t and optional milliseconds to a DateTime.
Definition FieldTypes.h:468

References fromUtcTimeT(), and set().

Referenced by FIX::UtcTimeStamp::setCurrent(), FIX::UtcTimeOnly::setCurrent(), and FIX::UtcDate::setCurrent().

◆ operator+=()

void FIX::DateTime::operator+= ( int  seconds)
inline

Add a number of seconds to this.

Definition at line 380 of file FieldTypes.h.

381 {
382 int d = seconds / SECONDS_PER_DAY;
383 int s = seconds % SECONDS_PER_DAY;
384
385 m_date += d;
387
388 if( m_time > NANOS_PER_DAY )
389 {
390 m_date++;
392 }
393 else if( m_time < 0 )
394 {
395 m_date--;
397 }
398 }
static const int64_t NANOS_PER_DAY
Definition FieldTypes.h:71

References m_date, m_time, NANOS_PER_DAY, NANOS_PER_SEC, SECONDS_PER_DAY, and set().

◆ set() [1/2]

void FIX::DateTime::set ( const DateTime other)
inline

Initialize from another DateTime.

Definition at line 373 of file FieldTypes.h.

374 {
375 m_date = other.m_date;
376 m_time = other.m_time;
377 }

References m_date, m_time, and set().

◆ set() [2/2]

void FIX::DateTime::set ( int  date,
int64_t  time 
)
inline

◆ setFraction()

void FIX::DateTime::setFraction ( int  fraction,
int  precision 
)
inline

Set the fraction portion of the time.

Definition at line 350 of file FieldTypes.h.

351 {
352 int hour, min, sec, old_nanos;
353 getHMS( hour, min, sec, old_nanos, 9 );
355 }
void setHMS(int hour, int minute, int second, int millis)
Set the time portion of the DateTime.
Definition FieldTypes.h:288

References getHMS(), set(), and setHMS().

◆ setHMS() [1/2]

void FIX::DateTime::setHMS ( int  hour,
int  minute,
int  second,
int  fraction,
int  precision 
)
inline

Set the time portion of the DateTime.

Definition at line 294 of file FieldTypes.h.

295 {
297
299 }

References convertToNanos(), m_time, makeHMS(), and set().

◆ setHMS() [2/2]

void FIX::DateTime::setHMS ( int  hour,
int  minute,
int  second,
int  millis 
)
inline

◆ setHour()

void FIX::DateTime::setHour ( int  hour)
inline

Set the hour portion of the time.

Definition at line 302 of file FieldTypes.h.

303 {
304 int old_hour, min, sec, millis;
306 setHMS( hour, min, sec, millis );
307 }

References getHMS(), set(), and setHMS().

◆ setMicrosecond()

void FIX::DateTime::setMicrosecond ( int  micros)
inline

Set the microsecond portion of the time.

Definition at line 334 of file FieldTypes.h.

335 {
336 int hour, min, sec, old_nanos;
337 getHMS( hour, min, sec, old_nanos, 9 );
338 setHMS( hour, min, sec, micros, 6 );
339 }

References getHMS(), set(), and setHMS().

◆ setMillisecond()

void FIX::DateTime::setMillisecond ( int  millis)
inline

Set the millisecond portion of the time.

Definition at line 326 of file FieldTypes.h.

327 {
328 int hour, min, sec, old_millis;
330 setHMS( hour, min, sec, millis );
331 }

References getHMS(), set(), and setHMS().

◆ setMinute()

void FIX::DateTime::setMinute ( int  min)
inline

Set the minute portion of the time.

Definition at line 310 of file FieldTypes.h.

311 {
312 int hour, old_min, sec, millis;
314 setHMS( hour, min, sec, millis );
315 }

References getHMS(), set(), and setHMS().

◆ setNanosecond()

void FIX::DateTime::setNanosecond ( int  nanos)
inline

Set the nanosecond portion of the time.

Definition at line 342 of file FieldTypes.h.

343 {
344 int hour, min, sec, old_nanos;
345 getHMS( hour, min, sec, old_nanos, 9 );
346 setHMS( hour, min, sec, nanos, 9 );
347 }

References getHMS(), set(), and setHMS().

◆ setSecond()

void FIX::DateTime::setSecond ( int  sec)
inline

Set the seconds portion of the time.

Definition at line 318 of file FieldTypes.h.

319 {
320 int hour, min, old_sec, millis;
322 setHMS( hour, min, sec, millis );
323 }

References getHMS(), set(), and setHMS().

◆ setYMD()

void FIX::DateTime::setYMD ( int  year,
int  month,
int  day 
)
inline

Set the date portion of the DateTime.

Definition at line 282 of file FieldTypes.h.

283 {
285 }

References julianDate(), m_date, and set().

Member Data Documentation

◆ JULIAN_19700101

const int64_t FIX::DateTime::JULIAN_19700101 = 2440588
static

Definition at line 77 of file FieldTypes.h.

Referenced by getTimeT().

◆ m_date

int FIX::DateTime::m_date

◆ m_time

int64_t FIX::DateTime::m_time

◆ MINUTES_PER_HOUR

const int64_t FIX::DateTime::MINUTES_PER_HOUR = 60
static

Definition at line 69 of file FieldTypes.h.

Referenced by getHMS(), getHMS(), and getMinute().

◆ NANOS_PER_DAY

const int64_t FIX::DateTime::NANOS_PER_DAY = 86400000000000
static

Definition at line 71 of file FieldTypes.h.

Referenced by operator+=().

◆ NANOS_PER_HOUR

const int64_t FIX::DateTime::NANOS_PER_HOUR = 3600000000000
static

Definition at line 72 of file FieldTypes.h.

Referenced by getHour().

◆ NANOS_PER_MIN

const int64_t FIX::DateTime::NANOS_PER_MIN = 60000000000
static

Definition at line 73 of file FieldTypes.h.

Referenced by getMinute().

◆ NANOS_PER_SEC

const int64_t FIX::DateTime::NANOS_PER_SEC = 1000000000
static

◆ SECONDS_PER_DAY

const int64_t FIX::DateTime::SECONDS_PER_DAY = 86400
static

Magic numbers.

Definition at line 66 of file FieldTypes.h.

Referenced by getTimeT(), FIX::TimeRange::isInSameRange(), operator+=(), and FIX::operator-().

◆ SECONDS_PER_HOUR

const int64_t FIX::DateTime::SECONDS_PER_HOUR = 3600
static

Definition at line 67 of file FieldTypes.h.

Referenced by getHMS(), getHMS(), and makeHMS().

◆ SECONDS_PER_MIN

const int64_t FIX::DateTime::SECONDS_PER_MIN = 60
static

Definition at line 68 of file FieldTypes.h.

Referenced by getHMS(), getHMS(), getSecond(), and makeHMS().


The documentation for this struct was generated from the following files:

Generated on Thu May 22 2025 08:23:50 for QuickFIX by doxygen 1.9.8 written by Dimitri van Heesch, © 1997-2001