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, 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
)
inlinestatic

Definition at line 467 of file FieldConvertors.h.

469 {
470 size_t len = value.size();
471 if (len < 17 || len > 27) throw FieldConvertError(value);
472
473 size_t i = 0;
474 int c = 0;
475 for( c = 0; c < 8; ++c )
476 if( !IS_DIGIT(value[i++]) ) throw FieldConvertError(value);
477 if (value[i++] != '-') throw FieldConvertError(value);
478 for( c = 0; c < 2; ++c )
479 if( !IS_DIGIT(value[i++]) ) throw FieldConvertError(value);
480 if( value[i++] != ':' ) throw FieldConvertError(value);
481 for( c = 0; c < 2; ++c )
482 if( !IS_DIGIT(value[i++]) ) throw FieldConvertError(value);
483 if( value[i++] != ':' ) throw FieldConvertError(value);
484 for( c = 0; c < 2; ++c )
485 if( !IS_DIGIT(value[i++]) ) throw FieldConvertError(value);
486
487 int year, mon, mday, hour, min, sec;
488
489 i = 0;
490
491 year = value[i++] - '0';
492 year = 10 * year + value[i++] - '0';
493 year = 10 * year + value[i++] - '0';
494 year = 10 * year + value[i++] - '0';
495
496 mon = value[i++] - '0';
497 mon = 10 * mon + value[i++] - '0';
498 if( mon < 1 || 12 < mon ) throw FieldConvertError(value);
499
500 mday = value[i++] - '0';
501 mday = 10 * mday + value[i++] - '0';
502 if( mday < 1 || 31 < mday ) throw FieldConvertError(value);
503
504 ++i; // skip '-'
505
506 hour = value[i++] - '0';
507 hour = 10 * hour + value[i++] - '0';
508 // No check for >= 0 as no '-' are converted here
509 if( 23 < hour ) throw FieldConvertError(value);
510
511 ++i; // skip ':'
512
513 min = value[i++] - '0';
514 min = 10 * min + value[i++] - '0';
515 // No check for >= 0 as no '-' are converted here
516 if( 59 < min ) throw FieldConvertError(value);
517
518 ++i; // skip ':'
519
520 sec = value[i++] - '0';
521 sec = 10 * sec + value[i++] - '0';
522
523 // No check for >= 0 as no '-' are converted here
524 if( 60 < sec ) throw FieldConvertError(value);
525
526 if (len == 17)
527 return UtcTimeStamp (hour, min, sec, 0,
528 mday, mon, year);
529
530 if( value[i++] != '.' ) throw FieldConvertError(value);
531
532 int fraction = 0;
533 for (; i < len; ++i)
534 {
535 char ch = value[i];
536 if( !IS_DIGIT(ch)) throw FieldConvertError(value);
537 fraction = (fraction * 10) + ch - '0';
538 }
539
540 return UtcTimeStamp (hour, min, sec, fraction,
541 mday, mon, year, len - 17 - 1);
542 }
#define IS_DIGIT(x)

References IS_DIGIT.

◆ convert() [2/2]

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

Definition at line 434 of file FieldConvertors.h.

437 {
438 char result[ 17+10 ]; // Maximum
439 int year, month, day, hour, minute, second, fraction;
440
441 value.getYMD( year, month, day );
442 value.getHMS( hour, minute, second, fraction, precision );
443
444 integer_to_string_padded( result, 4, year);
445 integer_to_string_padded( result + 4, 2, month );
446 integer_to_string_padded( result + 6, 2, day );
447 result[8] = '-';
448 integer_to_string_padded( result + 9, 2, hour);
449 result[11] = ':';
450 integer_to_string_padded( result + 12, 2, minute);
451 result[14] = ':';
452 integer_to_string_padded( result + 15, 2, second);
453
454 if( precision )
455 {
456 result[17] = '.';
457 if( integer_to_string_padded ( result + 18, precision, fraction )
458 != result + 18 )
459 {
460 throw FieldConvertError();
461 }
462 }
463
464 return std::string(result, precision ? (17 + 1 + precision) : 17);
465 }
char * integer_to_string_padded(char *buf, const size_t len, signed_int t, const char paddingChar='0')

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:

Generated on Thu Feb 29 2024 22:38:19 for QuickFIX by doxygen 1.9.8 written by Dimitri van Heesch, © 1997-2001