scidavis  2.3.0
About: SciDAVis is a free application for Scientific Data Analysis and Visualization (a fork off of QtiPlot).
  Fossies Dox: scidavis-2.3.0.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

Double2DateTimeFilter.cpp
Go to the documentation of this file.
1 
10 
29 #include "Double2DateTimeFilter.h"
30 
31 #include <math.h>
32 
33 QDateTime Double2DateTimeFilter::dateTimeAt(int row) const {
34  if (!d_inputs.value(0)) return QDateTime();
35  double input_value = d_inputs.value(0)->valueAt(row);
36  QDateTime result;
37  // This gets a little messy, since QDate can't represent the reference date of JDN.
38  // Thus, we manually interpret invalid dates as JDN reference.
39  switch (m_unit_interval) {
40  case Year:
41  if (m_date_time_0.isValid())
42  result = m_date_time_0.addYears(int(floor(input_value)));
43  else {
44  result.setDate(QDate(int(floor(input_value))+4713, 1, 1));
45  result.setTime(QTime(12,0,0,0));
46  }
47  return result.addMSecs(qRound64((input_value - int(floor(input_value))) *
48  result.date().daysInYear() * 86400000.0));
49  case Month:
50  if (m_date_time_0.isValid())
51  result = m_date_time_0.addMonths(int(floor(input_value)));
52  else {
53  result.setDate(QDate(int(floor(input_value))/12+4713, int(floor(input_value))%12+1, 1));
54  result.setTime(QTime(12,0,0,0));
55  }
56  return result.addMSecs(qRound64((input_value - int(floor(input_value))) *
57  result.date().daysInMonth() * 86400000.0));
58  case Day:
59  if (m_date_time_0.isValid())
60  result = m_date_time_0.addDays(int(floor(input_value)));
61  else {
62  result.setDate(QDate::fromJulianDay(int(floor(input_value))));
63  result.setTime(QTime(12,0,0,0));
64  }
65  return result.addMSecs(qRound64((input_value - int(floor(input_value))) * 86400000.0));
66  case Hour:
67  if (m_date_time_0.isValid())
68  return m_date_time_0.addMSecs(qRound64(input_value * 3600000.0));
69  else {
70  result.setDate(QDate::fromJulianDay(int(floor(input_value)) / 24));
71  result.setTime(QTime(12,0,0,0));
72  result = result.addSecs((int(floor(input_value)) % 24) * 3600);
73  return result.addMSecs(qRound64((input_value - int(floor(input_value))) * 3600000.0));
74  }
75  case Minute:
76  if (m_date_time_0.isValid())
77  return m_date_time_0.addMSecs(qRound64(input_value * 60000.0));
78  else {
79  result.setDate(QDate::fromJulianDay(int(floor(input_value)) / (24 * 60)));
80  result.setTime(QTime(12,0,0,0));
81  result = result.addSecs((int(floor(input_value)) % (24 * 60)) * 60);
82  return result.addMSecs(qRound64((input_value - int(floor(input_value))) * 60000.0));
83  }
84  case Second:
85  if (m_date_time_0.isValid())
86  return m_date_time_0.addMSecs(qRound64(input_value * 1000.0));
87  else {
88  result.setDate(QDate::fromJulianDay(int(floor(input_value)) / (24 * 60 * 60)));
89  result.setTime(QTime(12,0,0,0));
90  result = result.addSecs(int(floor(input_value)) % (24 * 60 * 60));
91  return result.addMSecs(qRound64((input_value - int(floor(input_value))) * 1000.0));
92  }
93  case Millisecond:
94  if (m_date_time_0.isValid())
95  return m_date_time_0.addMSecs(qRound64(input_value));
96  else {
97  result.setDate(QDate::fromJulianDay(int(floor(input_value)) / (24 * 60 * 60)));
98  result.setTime(QTime(12,0,0,0));
99  result = result.addSecs(int(floor(input_value)) % (24 * 60 * 60));
100  return result.addMSecs(qRound64((input_value - int(floor(input_value))) * 1000.0));
101  }
102  }
103  return result;
104 }
105 
Double2DateTimeFilter.h
Double2DateTimeFilter::Minute
@ Minute
Definition: Double2DateTimeFilter.h:50
Double2DateTimeFilter::m_date_time_0
QDateTime m_date_time_0
Definition: Double2DateTimeFilter.h:76
Double2DateTimeFilter::Month
@ Month
Definition: Double2DateTimeFilter.h:50
Double2DateTimeFilter::Hour
@ Hour
Definition: Double2DateTimeFilter.h:50
Double2DateTimeFilter::dateTimeAt
virtual QDateTime dateTimeAt(int row) const
Definition: Double2DateTimeFilter.cpp:33
Double2DateTimeFilter::Second
@ Second
Definition: Double2DateTimeFilter.h:50
Double2DateTimeFilter::Millisecond
@ Millisecond
Definition: Double2DateTimeFilter.h:50
Double2DateTimeFilter::Day
@ Day
Definition: Double2DateTimeFilter.h:50
AbstractFilter::d_inputs
QVector< const AbstractColumn * > d_inputs
The data sources connected to my input ports.
Definition: AbstractFilter.h:275
Double2DateTimeFilter::m_unit_interval
UnitInterval m_unit_interval
Definition: Double2DateTimeFilter.h:75
Double2DateTimeFilter::Year
@ Year
Definition: Double2DateTimeFilter.h:50