FIX::DateTime Struct Reference
User

`#include <FieldTypes.h>`

Inheritance diagram for FIX::DateTime:
[legend]

## Public Member Functions

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

## Static Public Member Functions

static int | convertToNanos (int fraction, int precision)
| Convert to internal nanos. More...
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. More...
static DateTime | nowUtc ()
| Return the current wall-clock time as a utc DateTime. More...
static DateTime | nowLocal ()
| Return the current wall-clock time as a local DateTime. More...
static DateTime | fromUtcTimeT (time_t t, int millis=0)
| Convert a time_t and optional milliseconds to a DateTime. More...
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. More...
static DateTime | fromTm (const tm &tm, int fraction, int precision)
| Convert a tm and optional milliseconds to a DateTime. More...
static int | julianDate (int year, int month, int day)
| Helper method to calculate a Julian day number. More...
static void | getYMD (int jday, int &year, int &month, int &day)
| Convert a Julian day number to a year, month and day. More...

## Public Attributes

int | m_date
int64_t | m_time

## Static Public Attributes

static const int64_t | SECONDS_PER_DAY = 86400
| Magic numbers. More...
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.

: m_date (0), m_time (0) {}
FIX::DateTime::m_time
int64_t m_time
Definition: FieldTypes.h:63
FIX::DateTime::m_date
int m_date
Definition: FieldTypes.h:62

Referenced by 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.

: m_date (date), m_time (time) {}

## 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.

{
m_date = julianDate( year, month, day );
m_time = makeHMS( hour, minute, second, millis * PRECISION_FACTOR[3] );
}
FIX::PRECISION_FACTOR
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
FIX::DateTime::makeHMS
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
FIX::DateTime::julianDate
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(), and FIX::PRECISION_FACTOR.

## 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.

{
m_date = julianDate( year, month, day );
int nanos = convertToNanos(fraction, precision);
m_time = makeHMS( hour, minute, second, nanos );
}
FIX::DateTime::convertToNanos
static int convertToNanos(int fraction, int precision)
Convert to internal nanos.
Definition: FieldTypes.h:401

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

## ~DateTime()

virtual FIX::DateTime::~DateTime | ( |  | ) |

inline virtual

Definition at line 102 of file FieldTypes.h.

{}

## Member Function Documentation

## clearDate()

void FIX::DateTime::clearDate | ( |  | ) |

inline

Clear the date portion of the DateTime.

Definition at line 358 of file FieldTypes.h.

{
m_date = 0;
}

References m_date.

Referenced by FIX::LocalTimeOnly::LocalTimeOnly(), and FIX::UtcTimeOnly::UtcTimeOnly().

## clearTime()

void FIX::DateTime::clearTime | ( |  | ) |

inline

Clear the time portion of the DateTime.

Definition at line 364 of file FieldTypes.h.

{
m_time = 0;
}

References m_time.

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

## convertToNanos()

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

inline static

Convert to internal nanos.

Definition at line 401 of file FieldTypes.h.

{
int nanos;
switch (precision)
{
case 0:
nanos = fraction * PRECISION_FACTOR[0];
break;
case 1:
nanos = fraction * PRECISION_FACTOR[1];
break;
case 2:
nanos = fraction * PRECISION_FACTOR[2];
break;
case 3:
nanos = fraction * PRECISION_FACTOR[3];
break;
case 4:
nanos = fraction * PRECISION_FACTOR[4];
break;
case 5:
nanos = fraction * PRECISION_FACTOR[5];
break;
case 6:
nanos = fraction * PRECISION_FACTOR[6];
break;
case 7:
nanos = fraction * PRECISION_FACTOR[7];
break;
case 8:
nanos = fraction * PRECISION_FACTOR[8];
break;
case 9:
default:
nanos = fraction * PRECISION_FACTOR[9];
break;
}
return nanos;
}

References FIX::PRECISION_FACTOR.

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

## fromLocalTimeT() [1/2]

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

inline static

Definition at line 486 of file FieldTypes.h.

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

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

## fromLocalTimeT() [2/2]

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

inline static

Definition at line 474 of file FieldTypes.h.

{
struct tm tm = time_localtime( &t );
return fromTm( tm, millis );
}

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

Referenced by nowLocal().

## fromTm() [1/2]

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

