Static Public Member Functions | List of all members
FIX::UtcTimeOnlyConvertor Struct Reference

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

#include <FieldConvertors.h>

Static Public Member Functions

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

Detailed Description

Converts a UtcTimeOnly to/from a string.

Definition at line 687 of file FieldConvertors.h.

Member Function Documentation

◆ convert() [1/2]

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

Definition at line 689 of file FieldConvertors.h.

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

Referenced by FIX::DataDictionary::checkValidFormat(), FIX::SessionFactory::create(), FIX::UtcTimeOnlyField::getValue(), and FIX::UtcTimeOnlyField::setValue().

692  {
693  char result[ 9+4 ];
694  int hour, minute, second, millis;
695 
696  value.getHMS( hour, minute, second, millis );
697 
698  integer_to_string_padded ( result, 3, hour, 2 );
699  result[2] = ':';
700  integer_to_string_padded ( result + 3, 3, minute, 2 );
701  result[5] = ':';
702  integer_to_string_padded ( result + 6, 3, second, 2 );
703 
704  if( showMilliseconds )
705  {
706  result[8] = '.';
707  if( integer_to_string_padded ( result + 9, 4, millis, 3 )
708  != result + 9 )
709  throw FieldConvertError();
710  }
711 
712  return result;
713  }
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 UtcTimeOnly FIX::UtcTimeOnlyConvertor::convert ( const std::string &  value)
throw (FieldConvertError
)
inlinestatic

Definition at line 715 of file FieldConvertors.h.

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

717  {
718  bool haveMilliseconds = false;
719 
720  switch( value.size() )
721  {
722  case 12: haveMilliseconds = true;
723  case 8: break;
724  default: throw FieldConvertError(value);
725  }
726 
727  int i = 0;
728  int c = 0;
729  for( c = 0; c < 2; ++c )
730  if( !IS_DIGIT(value[i++]) ) throw FieldConvertError(value);
731  if( value[i++] != ':' ) throw FieldConvertError(value);
732  for( c = 0; c < 2; ++c )
733  if( !IS_DIGIT(value[i++]) ) throw FieldConvertError(value);
734  if( value[i++] != ':' ) throw FieldConvertError(value);
735  for( c = 0; c < 2; ++c )
736  if( !IS_DIGIT(value[i++]) ) throw FieldConvertError(value);
737 
738  if( haveMilliseconds )
739  {
740  // ++i instead of i++ skips the '.' separator
741  for( c = 0; c < 3; ++c )
742  if( !IS_DIGIT(value[++i]) ) throw FieldConvertError(value);
743  }
744 
745  int hour, min, sec, millis;
746 
747  i = 0;
748 
749  hour = value[i++] - '0';
750  hour = 10 * hour + value[i++] - '0';
751  // No check for >= 0 as no '-' are converted here
752  if( 23 < hour ) throw FieldConvertError(value);
753  ++i; // skip ':'
754 
755  min = value[i++] - '0';
756  min = 10 * min + value[i++] - '0';
757  // No check for >= 0 as no '-' are converted here
758  if( 59 < min ) throw FieldConvertError(value);
759  ++i; // skip ':'
760 
761  sec = value[i++] - '0';
762  sec = 10 * sec + value[i++] - '0';
763  // No check for >= 0 as no '-' are converted here
764  if( 60 < sec ) throw FieldConvertError(value);
765 
766  if( haveMilliseconds )
767  {
768  millis = (100 * (value[i+1] - '0')
769  + 10 * (value[i+2] - '0')
770  + (value[i+3] - '0'));
771  }
772  else
773  millis = 0;
774 
775  return UtcTimeOnly( hour, min, sec, millis );
776  }
#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