FIX::UtcTimeStampConvertor Struct Reference

Converts a UtcTimeStamp to/from a string. More...

`#include <FieldConvertors.h>`

## Static Public Member Functions

static std::string | convert (const UtcTimeStamp &value, int precision=0) throw ( FieldConvertError )
static UtcTimeStamp | convert (const std::string &value) throw ( FieldConvertError )

## Detailed Description

Converts a UtcTimeStamp to/from a string.

Definition at line 432 of file FieldConvertors.h.

## Member Function Documentation

## convert() [1/2]

static UtcTimeStamp FIX::UtcTimeStampConvertor::convert | ( | const std::string & | value | ) |
throw | ( | FieldConvertError
| ) |  |

inline static

Definition at line 467 of file FieldConvertors.h.

{
size_t len = value.size();
if (len < 17 || len > 27) throw FieldConvertError(value);
size_t i = 0;
int c = 0;
for( c = 0; c < 8; ++c )
if( !IS_DIGIT(value[i++]) ) throw FieldConvertError(value);
if (value[i++] != '-') throw FieldConvertError(value);
for( c = 0; c < 2; ++c )
if( !IS_DIGIT(value[i++]) ) throw FieldConvertError(value);
if( value[i++] != ':' ) throw FieldConvertError(value);
for( c = 0; c < 2; ++c )
if( !IS_DIGIT(value[i++]) ) throw FieldConvertError(value);
if( value[i++] != ':' ) throw FieldConvertError(value);
for( c = 0; c < 2; ++c )
if( !IS_DIGIT(value[i++]) ) throw FieldConvertError(value);
int year, mon, mday, hour, min, sec;
i = 0;
year = value[i++] - '0';
year = 10 * year + value[i++] - '0';
year = 10 * year + value[i++] - '0';
year = 10 * year + value[i++] - '0';
mon = value[i++] - '0';
mon = 10 * mon + value[i++] - '0';
if( mon < 1 || 12 < mon ) throw FieldConvertError(value);
mday = value[i++] - '0';
mday = 10 * mday + value[i++] - '0';
if( mday < 1 || 31 < mday ) throw FieldConvertError(value);
++i; // skip '-'
hour = value[i++] - '0';
hour = 10 * hour + value[i++] - '0';
// No check for >= 0 as no '-' are converted here
if( 23 < hour ) throw FieldConvertError(value);
++i; // skip ':'
min = value[i++] - '0';
min = 10 * min + value[i++] - '0';
// No check for >= 0 as no '-' are converted here
if( 59 < min ) throw FieldConvertError(value);
++i; // skip ':'
sec = value[i++] - '0';
sec = 10 * sec + value[i++] - '0';
// No check for >= 0 as no '-' are converted here
if( 60 < sec ) throw FieldConvertError(value);
if (len == 17)
return UtcTimeStamp (hour, min, sec, 0,
mday, mon, year);
if( value[i++] != '.' ) throw FieldConvertError(value);
int fraction = 0;
for (; i < len; ++i)
{
char ch = value[i];
if( !IS_DIGIT(ch)) throw FieldConvertError(value);
fraction = (fraction * 10) + ch - '0';
}
return UtcTimeStamp (hour, min, sec, fraction,
mday, mon, year, len - 17 - 1);
}
IS_DIGIT
#define IS_DIGIT(x)
Definition FieldConvertors.h:49
FIX::TYPE::UtcTimeStamp
@ UtcTimeStamp
Definition FieldTypes.h:923

References IS_DIGIT.

## convert() [2/2]

static std::string FIX::UtcTimeStampConvertor::convert | ( | const UtcTimeStamp & | value,
|  | int | precision = `0`
| ) |  |
throw | ( | FieldConvertError
| ) |  |

inline static

Definition at line 434 of file FieldConvertors.h.

{
char result[ 17+10 ]; // Maximum
int year, month, day, hour, minute, second, fraction;
value.getYMD( year, month, day );
value.getHMS( hour, minute, second, fraction, precision );
integer_to_string_padded( result, 4, year);
integer_to_string_padded( result + 4, 2, month );
integer_to_string_padded( result + 6, 2, day );
result[8] = '-';
integer_to_string_padded( result + 9, 2, hour);
result[11] = ':';
integer_to_string_padded( result + 12, 2, minute);
result[14] = ':';
integer_to_string_padded( result + 15, 2, second);
if( precision )
{
result[17] = '.';
if( integer_to_string_padded ( result + 18, precision, fraction )
!= result + 18 )
{
throw FieldConvertError();
}
}
return std::string(result, precision ? (17 + 1 + precision) : 17);
}
FIX::integer_to_string_padded
char * integer_to_string_padded(char *buf, const size_t len, signed_int t, const char paddingChar='0')
Definition FieldConvertors.h:132

References FIX::DateTime::getHMS(), FIX::DateTime::getYMD(), and FIX::integer_to_string_padded().

Referenced by FIX::DataDictionary::checkValidFormat(), FIX::UtcTimeStampField::getValue(), FIX::FileLog::onEvent(), FIX::ScreenLog::onEvent(), FIX::FileLog::onIncoming(), FIX::ScreenLog::onIncoming(), FIX::FileLog::onOutgoing(), FIX::ScreenLog::onOutgoing(), FIX::FileStore::populateCache(), FIX::FileStore::setSession(), and FIX::UtcTimeStampField::setValue().

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

- FieldConvertors.h