DateTimeNode.h
/* -*- mode: c++; indent-tabs-mode: nil -*- */
/*
DateTimeNode.h
DateTimeNode Class Definition
Qore Programming Language
Copyright (C) 2003 - 2021 Qore Technologies, s.r.o.
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
Note that the Qore library is released under a choice of three open-source
licenses: MIT (as above), LGPL 2+, or GPL 2+; see README-LICENSE for more
information.
*/
#ifndef _QORE_DATETIMENODE_H
#define _QORE_DATETIMENODE_H
#include <qore/AbstractQoreNode.h>
#include <qore/DateTime.h>
class qore_date_private;
class LocalVar;
class DateTimeNode : public SimpleValueQoreNode, public DateTime {
private:
DLLLOCAL DateTimeNode(const DateTime*) = delete;
DLLLOCAL DateTimeNode& operator=(const DateTimeNode&) = delete;
DLLEXPORT virtual bool getAsBoolImpl() const;
DLLEXPORT virtual int getAsIntImpl() const;
DLLEXPORT virtual int64 getAsBigIntImpl() const;
DLLEXPORT virtual double getAsFloatImpl() const;
DLLLOCAL DateTimeNode(qore_date_private* n_priv);
protected:
DLLEXPORT virtual ~DateTimeNode();
public:
DLLEXPORT DateTimeNode(bool r = false);
DLLEXPORT DateTimeNode(int n_year, int n_month, int n_day, int n_hour = 0, int n_minute = 0, int n_second = 0, short n_ms = 0, bool n_relative = false);
DLLEXPORT DateTimeNode(int64 seconds);
DLLEXPORT DateTimeNode(int64 seconds, int ms);
DLLEXPORT explicit DateTimeNode(const AbstractQoreZoneInfo* zone, const QoreValue v);
DLLEXPORT explicit DateTimeNode(const QoreValue v);
DLLEXPORT DateTimeNode(const char* date);
DLLEXPORT DateTimeNode(const char* date, ExceptionSink* xsink);
DLLEXPORT DateTimeNode(const AbstractQoreZoneInfo* zone, const char* date);
DLLEXPORT DateTimeNode(struct tm* tms);
DLLEXPORT DateTimeNode(const DateTimeNode& dt);
DLLEXPORT DateTimeNode(const DateTime& dt);
DLLEXPORT virtual QoreString* getStringRepresentation(bool& del) const;
DLLEXPORT virtual void getStringRepresentation(QoreString& str) const;
DLLEXPORT virtual DateTime* getDateTimeRepresentation(bool& del) const;
DLLEXPORT virtual void getDateTimeRepresentation(DateTime& dt) const;
DLLEXPORT virtual QoreString* getAsString(bool& del, int foff, ExceptionSink* xsink) const;
DLLEXPORT virtual int getAsString(QoreString& str, int foff, ExceptionSink* xsink) const;
DLLEXPORT virtual AbstractQoreNode* realCopy() const;
DLLEXPORT virtual bool is_equal_soft(const AbstractQoreNode* v, ExceptionSink* xsink) const;
DLLEXPORT virtual bool is_equal_hard(const AbstractQoreNode* v, ExceptionSink* xsink) const;
DLLEXPORT virtual const char* getTypeName() const;
DLLEXPORT DateTimeNode* copy() const;
DLLEXPORT DateTimeNode* add(const DateTime* dt) const;
DLLEXPORT DateTimeNode* add(const DateTime& dt) const;
DLLEXPORT DateTimeNode* subtractBy(const DateTime* dt) const;
DLLEXPORT DateTimeNode* subtractBy(const DateTime& dt) const;
DLLEXPORT DateTimeNode* unaryMinus() const;
DLLEXPORT DateTimeNode* refSelf() const;
DLLEXPORT virtual int parseInit(QoreValue& val, QoreParseContext& parse_context);
DLLLOCAL static const char* getStaticTypeName() {
return "date";
}
DLLLOCAL static qore_type_t getStaticTypeCode() {
return NT_DATE;
}
DLLEXPORT static DateTimeNode* getDateFromISOWeek(int year, int week, int day, ExceptionSink* xsink);
DLLEXPORT static DateTimeNode* makeAbsolute(const AbstractQoreZoneInfo* n_zone, int n_year, int n_month, int n_day, int n_hour = 0, int n_minute = 0, int n_second = 0, int n_us = 0);
DLLEXPORT static DateTimeNode* makeAbsolute(const AbstractQoreZoneInfo* n_zone, int n_year, int n_month, int n_day, int n_hour, int n_minute, int n_second, int n_us, ExceptionSink* xsink);
DLLEXPORT static DateTimeNode* makeAbsolute(const AbstractQoreZoneInfo* zone, int64 seconds, int us = 0);
DLLEXPORT static DateTimeNode* makeAbsoluteLocal(const AbstractQoreZoneInfo* zone, int64 seconds, int us = 0);
DLLEXPORT static DateTimeNode* makeRelative(int n_year, int n_month, int n_day, int n_hour = 0, int n_minute = 0, int n_second = 0, int n_us = 0);
DLLEXPORT static DateTimeNode* makeRelativeFromSeconds(int64 n_second, int n_us = 0);
};
DLLEXPORT extern DateTimeNode* ZeroDate;
DLLEXPORT extern DateTimeNode* OneDate;
class DateTimeValueHelper {
private:
const DateTime* dt;
bool del;
DLLLOCAL DateTimeValueHelper(const DateTimeValueHelper&); // not implemented
DLLLOCAL DateTimeValueHelper& operator=(const DateTimeValueHelper&); // not implemented
DLLLOCAL void* operator new(size_t); // not implemented, make sure it is not new'ed
public:
DLLEXPORT DateTimeValueHelper(const AbstractQoreNode* n);
DLLEXPORT DateTimeValueHelper(const QoreValue& n);
DLLEXPORT ~DateTimeValueHelper();
DLLLOCAL const DateTime* operator->() { return dt; }
DLLLOCAL const DateTime* operator*() { return dt; }
};
class DateTimeNodeValueHelper {
private:
DateTimeNode* dt;
bool del;
DLLLOCAL DateTimeNodeValueHelper(const DateTimeNodeValueHelper&); // not implemented
DLLLOCAL DateTimeNodeValueHelper& operator=(const DateTimeNodeValueHelper&); // not implemented
DLLLOCAL void* operator new(size_t); // not implemented, make sure it is not new'ed
public:
DLLLOCAL DateTimeNodeValueHelper(const AbstractQoreNode* n) {
if (!n) {
dt = ZeroDate;
del = false;
return;
}
// optmization without virtual function call for most common case
if (n->getType() == NT_DATE) {
dt = const_cast<DateTimeNode*>(reinterpret_cast<const DateTimeNode*>(n));
del = false;
return;
}
dt = new DateTimeNode;
n->getDateTimeRepresentation(*dt);
del = true;
}
DLLLOCAL DateTimeNodeValueHelper(const AbstractQoreNode* n, ExceptionSink* xsink);
DLLEXPORT DateTimeNodeValueHelper(const QoreValue& n);
DLLLOCAL ~DateTimeNodeValueHelper() {
if (dt && del)
dt->deref();
}
DLLLOCAL const DateTimeNode* operator->() { return dt; }
DLLLOCAL const DateTimeNode* operator*() { return dt; }
DLLLOCAL DateTimeNode* getReferencedValue() {
if (del)
del = false;
else if (dt)
dt->ref();
return dt;
}
};
#endif
DateTimeNode::makeRelative
static DLLEXPORT DateTimeNode * makeRelative(int n_year, int n_month, int n_day, int n_hour=0, int n_minute=0, int n_second=0, int n_us=0)
static "constructor" to create a relative time, including microseconds
AbstractQoreNode::getType
DLLLOCAL qore_type_t getType() const
returns the data type
Definition: AbstractQoreNode.h:175
DateTimeNode::unaryMinus
DLLEXPORT DateTimeNode * unaryMinus() const
returns the negative time from the current time
DateTime
Holds absolute and relative date/time values in Qore with precision to the microsecond.
Definition: DateTime.h:93
AbstractQoreNode
The base class for all value and parse types in Qore expression trees.
Definition: AbstractQoreNode.h:57
DateTimeNode::makeRelativeFromSeconds
static DLLEXPORT DateTimeNode * makeRelativeFromSeconds(int64 n_second, int n_us=0)
static "constructor" to create a relative time, including microseconds
DateTimeNode::getDateTimeRepresentation
virtual DLLEXPORT DateTime * getDateTimeRepresentation(bool &del) const
returns "this" as a DateTime, del is set to false
DateTimeNodeValueHelper::~DateTimeNodeValueHelper
DLLLOCAL ~DateTimeNodeValueHelper()
dereferences the DateTimeNode value if necessary
Definition: DateTimeNode.h:394
NT_DATE
const qore_type_t NT_DATE
type value for DateTimeNode
Definition: node_types.h:46
DateTimeNode::subtractBy
DLLEXPORT DateTimeNode * subtractBy(const DateTime *dt) const
subtracts a DateTime value from the current value and returns the new value, the caller owns the poin...
DateTimeNode::getStaticTypeName
static DLLLOCAL const char * getStaticTypeName()
returns the type name (useful in templates)
Definition: DateTimeNode.h:267
DateTimeNode::~DateTimeNode
virtual DLLEXPORT ~DateTimeNode()
protected destructor only called when references = 0, use deref() instead
QoreString
Qore&#39;s string type supported by the QoreEncoding class.
Definition: QoreString.h:81
DateTimeNode::getAsString
virtual DLLEXPORT QoreString * getAsString(bool &del, int foff, ExceptionSink *xsink) const
returns the date/time value as a formatted string for n and N printf formatting, del is set to true ...
DateTimeNode::getStaticTypeCode
static DLLLOCAL qore_type_t getStaticTypeCode()
returns the type code (useful in templates)
Definition: DateTimeNode.h:272
DateTimeValueHelper
manages calls to AbstractQoreNode::getDateTimeRepresentation() when a simple DateTime value is requir...
Definition: DateTimeNode.h:326
DateTimeNode::parseInit
virtual DLLEXPORT int parseInit(QoreValue &val, QoreParseContext &parse_context)
returns the type information
DateTimeNode::copy
DLLEXPORT DateTimeNode * copy() const
returns a copy of the DateTimeNode, the caller owns the pointer&#39;s reference count ...
DateTimeNode
Qore&#39;s parse tree/value type for date-time values, reference-counted, dynamically-allocated only...
Definition: DateTimeNode.h:45
QoreValue
The main value class in Qore, designed to be passed by value.
Definition: QoreValue.h:267
AbstractQoreNode::getDateTimeRepresentation
virtual DLLEXPORT class DateTime * getDateTimeRepresentation(bool &del) const
returns the DateTime representation of this type (default implementation: returns ZeroDate...
ExceptionSink
container for holding Qore-language exception information and also for registering a "thread_exit" ca...
Definition: ExceptionSink.h:48
DateTimeNode::refSelf
DLLEXPORT DateTimeNode * refSelf() const
returns this with an incremented ref count
DateTimeNode::is_equal_soft
virtual DLLEXPORT bool is_equal_soft(const AbstractQoreNode *v, ExceptionSink *xsink) const
tests for equality with possible type conversion (soft compare)
DateTimeValueHelper::~DateTimeValueHelper
DLLEXPORT ~DateTimeValueHelper()
deletes the DateTime value being managed if necessary
int64
long long int64
64bit integer type, cannot use int64_t here since it breaks the API on some 64-bit systems due to equ...
Definition: common.h:260
DateTimeNode::getStringRepresentation
virtual DLLEXPORT QoreString * getStringRepresentation(bool &del) const
returns a string in the format YYYYMMDDHHmmSS, del is set to true
AbstractQoreNode::ref
DLLEXPORT void ref() const
increments the reference count
DateTimeNodeValueHelper
manages calls to AbstractQoreNode::getDateTimeRepresentation() when a DateTimeNode value is required ...
Definition: DateTimeNode.h:353
DateTimeNodeValueHelper::getReferencedValue
DLLLOCAL DateTimeNode * getReferencedValue()
returns a referenced value - the caller will own the reference
Definition: DateTimeNode.h:407
DateTimeNode::makeAbsoluteLocal
static DLLEXPORT DateTimeNode * makeAbsoluteLocal(const AbstractQoreZoneInfo *zone, int64 seconds, int us=0)
static "constructor" to create an absolute time as an offset from the given time zone&#39;s epoch...
qore_type_t
int16_t qore_type_t
used to identify unique Qore data and parse types (descendents of AbstractQoreNode) ...
Definition: common.h:70
DateTimeNode::getDateFromISOWeek
static DLLEXPORT DateTimeNode * getDateFromISOWeek(int year, int week, int day, ExceptionSink *xsink)
returns a DateTimeNode value as generated from the ISO-8601 week information
DateTimeNode::add
DLLEXPORT DateTimeNode * add(const DateTime *dt) const
adds a DateTime value to the current value and returns the new value, the caller owns the pointer&#39;s r...
SimpleValueQoreNode
base class for simple value types
Definition: AbstractQoreNode.h:372
DateTimeNode::realCopy
virtual DLLEXPORT AbstractQoreNode * realCopy() const
returns a copy of the object; the caller owns the reference count
DateTimeNode::getTypeName
virtual DLLEXPORT const char * getTypeName() const
returns the type name as a c string
DateTimeNode::is_equal_hard
virtual DLLEXPORT bool is_equal_hard(const AbstractQoreNode *v, ExceptionSink *xsink) const
tests for equality ("deep compare" including all contained values for container types) without type c...
DateTimeNode::makeAbsolute
static DLLEXPORT DateTimeNode * makeAbsolute(const AbstractQoreZoneInfo *n_zone, int n_year, int n_month, int n_day, int n_hour=0, int n_minute=0, int n_second=0, int n_us=0)
static "constructor" to create an absolute time, including microseconds