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 if (value > 0) {
144 dt = fromSecsSinceEpoch ((unsigned long int) (value));
145 } else {
146 dt = fromSecsSinceEpoch ((long int) (value));
147 }
148
149 return dt.toLocalTime ().toString (format); // Convert using local time to prevent addition of utc offset
150}
#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 443 of file FormatDateTime.cpp.

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

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