Qt 4.8
Public Functions | List of all members
QPatternist::DateTimeDurationMathematician Class Reference

Performs arithmetics between an AbstractDateTime value and an AbstractDuration value. More...

#include <qatomicmathematicians_p.h>

Inheritance diagram for QPatternist::DateTimeDurationMathematician:
QPatternist::AtomicMathematician QPatternist::DelegatingSourceLocationReflection QPatternist::AtomicTypeVisitorResult QPatternist::SourceLocationReflection QSharedData

Public Functions

virtual Item calculate (const Item &o1, const Operator op, const Item &o2, const QExplicitlySharedDataPointer< DynamicContext > &context) const
 
 DateTimeDurationMathematician (const SourceLocationReflection *const r)
 
- Public Functions inherited from QPatternist::AtomicMathematician
virtual ~AtomicMathematician ()
 
- Public Functions inherited from QPatternist::AtomicTypeVisitorResult
 AtomicTypeVisitorResult ()
 
virtual ~AtomicTypeVisitorResult ()
 
- Public Functions inherited from QSharedData
 QSharedData ()
 Constructs a QSharedData object with a reference count of 0. More...
 
 QSharedData (const QSharedData &)
 Constructs a QSharedData object with reference count 0. More...
 
- Public Functions inherited from QPatternist::DelegatingSourceLocationReflection
virtual const SourceLocationReflectionactualReflection () const
 
 DelegatingSourceLocationReflection (const SourceLocationReflection *const r)
 
virtual QString description () const
 
- Public Functions inherited from QPatternist::SourceLocationReflection
virtual QSourceLocation sourceLocation () const
 
 SourceLocationReflection ()
 
virtual ~SourceLocationReflection ()
 

Additional Inherited Members

- Public Types inherited from QPatternist::AtomicMathematician
enum  Operator {
  Div = 1, IDiv = 2, Substract = 4, Mod = 8,
  Multiply = 16, Add = 32
}
 
typedef QFlags< OperatorOperators
 
typedef QExplicitlySharedDataPointer< AtomicMathematicianPtr
 
- Public Types inherited from QPatternist::AtomicTypeVisitorResult
typedef QExplicitlySharedDataPointer< AtomicTypeVisitorResultPtr
 
- Static Public Functions inherited from QPatternist::AtomicMathematician
static QString displayName (const AtomicMathematician::Operator op)
 
- Public Variables inherited from QSharedData
QAtomicInt ref
 

Detailed Description

Performs arithmetics between an AbstractDateTime value and an AbstractDuration value.

Author
Frans Englich frans.nosp@m..eng.nosp@m.lich@.nosp@m.noki.nosp@m.a.com

Definition at line 210 of file qatomicmathematicians_p.h.

Constructors and Destructors

◆ DateTimeDurationMathematician()

QPatternist::DateTimeDurationMathematician::DateTimeDurationMathematician ( const SourceLocationReflection *const  r)
inline

Definition at line 215 of file qatomicmathematicians_p.h.

216  {
217  }
DelegatingSourceLocationReflection(const SourceLocationReflection *const r)

Functions

◆ calculate()

Item DateTimeDurationMathematician::calculate ( const Item o1,
const Operator  op,
const Item o2,
const QExplicitlySharedDataPointer< DynamicContext > &  context 
) const
virtual

o1 is an AbstractDateTime and o2 is an AbstractDuration.

Implements QPatternist::AtomicMathematician.

Definition at line 306 of file qatomicmathematicians.cpp.

310 {
311  Q_ASSERT(op == Substract || op == Add);
312 
313  const AbstractDateTime::Ptr adt(o1.as<AbstractDateTime>());
314  const AbstractDuration::Ptr dur(o2.as<AbstractDuration>());
315  QDateTime dt(adt->toDateTime());
316  //pDebug() << "DateTimeDurationMathematician::calculate():" << dt.toString();
317  //dt.setDateOnly(false);
318  const qint8 sign = (op == Add ? 1 : -1) * (dur->isPositive() ? 1 : -1);
319 
320  // TODO milli seconds
321  dt = dt.addSecs(sign * (dur->seconds() + dur->minutes() * 60 + dur->hours() * 60 * 60));
322  dt = dt.addDays(sign * dur->days());
323  dt = dt.addMonths(sign * dur->months());
324  dt = dt.addYears(sign * dur->years());
325 
326  QString msg;
327 
328  if(AbstractDateTime::isRangeValid(dt.date(), msg))
329  return adt->fromValue(dt);
330  else
331  {
332  context->error(msg, ReportContext::FODT0001,
333  this);
334  return Item();
335  }
336 }
Base class for classes implementing durations.
Base class for classes implementing values related to time, date or both.
The QExplicitlySharedDataPointer class represents a pointer to an explicitly shared object...
Definition: qshareddata.h:136
The QString class provides a Unicode character string.
Definition: qstring.h:83
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
static int sign(int x)
signed char qint8
Definition: qglobal.h:933
void error(const QString &message, const ReportContext::ErrorCode errorCode, const QSourceLocation &sourceLocation)
The QDateTime class provides date and time functions.
Definition: qdatetime.h:216
Represents an item in the XPath 2.0 Data Model.
Definition: qitem_p.h:182
static bool isRangeValid(const QDate &date, QString &message)
TCastTarget * as() const
Definition: qitem_p.h:278

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