inline static

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.

{
int nanos = convertToNanos(fraction, precision);
return DateTime ( julianDate(tm.tm_year + 1900, tm.tm_mon + 1,
tm.tm_mday),
makeHMS(tm.tm_hour, tm.tm_min, tm.tm_sec, nanos) );
}
FIX::DateTime::DateTime
DateTime()
Default constructor - initializes to zero.
Definition: FieldTypes.h:80

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

## fromTm() [2/2]

static DateTime FIX::DateTime::fromTm | ( | const tm & | tm,
|  | int | millis = `0`
| ) |  |

inline static

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.

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

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

Referenced by fromLocalTimeT(), and fromUtcTimeT().

## fromUtcTimeT() [1/2]

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

inline static

Definition at line 480 of file FieldTypes.h.

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

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

## fromUtcTimeT() [2/2]

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

inline static

Convert a time_t and optional milliseconds to a DateTime.

Definition at line 468 of file FieldTypes.h.

{
struct tm tm = time_gmtime( &t );
return fromTm( tm, millis );
}

References fromTm(), 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.

{ return getDay(); }
FIX::DateTime::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.

{
int y, m, d;
getYMD( y, m, d );
return d;
}
FIX::DateTime::getYMD
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().

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.

{
switch (precision)
{
case 0:
return (getNanosecond() / PRECISION_FACTOR[0]);
case 1:
return (getNanosecond() / PRECISION_FACTOR[1]);
case 2:
return (getNanosecond() / PRECISION_FACTOR[2]);
case 3:
return (getNanosecond() / PRECISION_FACTOR[3]);
case 4:
return (getNanosecond() / PRECISION_FACTOR[4]);
case 5:
return (getNanosecond() / PRECISION_FACTOR[5]);
case 6:
return (getNanosecond() / PRECISION_FACTOR[6]);
case 7:
return (getNanosecond() / PRECISION_FACTOR[7]);
case 8:
return (getNanosecond() / PRECISION_FACTOR[8]);
case 9:
default:
return (getNanosecond() / PRECISION_FACTOR[9]);
}
}
FIX::DateTime::getNanosecond
unsigned int getNanosecond() const
Return the nanosecond portion of the time.
Definition: FieldTypes.h:166

References getNanosecond(), and FIX::PRECISION_FACTOR.

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.

{
int ticks = (int)(m_time / NANOS_PER_SEC);
hour = ticks / SECONDS_PER_HOUR;
minute = (ticks / SECONDS_PER_MIN) % MINUTES_PER_HOUR;
second = ticks % SECONDS_PER_MIN;
fraction = getFraction(precision);
}
FIX::DateTime::SECONDS_PER_HOUR
static const int64_t SECONDS_PER_HOUR
Definition: FieldTypes.h:67
FIX::DateTime::SECONDS_PER_MIN
static const int64_t SECONDS_PER_MIN
Definition: FieldTypes.h:68
FIX::DateTime::getFraction
int getFraction(int precision) const
Return the fraction portion of the time.
Definition: FieldTypes.h:172
FIX::DateTime::MINUTES_PER_HOUR
static const int64_t MINUTES_PER_HOUR
Definition: FieldTypes.h:69
FIX::DateTime::NANOS_PER_SEC
static const int64_t NANOS_PER_SEC
Definition: FieldTypes.h:74

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

## 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.

{
int ticks = (int)(m_time / NANOS_PER_SEC);
hour = ticks / SECONDS_PER_HOUR;
minute = (ticks / SECONDS_PER_MIN) % MINUTES_PER_HOUR;
second = ticks % SECONDS_PER_MIN;
millis = getMillisecond();
}
FIX::DateTime::getMillisecond
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, and SECONDS_PER_MIN.

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.

{
return (int)(m_time / NANOS_PER_HOUR);
}
FIX::DateTime::NANOS_PER_HOUR
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.

