Qore Programming Language 1.18.0
Loading...
Searching...
No Matches
DateTimeNode.h
1/* -*- mode: c++; indent-tabs-mode: nil -*- */
2/*
3 DateTimeNode.h
4
5 DateTimeNode Class Definition
6
7 Qore Programming Language
8
9 Copyright (C) 2003 - 2023 Qore Technologies, s.r.o.
10
11 Permission is hereby granted, free of charge, to any person obtaining a
12 copy of this software and associated documentation files (the "Software"),
13 to deal in the Software without restriction, including without limitation
14 the rights to use, copy, modify, merge, publish, distribute, sublicense,
15 and/or sell copies of the Software, and to permit persons to whom the
16 Software is furnished to do so, subject to the following conditions:
17
18 The above copyright notice and this permission notice shall be included in
19 all copies or substantial portions of the Software.
20
21 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
26 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
27 DEALINGS IN THE SOFTWARE.
28
29 Note that the Qore library is released under a choice of three open-source
30 licenses: MIT (as above), LGPL 2+, or GPL 2+; see README-LICENSE for more
31 information.
32*/
33
34#ifndef _QORE_DATETIMENODE_H
35
36#define _QORE_DATETIMENODE_H
37
38#include <qore/AbstractQoreNode.h>
39#include <qore/DateTime.h>
40
41class qore_date_private;
42class LocalVar;
43
46private:
48 DLLLOCAL DateTimeNode(const DateTime*) = delete;
49
51 DLLLOCAL DateTimeNode& operator=(const DateTimeNode&) = delete;
52
54
58 DLLEXPORT virtual bool getAsBoolImpl() const;
59
61
64 DLLEXPORT virtual int getAsIntImpl() const;
65
67
70 DLLEXPORT virtual int64 getAsBigIntImpl() const;
71
73
76 DLLEXPORT virtual double getAsFloatImpl() const;
77
79 DLLLOCAL DateTimeNode(qore_date_private* n_priv);
80
81protected:
83 DLLEXPORT virtual ~DateTimeNode();
84
85public:
87
90 DLLEXPORT DateTimeNode(bool r = false);
91
93
103 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);
104
106
109 DLLEXPORT DateTimeNode(int64 seconds);
110
112
116 DLLEXPORT DateTimeNode(int64 seconds, int ms);
117
119
125 DLLEXPORT explicit DateTimeNode(const AbstractQoreZoneInfo* zone, const QoreValue v);
126
128
131 DLLEXPORT explicit DateTimeNode(const QoreValue v);
132
134
136 DLLEXPORT DateTimeNode(const char* date);
137
139
144 DLLEXPORT DateTimeNode(const char* date, ExceptionSink* xsink);
145
147
151 DLLEXPORT DateTimeNode(const AbstractQoreZoneInfo* zone, const char* date);
152
154
157 DLLEXPORT DateTimeNode(struct tm* tms);
158
160 DLLEXPORT DateTimeNode(const DateTimeNode& dt);
161
163 DLLEXPORT DateTimeNode(const DateTime& dt);
164
166
171 DLLEXPORT virtual QoreString* getStringRepresentation(bool& del) const;
172
174
177 DLLEXPORT virtual void getStringRepresentation(QoreString& str) const;
178
180
184 DLLEXPORT virtual DateTime* getDateTimeRepresentation(bool& del) const;
185
187
190 DLLEXPORT virtual void getDateTimeRepresentation(DateTime& dt) const;
191
193
202 DLLEXPORT virtual QoreString* getAsString(bool& del, int foff, ExceptionSink* xsink) const;
203
205
212 DLLEXPORT virtual int getAsString(QoreString& str, int foff, ExceptionSink* xsink) const;
213
214 DLLEXPORT virtual AbstractQoreNode* realCopy() const;
215
217
221 DLLEXPORT virtual bool is_equal_soft(const AbstractQoreNode* v, ExceptionSink* xsink) const;
222 DLLEXPORT virtual bool is_equal_hard(const AbstractQoreNode* v, ExceptionSink* xsink) const;
223
225 DLLEXPORT virtual const char* getTypeName() const;
226
228
231 DLLEXPORT DateTimeNode* copy() const;
232
234
237 DLLEXPORT DateTimeNode* add(const DateTime* dt) const;
238
240
243 DLLEXPORT DateTimeNode* add(const DateTime& dt) const;
244
246
249 DLLEXPORT DateTimeNode* subtractBy(const DateTime* dt) const;
250
252
255 DLLEXPORT DateTimeNode* subtractBy(const DateTime& dt) const;
256
258 DLLEXPORT DateTimeNode* unaryMinus() const;
259
261 DLLEXPORT DateTimeNode* refSelf() const;
262
264 DLLEXPORT virtual int parseInit(QoreValue& val, QoreParseContext& parse_context);
265
267 DLLLOCAL static const char* getStaticTypeName() {
268 return "date";
269 }
270
272 DLLLOCAL static qore_type_t getStaticTypeCode() {
273 return NT_DATE;
274 }
275
277
284 DLLEXPORT static DateTimeNode* getDateFromISOWeek(int year, int week, int day, ExceptionSink* xsink);
285
287 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);
288
290
292 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);
293
295
300 DLLEXPORT static DateTimeNode* makeAbsolute(const AbstractQoreZoneInfo* zone, int64 seconds, int us = 0);
301
303
308 DLLEXPORT static DateTimeNode* makeAbsoluteLocal(const AbstractQoreZoneInfo* zone, int64 seconds, int us = 0);
309
311 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);
312
314 DLLEXPORT static DateTimeNode* makeRelativeFromSeconds(int64 n_second, int n_us = 0);
315};
316
317DLLEXPORT extern DateTimeNode* ZeroDate;
318DLLEXPORT extern DateTimeNode* OneDate;
319
321
327public:
330
332 DLLEXPORT DateTimeValueHelper(const QoreValue& n);
333
336
337 DLLLOCAL const DateTime* operator->() { return dt; }
338 DLLLOCAL const DateTime* operator*() { return dt; }
339
340private:
341 const DateTime* dt;
342 bool del;
343
344 DLLLOCAL DateTimeValueHelper(const DateTimeValueHelper&) = delete;
345 DLLLOCAL DateTimeValueHelper& operator=(const DateTimeValueHelper&) = delete;
346 DLLLOCAL static void* operator new(size_t) = delete;
347};
348
350
354public:
357 if (!n) {
358 dt = ZeroDate;
359 del = false;
360 return;
361 }
362
363 // optmization without virtual function call for most common case
364 if (n->getType() == NT_DATE) {
365 dt = const_cast<DateTimeNode*>(reinterpret_cast<const DateTimeNode*>(n));
366 del = false;
367 return;
368 }
369
370 dt = new DateTimeNode;
372 del = true;
373 }
374
376
381
384
387 if (dt && del)
388 dt->deref();
389 }
390
391 DLLLOCAL const DateTimeNode* operator->() { return dt; }
392 DLLLOCAL const DateTimeNode* operator*() { return dt; }
393
395
400 if (del)
401 del = false;
402 else if (dt)
403 dt->ref();
404 return dt;
405 }
406
407private:
408 DateTimeNode* dt;
409 bool del;
410
411 DLLLOCAL DateTimeNodeValueHelper(const DateTimeNodeValueHelper&) = delete;
412 DLLLOCAL DateTimeNodeValueHelper& operator=(const DateTimeNodeValueHelper&) = delete;
413 DLLLOCAL static void* operator new(size_t) = delete;
414};
415
416#endif
The base class for all value and parse types in Qore expression trees.
Definition: AbstractQoreNode.h:57
DLLEXPORT void ref() const
increments the reference count
virtual DLLEXPORT class DateTime * getDateTimeRepresentation(bool &del) const
returns the DateTime representation of this type (default implementation: returns ZeroDate,...
DLLLOCAL qore_type_t getType() const
returns the data type
Definition: AbstractQoreNode.h:175
Holds absolute and relative date/time values in Qore with precision to the microsecond.
Definition: DateTime.h:93
Qore's parse tree/value type for date-time values, reference-counted, dynamically-allocated only.
Definition: DateTimeNode.h:45
static DLLLOCAL qore_type_t getStaticTypeCode()
returns the type code (useful in templates)
Definition: DateTimeNode.h:272
DLLEXPORT DateTimeNode(const char *date, ExceptionSink *xsink)
constructor for setting the date from a string with a flexible format, throws a Qore-language excepti...
DLLEXPORT DateTimeNode(const QoreValue v)
constructor for creating a relative date from a value representing a number of seconds
virtual DLLEXPORT AbstractQoreNode * realCopy() const
returns a copy of the object; the caller owns the reference count
DLLEXPORT DateTimeNode(const AbstractQoreZoneInfo *zone, const QoreValue v)
constructor for creating an absolute date from a value representing a number of seconds
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's epoch,...
virtual DLLEXPORT int getAsString(QoreString &str, int foff, ExceptionSink *xsink) const
concatenates a string representation of the date/time value (designed for n and N printf formatting) ...
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's r...
DLLEXPORT DateTimeNode * unaryMinus() const
returns the negative time from the current time
DLLEXPORT DateTimeNode * refSelf() const
returns this with an incremented ref count
static DLLEXPORT DateTimeNode * makeRelativeFromSeconds(int64 n_second, int n_us=0)
static "constructor" to create a relative time, including microseconds
static DLLEXPORT DateTimeNode * makeAbsolute(const AbstractQoreZoneInfo *zone, int64 seconds, int us=0)
static "constructor" to create an absolute time as an offset from the epoch, including microseconds
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's r...
DLLEXPORT DateTimeNode(const AbstractQoreZoneInfo *zone, const char *date)
constructor for setting the date from a string with a flexible format
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)
constructor for setting all parameters
DLLEXPORT DateTimeNode(int64 seconds, int ms)
constructor for setting an absolute date based on the number of seconds from January 1,...
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
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...
DLLEXPORT DateTimeNode(const char *date)
constructor for setting the date from a string with a flexible format, silently accepts invalid date ...
virtual DLLEXPORT bool is_equal_soft(const AbstractQoreNode *v, ExceptionSink *xsink) const
tests for equality with possible type conversion (soft compare)
virtual DLLEXPORT void getStringRepresentation(QoreString &str) const
concatentates the date/time value in the format YYYYMMDDHHmmDD to an existing QoreString reference
static DLLEXPORT 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)
static "constructor" to create an absolute time, including microseconds, throws an exception with inv...
virtual DLLEXPORT int parseInit(QoreValue &val, QoreParseContext &parse_context)
returns the type information
virtual DLLEXPORT QoreString * getStringRepresentation(bool &del) const
returns a string in the format YYYYMMDDHHmmSS, del is set to true
DLLEXPORT DateTimeNode(hashdecl tm *tms)
constructor for setting an absolute date based on a "hashdecl tm"
static DLLEXPORT DateTimeNode * getDateFromISOWeek(int year, int week, int day, ExceptionSink *xsink)
returns a DateTimeNode value as generated from the ISO-8601 week information
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...
virtual DLLEXPORT DateTime * getDateTimeRepresentation(bool &del) const
returns "this" as a DateTime, del is set to false
DLLEXPORT DateTimeNode * copy() const
returns a copy of the DateTimeNode, the caller owns the pointer's reference count
DLLEXPORT DateTimeNode(const DateTime &dt)
constructor to set the date from a DateTime value
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
virtual DLLEXPORT const char * getTypeName() const
returns the type name as a c string
DLLEXPORT DateTimeNode(bool r=false)
constructor for an empty object
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...
DLLEXPORT DateTimeNode(int64 seconds)
constructor for setting an absolute date based on the number of seconds from January 1,...
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
static DLLLOCAL const char * getStaticTypeName()
returns the type name (useful in templates)
Definition: DateTimeNode.h:267
DLLEXPORT DateTimeNode(const DateTimeNode &dt)
copy constructor
virtual DLLEXPORT void getDateTimeRepresentation(DateTime &dt) const
assigns this date/time representation to the passed DateTime reference
virtual DLLEXPORT ~DateTimeNode()
protected destructor only called when references = 0, use deref() instead
manages calls to AbstractQoreNode::getDateTimeRepresentation() when a DateTimeNode value is required
Definition: DateTimeNode.h:353
DLLLOCAL DateTimeNodeValueHelper(const AbstractQoreNode *n, ExceptionSink *xsink)
gets the DateTimeNode value and sets the temporary flag
DLLLOCAL DateTimeNode * getReferencedValue()
returns a referenced value - the caller will own the reference
Definition: DateTimeNode.h:399
DLLLOCAL ~DateTimeNodeValueHelper()
dereferences the DateTimeNode value if necessary
Definition: DateTimeNode.h:386
DLLLOCAL DateTimeNodeValueHelper(const AbstractQoreNode *n)
gets the DateTimeNode value and sets the temporary flag
Definition: DateTimeNode.h:356
DLLEXPORT DateTimeNodeValueHelper(const QoreValue &n)
gets the DateTime value and set the delete flag
manages calls to AbstractQoreNode::getDateTimeRepresentation() when a simple DateTime value is requir...
Definition: DateTimeNode.h:326
DLLEXPORT DateTimeValueHelper(const QoreValue &n)
gets the DateTime value and set the delete flag
DLLEXPORT DateTimeValueHelper(const AbstractQoreNode *n)
gets the DateTime value and set the delete flag
DLLEXPORT ~DateTimeValueHelper()
deletes the DateTime value being managed if necessary
container for holding Qore-language exception information and also for registering a "thread_exit" ca...
Definition: ExceptionSink.h:50
Qore's string type supported by the QoreEncoding class.
Definition: QoreString.h:93
base class for simple value types
Definition: AbstractQoreNode.h:372
int16_t qore_type_t
used to identify unique Qore data and parse types (descendents of AbstractQoreNode)
Definition: common.h:70
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
const qore_type_t NT_DATE
type value for DateTimeNode
Definition: node_types.h:46
The main value class in Qore, designed to be passed by value.
Definition: QoreValue.h:276