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 553 of file FieldConvertors.h.

Member Function Documentation

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

Definition at line 555 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().

558  {
559  char result[ 18+4 ];
560  int year, month, day, hour, minute, second, millis;
561 
562  value.getYMD( year, month, day );
563  value.getHMS( hour, minute, second, millis );
564 
565  integer_to_string_padded( result, 5, year, 4 );
566  integer_to_string_padded( result + 4, 3, month, 2 );
567  integer_to_string_padded( result + 6, 3, day, 2 );
568  result[8] = '-';
569  integer_to_string_padded( result + 9, 3, hour, 2 );
570  result[11] = ':';
571  integer_to_string_padded( result + 12, 3, minute, 2 );
572  result[14] = ':';
573  integer_to_string_padded( result + 15, 3, second, 2 );
574 
575  if( showMilliseconds )
576  {
577  result[17] = '.';
578  if( integer_to_string_padded ( result + 18, 4, millis, 3 )
579  != result + 18 )
580  {
581  throw FieldConvertError();
582  }
583  }
584 
585  return result;
586  }
char * integer_to_string_padded(char *buf, const size_t len, signed_int t, const size_t width=0, const char paddingChar= '0')
static UtcTimeStamp FIX::UtcTimeStampConvertor::convert ( const std::string &  value,
bool  calculateDays = false 
)
throw (FieldConvertError
)
inlinestatic

Definition at line 588 of file FieldConvertors.h.

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

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

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

Generated on Sat Mar 29 2014 15:13:34 for QuickFIX by doxygen 1.8.5 written by Dimitri van Heesch, © 1997-2001