Engauge Digitizer 2
Loading...
Searching...
No Matches
Public Member Functions | List of all members
FormatDateTime Class Reference

Input parsing and output formatting for date/time values. More...

#include <FormatDateTime.h>

Collaboration diagram for FormatDateTime:
Collaboration graph

Public Member Functions

 FormatDateTime ()
 Single constructor.
 
QString formatOutput (CoordUnitsDate coordUnitsDate, CoordUnitsTime coordUnitsTime, double value) const
 Format the date/time value according to date/time format settings.
 
QValidator::State parseInput (CoordUnitsDate coordUnitsDate, CoordUnitsTime coordUnitsTime, const QString &stringUntrimmed, double &value) const
 Parse the input string into a time value.
 

Detailed Description

Input parsing and output formatting for date/time values.

Definition at line 25 of file FormatDateTime.h.

Constructor & Destructor Documentation

◆ FormatDateTime()

FormatDateTime::FormatDateTime ( )

Single constructor.

Definition at line 17 of file FormatDateTime.cpp.

18{
19 loadFormatsFormat();
20 loadFormatsParseAcceptable();
21 loadFormatsParseIncomplete();
22}

Member Function Documentation

◆ formatOutput()

QString FormatDateTime::formatOutput ( CoordUnitsDate coordUnitsDate,
CoordUnitsTime coordUnitsTime,
double value ) const

Format the date/time value according to date/time format settings.

Definition at line 127 of file FormatDateTime.cpp.

130{
131 LOG4CPP_INFO_S ((*mainCat)) << "FormatDateTime::formatOutput"
132 << " value=" << value;
133
134 ENGAUGE_ASSERT (m_formatsDateFormat.contains (coordUnitsDate));
135 ENGAUGE_ASSERT (m_formatsTimeFormat.contains (coordUnitsTime));
136
137 QString format = m_formatsDateFormat [coordUnitsDate] + " " + m_formatsTimeFormat [coordUnitsTime];
138 format = format.trimmed();
139
140 // Range of unsigned versus signed is not a problem here. A signed value maxes out at 2.4 billion
141 // which is year 2038
142 QDateTime dt = QDateTime::fromTime_t (unsigned (qFloor (value)));
143
144 return dt.toTimeSpec(REFERENCE_TIME_ZONE).toString (format);
145}
const int INNER_RADIUS_MIN
#define ENGAUGE_ASSERT(cond)
Drop in replacement for Q_ASSERT if defined(QT_NO_DEBUG) && !defined(QT_FORCE_ASSERTS) define ENGAUGE...
const Qt::TimeSpec REFERENCE_TIME_ZONE(Qt::UTC)
log4cpp::Category * mainCat
Definition Logger.cpp:14
#define LOG4CPP_INFO_S(logger)
Definition convenience.h:18

◆ parseInput()

QValidator::State FormatDateTime::parseInput ( CoordUnitsDate coordUnitsDate,
CoordUnitsTime coordUnitsTime,
const QString & stringUntrimmed,
double & value ) const

Parse the input string into a time value.

Success flag is false if parsing failed. Leading/trailing spaces are trimmed (=ignored)

Definition at line 425 of file FormatDateTime.cpp.

429{
430 LOG4CPP_INFO_S ((*mainCat)) << "FormatDateTime::parseInput"
431 << " date=" << coordUnitsDateToString (coordUnitsDate).toLatin1().data()
432 << " time=" << coordUnitsTimeToString (coordUnitsTime).toLatin1().data()
433 << " string=" << stringUntrimmed.toLatin1().data();
434
435 const bool USE_QREGEXP = true, DO_NOT_USE_QREGEXP = false;
436
437 const QString string = stringUntrimmed.trimmed();
438
439 QValidator::State state;
440 if (string.isEmpty()) {
441
442 state = QValidator::Intermediate;
443
444 } else {
445
446 state = QValidator::Invalid;
447
448 // First see if value is acceptable
449 bool success = false;
450 dateTimeLookup (m_formatsDateParseAcceptable,
451 m_formatsTimeParseAcceptable,
452 coordUnitsDate,
453 coordUnitsTime,
454 string,
456 value,
457 success);
458 if (success) {
459
460 state = QValidator::Acceptable;
461
462 } else {
463
464 // Not acceptable, but perhaps it is just incomplete
465 dateTimeLookup (m_formatsDateParseIncomplete,
466 m_formatsTimeParseIncomplete,
467 coordUnitsDate,
468 coordUnitsTime,
469 string,
471 value,
472 success);
473 if (success) {
474
475 state = QValidator::Intermediate;
476
477 }
478 }
479 }
480
481 return state;
482}
QString coordUnitsDateToString(CoordUnitsDate coordUnits)
QString coordUnitsTimeToString(CoordUnitsTime coordUnits)

The documentation for this class was generated from the following files: