Static Public Member Functions
FIX::UtcTimeStampConvertor Struct Reference

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

#include <FieldConvertors.h>

List of all members.

Static Public Member Functions

static std::string convert (const UtcTimeStamp &value, bool showMilliseconds=false) throw ( FieldConvertError )
static UtcTimeStamp convert (const std::string &value, bool calculateDays=false) throw ( FieldConvertError )

Detailed Description

Converts a UtcTimeStamp to/from a string.

Definition at line 564 of file FieldConvertors.h.


Member Function Documentation

static std::string FIX::UtcTimeStampConvertor::convert ( const UtcTimeStamp value,
bool  showMilliseconds = false 
) throw ( FieldConvertError ) [inline, static]

Definition at line 566 of file FieldConvertors.h.

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().

  {
    char result[ 18+4 ];
    int year, month, day, hour, minute, second, millis;

    value.getYMD( year, month, day );
    value.getHMS( hour, minute, second, millis );

    integer_to_string_padded( result, 5, year, 4 );
    integer_to_string_padded( result + 4, 3, month, 2 );
    integer_to_string_padded( result + 6, 3, day, 2 );
    result[8]  = '-';
    integer_to_string_padded( result + 9, 3, hour, 2 );
    result[11] = ':';
    integer_to_string_padded( result + 12, 3, minute, 2 );
    result[14] = ':';
    integer_to_string_padded( result + 15, 3, second, 2 );

    if( showMilliseconds )
    {
      result[17] = '.';
      if( integer_to_string_padded ( result + 18, 4, millis, 3 )
          != result + 18 )
      {
        throw FieldConvertError();
      }
    }

    return result;
  }
static UtcTimeStamp FIX::UtcTimeStampConvertor::convert ( const std::string &  value,
bool  calculateDays = false 
) throw ( FieldConvertError ) [inline, static]

Definition at line 599 of file FieldConvertors.h.

References IS_DIGIT, and FIX::TYPE::UtcTimeStamp.

  {
    bool haveMilliseconds = false;

    switch( value.size() )
    {
      case 21: haveMilliseconds = true;
      case 17: break;
      default: throw FieldConvertError(value);
    }

    int 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);

    if( haveMilliseconds )
    {
      if( value[i++] != '.' ) throw FieldConvertError(value);
      for( c = 0; c < 3; ++c )
        if( !IS_DIGIT(value[i++]) ) throw FieldConvertError(value);
    }

    int year, mon, mday, hour, min, sec, millis;

    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( haveMilliseconds )
    {
      millis = (100 * (value[i+1] - '0')
                + 10 * (value[i+2] - '0')
                + (value[i+3] - '0'));
    }
    else
      millis = 0;

    return UtcTimeStamp (hour, min, sec, millis,
                         mday, mon, year);
  }

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

Generated on Mon Jun 23 2014 23:49:39 for QuickFIX by doxygen 1.7.6.1 written by Dimitri van Heesch, © 1997-2001