Commit 9eec1a07 authored by Stefan Gerlach's avatar Stefan Gerlach

fix converting double to date time and vice versa

parent 3fcfdabf
......@@ -40,10 +40,11 @@ class DateTime2DoubleFilter : public AbstractSimpleFilter {
public:
virtual double valueAt(int row) const {
if (!m_inputs.value(0)) return NAN;
QDateTime input_value = m_inputs.value(0)->dateTimeAt(row);
if (!input_value.isValid()) return NAN;
return double(input_value.date().toJulianDay()) +
double( -input_value.time().msecsTo(QTime(12,0,0,0)) ) / 86400000.0;
QDateTime inputDate = m_inputs.value(0)->dateTimeAt(row);
if (!inputDate.isValid()) return NAN;
QDateTime start(QDate(1900, 1, 1));
return double(start.daysTo(inputDate)) +
double( -inputDate.time().msecsTo(QTime(0,0,0,0)) ) / 86400000.0;
}
//! Return the data type of the column
......@@ -51,7 +52,7 @@ public:
protected:
//! Using typed ports: only DateTime inputs are accepted.
virtual bool inputAcceptable(int, const AbstractColumn *source) {
virtual bool inputAcceptable(int, const AbstractColumn* source) {
return source->columnMode() == AbstractColumn::DateTime;
}
};
......
......@@ -43,15 +43,16 @@ public:
if (!m_inputs.value(0)) return QDate();
double inputValue = m_inputs.value(0)->valueAt(row);
if (std::isnan(inputValue)) return QDate();
return QDate::fromJulianDay(qRound(inputValue));
//QDEBUG(" convert " << inputValue << " to " << QDate(1900, 1, int(inputValue)));
return QDate(1900, 1, 1 + int(inputValue));
}
virtual QTime timeAt(int row) const {
if (!m_inputs.value(0)) return QTime();
double inputValue = m_inputs.value(0)->valueAt(row);
if (std::isnan(inputValue)) return QTime();
// we only want the digits behind the dot and
// convert them from fraction of day to milliseconds
return QTime(12,0,0,0).addMSecs(int( (inputValue - int(inputValue)) * 86400000.0 ));
// we only want the digits behind the dot and convert them from fraction of day to milliseconds
//QDEBUG(" convert " << inputValue << " to " << QTime(0,0,0,0).addMSecs(int( (inputValue - int(inputValue)) * 86400000.0 )));
return QTime(0,0,0,0).addMSecs(int( (inputValue - int(inputValue)) * 86400000.0 ));
}
virtual QDateTime dateTimeAt(int row) const {
return QDateTime(dateAt(row), timeAt(row));
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment