Engauge Digitizer 2
Loading...
Searching...
No Matches
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 14 of file FormatDateTime.cpp.

15{
16 loadFormatsFormat();
17 loadFormatsParseAcceptable();
18 loadFormatsParseIncomplete();
19}

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 // We are using 64 bits resolution on seconds from epoch rather than time_t which has 32 bits resolution (and
141 // is therefore limited to 1970 to 2038). Time value is negative for pre-epoch. Grep for toSecsSinceEpoch in this same file
142 QDateTime dt;
143 dt = fromSecsSinceEpoch (static_cast<qint64> (value));
144
145 return dt.toLocalTime ().toString (format); // Convert using local time to prevent addition of utc offset
146}
#define ENGAUGE_ASSERT(cond)
Drop in replacement for Q_ASSERT.
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 439 of file FormatDateTime.cpp.

443{
444 LOG4CPP_INFO_S ((*mainCat)) << "FormatDateTime::parseInput"
445 << " date=" << coordUnitsDateToString (coordUnitsDate).toLatin1().data()
446 << " time=" << coordUnitsTimeToString (coordUnitsTime).toLatin1().data()
447 << " string=" << stringUntrimmed.toLatin1().data();
448
449 const bool USE_QREGEXP = true, DO_NOT_USE_QREGEXP = false;
450
451 const QString string = stringUntrimmed.trimmed();
452
453 QValidator::State state;
454 if (string.isEmpty()) {
455
456 state = QValidator::Intermediate;
457
458 } else {
459
460 state = QValidator::Invalid;
461
462 // First see if value is acceptable
463 bool success = false;
464 dateTimeLookup (m_formatsDateParseAcceptable,
465 m_formatsTimeParseAcceptable,
466 coordUnitsDate,
467 coordUnitsTime,
468 string,
469 USE_QREGEXP,
470 value,
471 success);
472 if (success) {
473
474 state = QValidator::Acceptable;
475
476 } else {
477
478 // Not acceptable, but perhaps it is just incomplete
479 dateTimeLookup (m_formatsDateParseIncomplete,
480 m_formatsTimeParseIncomplete,
481 coordUnitsDate,
482 coordUnitsTime,
483 string,
484 DO_NOT_USE_QREGEXP,
485 value,
486 success);
487 if (success) {
488
489 state = QValidator::Intermediate;
490
491 }
492 }
493 }
494
495 return state;
496}
QString coordUnitsDateToString(CoordUnitsDate coordUnits)
QString coordUnitsTimeToString(CoordUnitsTime coordUnits)

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