{ 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.

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

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.

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

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.

{
return (m_time / NANOS_PER_MIN) % MINUTES_PER_HOUR;
}
FIX::DateTime::NANOS_PER_MIN
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.

{
int y, m, d;
getYMD( y, m, d );
return m;
}

References getYMD().

## getNanosecond()

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

inline

Return the nanosecond portion of the time.

Definition at line 166 of file FieldTypes.h.

{
return static_cast<uint64_t>(m_time) % NANOS_PER_SEC;
}
uint64_t
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.

{
return (m_time / NANOS_PER_SEC) % SECONDS_PER_MIN;
}

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.

{
return (SECONDS_PER_DAY * (m_date - JULIAN_19700101) +
m_time / NANOS_PER_SEC);
}
FIX::DateTime::SECONDS_PER_DAY
static const int64_t SECONDS_PER_DAY
Magic numbers.
Definition: FieldTypes.h:66
FIX::DateTime::JULIAN_19700101
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(), 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.

{
int year, month, day;
int hour, minute, second, millis;
tm result = { 0 };
getYMD( year, month, day );
getHMS( hour, minute, second, millis );
result.tm_year = year - 1900;
result.tm_mon = month - 1;
result.tm_mday = day;
result.tm_hour = hour;
result.tm_min = minute;
result.tm_sec = second;
result.tm_isdst = -1;
return result;
}
FIX::DateTime::getHMS
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(), and getYMD().

## 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.

{
int Y, M, D;
getYMD (Y, M, D);
int m = M >= 3 ? M - 2 : M + 10;
int Yprime = M >= 3 ? Y : Y - 1;
int y = Yprime % 100;
int c = Yprime / 100;
int wd = (D + int (2.6 * m - 0.2) + y + int (y / 4) + int (c / 4) -
(2 * c)) % 7;
return 1 + (wd < 0 ? 7 + wd : wd);
}

References getYMD().

Referenced by 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.

{
int y, m, d;
getYMD( y, m, d );
return y;
}

References getYMD().

## 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.

{
getYMD( m_date, year, month, day );
}

References m_date.

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

## getYMD() [2/2]

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

inline static

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

Definition at line 522 of file FieldTypes.h.

{
int a = jday + 32044;
int b = (4 * a + 3) / 146097;
int c = a - int ((b * 146097) / 4);
int d = (4 * c + 3) / 1461;
int e = c - int ((1461 * d) / 4);
int m = (5 * e + 2) / 153;
day = e - int ((153 * m + 2) / 5) + 1;
month = m + 3 - 12 * int (m / 10);
year = b * 100 + d - 4800 + int (m / 10);
}

## julianDate()

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

inline static

Helper method to calculate a Julian day number.

Definition at line 512 of file FieldTypes.h.

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

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

## makeHMS()

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

inline static

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

Definition at line 454 of file FieldTypes.h.

{
return NANOS_PER_SEC * (SECONDS_PER_HOUR * hour +
SECONDS_PER_MIN * minute +
second) + nanos;
}

References NANOS_PER_SEC, SECONDS_PER_HOUR, and SECONDS_PER_MIN.

Referenced by DateTime(), fromTm(), 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.

{
#if defined( _POSIX_SOURCE ) || defined(HAVE_GETTIMEOFDAY)
struct timeval tv;
gettimeofday (&tv, 0);
return fromLocalTimeT( tv.tv_sec, tv.tv_usec, 6 );
#elif defined( HAVE_FTIME )
timeb tb;
ftime (&tb);
return fromLocalTimeT( tb.time, tb.millitm );
#else
return fromLocalTimeT( ::time (0), 0 );
#endif
}
FIX::DateTime::fromLocalTimeT
static DateTime fromLocalTimeT(time_t t, int millis=0)
Definition: FieldTypes.h:474

References fromLocalTimeT().

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.

{
#if defined( _POSIX_SOURCE ) || defined(HAVE_GETTIMEOFDAY)
struct timeval tv;
gettimeofday (&tv, 0);
return fromUtcTimeT( tv.tv_sec, tv.tv_usec, 6 );
#elif defined( HAVE_FTIME )
timeb tb;
ftime (&tb);
return fromUtcTimeT (tb.time, tb.millitm);
#else
return fromUtcTimeT( ::time (0), 0 );
#endif
}
FIX::DateTime::fromUtcTimeT
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().

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.

{
int d = seconds / SECONDS_PER_DAY;
int s = seconds % SECONDS_PER_DAY;
m_date += d;
m_time += s * NANOS_PER_SEC;
if( m_time > NANOS_PER_DAY )
{
m_date++;
m_time %= NANOS_PER_DAY;
}
else if( m_time < 0 )
{
m_date--;
m_time += NANOS_PER_DAY;
}
}
FIX::DateTime::NANOS_PER_DAY
static const int64_t NANOS_PER_DAY
Definition: FieldTypes.h:71

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

## set() [1/2]

void FIX::DateTime::set | ( | const DateTime & | other | ) |

inline

Initialize from another DateTime.

Definition at line 373 of file FieldTypes.h.

{
m_date = other.m_date;
m_time = other.m_time;
}

References m_date, and m_time.

## set() [2/2]

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

inline

Set the internal date and time members.

Definition at line 370 of file FieldTypes.h.

{ m_date = date; m_time = time; }

References m_date, and m_time.

Referenced by FIX::UtcTimeStamp::setCurrent(), and FIX::LocalTimeStamp::setCurrent().

## 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.

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

References getHMS(), 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.

{
int nanos = convertToNanos(fraction, precision);
m_time = makeHMS( hour, minute, second, nanos);
}

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

## setHMS() [2/2]

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

inline

Set the time portion of the DateTime.

Definition at line 288 of file FieldTypes.h.

{
m_time = makeHMS( hour, minute, second, millis * PRECISION_FACTOR[3] );
}

References m_time, makeHMS(), and FIX::PRECISION_FACTOR.

Referenced by FIX::LocalTimeOnly::LocalTimeOnly(), FIX::LocalTimeStamp::LocalTimeStamp(), setFraction(), setHour(), setMicrosecond(), setMillisecond(), setMinute(), setNanosecond(), setSecond(), FIX::UtcTimeOnly::UtcTimeOnly(), and FIX::UtcTimeStamp::UtcTimeStamp().

## setHour()

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

inline

Set the hour portion of the time.

Definition at line 302 of file FieldTypes.h.

{
int old_hour, min, sec, millis;
getHMS( old_hour, min, sec, millis );
setHMS( hour, min, sec, millis );
}

References getHMS(), 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.

{
int hour, min, sec, old_nanos;
getHMS( hour, min, sec, old_nanos, 9 );
setHMS( hour, min, sec, micros, 6 );
}

References getHMS(), 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.

{
int hour, min, sec, old_millis;
getHMS( hour, min, sec, old_millis );
setHMS( hour, min, sec, millis );
}

References getHMS(), 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.

{
int hour, old_min, sec, millis;
getHMS( hour, old_min, sec, millis );
setHMS( hour, min, sec, millis );
}

References getHMS(), 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.

{
int hour, min, sec, old_nanos;
getHMS( hour, min, sec, old_nanos, 9 );
setHMS( hour, min, sec, nanos, 9 );
}

References getHMS(), 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.

{
int hour, min, old_sec, millis;
getHMS( hour, min, old_sec, millis );
setHMS( hour, min, sec, millis );
}

References getHMS(), 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.

{
m_date = julianDate( year, month, day );
}

References julianDate(), and m_date.

## 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

Definition at line 62 of file FieldTypes.h.

Referenced by clearDate(), DateTime(), getJulianDate(), getTimeT(), getYMD(), operator+=(), FIX::operator-(), FIX::operator<(), FIX::operator==(), set(), FIX::UtcDate::setCurrent(), FIX::LocalDate::setCurrent(), and setYMD().

## m_time

int64_t FIX::DateTime::m_time

Definition at line 63 of file FieldTypes.h.

Referenced by clearTime(), DateTime(), getHMS(), getHour(), getMinute(), getNanosecond(), getSecond(), getTimeT(), operator+=(), FIX::operator-(), FIX::operator<(), FIX::operator==(), set(), FIX::UtcTimeOnly::setCurrent(), FIX::LocalTimeOnly::setCurrent(), and setHMS().

## MINUTES_PER_HOUR

const int64_t FIX::DateTime::MINUTES_PER_HOUR = 60

static

Definition at line 69 of file FieldTypes.h.

Referenced by 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

Definition at line 74 of file FieldTypes.h.

Referenced by getHMS(), getNanosecond(), getSecond(), getTimeT(), makeHMS(), operator+=(), and FIX::operator-().

## 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(), 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(), getSecond(), and makeHMS().

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

- FieldTypes.h
- FieldTypes.cpp