Static Public Member Functions | List of all members
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, 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

◆ convert() [1/2]

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

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

569  {
570  char result[ 18+4 ];
571  int year, month, day, hour, minute, second, millis;
572 
573  value.getYMD( year, month, day );
574  value.getHMS( hour, minute, second, millis );
575 
576  integer_to_string_padded( result, 5, year, 4 );
577  integer_to_string_padded( result + 4, 3, month, 2 );
578  integer_to_string_padded( result + 6, 3, day, 2 );
579  result[8] = '-';
580  integer_to_string_padded( result + 9, 3, hour, 2 );
581  result[11] = ':';
582  integer_to_string_padded( result + 12, 3, minute, 2 );
583  result[14] = ':';
584  integer_to_string_padded( result + 15, 3, second, 2 );
585 
586  if( showMilliseconds )
587  {
588  result[17] = '.';
589  if( integer_to_string_padded ( result + 18, 4, millis, 3 )
590  != result + 18 )
591  {
592  throw FieldConvertError();
593  }
594  }
595 
596  return result;
597  }
char * integer_to_string_padded(char *buf, const size_t len, signed_int t, const size_t width=0, const char paddingChar='0')

◆ convert() [2/2]

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

Definition at line 599 of file FieldConvertors.h.

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

602  {
603  bool haveMilliseconds = false;
604 
605  switch( value.size() )
606  {
607  case 21: haveMilliseconds = true;
608  case 17: break;
609  default: throw FieldConvertError(value);
610  }
611 
612  int i = 0;
613  int c = 0;
614  for( c = 0; c < 8; ++c )
615  if( !IS_DIGIT(value[i++]) ) throw FieldConvertError(value);
616  if (value[i++] != '-') throw FieldConvertError(value);
617  for( c = 0; c < 2; ++c )
618  if( !IS_DIGIT(value[i++]) ) throw FieldConvertError(value);
619  if( value[i++] != ':' ) throw FieldConvertError(value);
620  for( c = 0; c < 2; ++c )
621  if( !IS_DIGIT(value[i++]) ) throw FieldConvertError(value);
622  if( value[i++] != ':' ) throw FieldConvertError(value);
623  for( c = 0; c < 2; ++c )
624  if( !IS_DIGIT(value[i++]) ) throw FieldConvertError(value);
625 
626  if( haveMilliseconds )
627  {
628  if( value[i++] != '.' ) throw FieldConvertError(value);
629  for( c = 0; c < 3; ++c )
630  if( !IS_DIGIT(value[i++]) ) throw FieldConvertError(value);
631  }
632 
633  int year, mon, mday, hour, min, sec, millis;
634 
635  i = 0;
636 
637  year = value[i++] - '0';
638  year = 10 * year + value[i++] - '0';
639  year = 10 * year + value[i++] - '0';
640  year = 10 * year + value[i++] - '0';
641 
642  mon = value[i++] - '0';
643  mon = 10 * mon + value[i++] - '0';
644  if( mon < 1 || 12 < mon ) throw FieldConvertError(value);
645 
646  mday = value[i++] - '0';
647  mday = 10 * mday + value[i++] - '0';
648  if( mday < 1 || 31 < mday ) throw FieldConvertError(value);
649 
650  ++i; // skip '-'
651 
652  hour = value[i++] - '0';
653  hour = 10 * hour + value[i++] - '0';
654  // No check for >= 0 as no '-' are converted here
655  if( 23 < hour ) throw FieldConvertError(value);
656 
657  ++i; // skip ':'
658 
659  min = value[i++] - '0';
660  min = 10 * min + value[i++] - '0';
661  // No check for >= 0 as no '-' are converted here
662  if( 59 < min ) throw FieldConvertError(value);
663 
664  ++i; // skip ':'
665 
666  sec = value[i++] - '0';
667  sec = 10 * sec + value[i++] - '0';
668 
669  // No check for >= 0 as no '-' are converted here
670  if( 60 < sec ) throw FieldConvertError(value);
671 
672  if( haveMilliseconds )
673  {
674  millis = (100 * (value[i+1] - '0')
675  + 10 * (value[i+2] - '0')
676  + (value[i+3] - '0'));
677  }
678  else
679  millis = 0;
680 
681  return UtcTimeStamp (hour, min, sec, millis,
682  mday, mon, year);
683  }
#define IS_DIGIT(x)

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

Generated on Thu Sep 5 2019 11:07:58 for QuickFIX by doxygen 1.8.13 written by Dimitri van Heesch, © 1997-2001