Qore Programming Language 1.19.5
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
41DLLEXPORT const AbstractQoreZoneInfo* currentTZ();
42
43class qore_date_private;
44class LocalVar;
45
48private:
50 DLLLOCAL DateTimeNode(const DateTime*) = delete;
51
53 DLLLOCAL DateTimeNode& operator=(const DateTimeNode&) = delete;
54
56
60 DLLEXPORT virtual bool getAsBoolImpl() const;
61
63
66 DLLEXPORT virtual int getAsIntImpl() const;
67
69
72 DLLEXPORT virtual int64 getAsBigIntImpl() const;
73
75
78 DLLEXPORT virtual double getAsFloatImpl() const;
79
81 DLLLOCAL DateTimeNode(qore_date_private* n_priv);
82
83protected:
85 DLLEXPORT virtual ~DateTimeNode();
86
87public:
89
92 DLLEXPORT DateTimeNode(bool r = false);
93
95
105 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);
106
108
111 DLLEXPORT DateTimeNode(int64 seconds);
112
114
118 DLLEXPORT DateTimeNode(int64 seconds, int ms);
119
121
127 DLLEXPORT explicit DateTimeNode(const AbstractQoreZoneInfo* zone, const QoreValue v);
128
130
133 DLLEXPORT explicit DateTimeNode(const QoreValue v);
134
136
138 DLLEXPORT DateTimeNode(const char* date);
139
141
146 DLLEXPORT DateTimeNode(const char* date, ExceptionSink* xsink);
147
149
153 DLLEXPORT DateTimeNode(const AbstractQoreZoneInfo* zone, const char* date);
154
156
159 DLLEXPORT DateTimeNode(struct tm* tms);
160
162 DLLEXPORT DateTimeNode(const DateTimeNode& dt);
163
165 DLLEXPORT DateTimeNode(const DateTime& dt);
166
168
173 DLLEXPORT virtual QoreString* getStringRepresentation(bool& del) const;
174
176
179 DLLEXPORT virtual void getStringRepresentation(QoreString& str) const;
180
182
186 DLLEXPORT virtual DateTime* getDateTimeRepresentation(bool& del) const;
187
189
192 DLLEXPORT virtual void getDateTimeRepresentation(DateTime& dt) const;
193
195
204 DLLEXPORT virtual QoreString* getAsString(bool& del, int foff, ExceptionSink* xsink) const;
205
207
214 DLLEXPORT virtual int getAsString(QoreString& str, int foff, ExceptionSink* xsink) const;
215
216 DLLEXPORT virtual AbstractQoreNode* realCopy() const;
217
219
223 DLLEXPORT virtual bool is_equal_soft(const AbstractQoreNode* v, ExceptionSink* xsink) const;
224 DLLEXPORT virtual bool is_equal_hard(const AbstractQoreNode* v, ExceptionSink* xsink) const;
225
227 DLLEXPORT virtual const char* getTypeName() const;
228
230
233 DLLEXPORT DateTimeNode* copy() const;
234
236
239 DLLEXPORT DateTimeNode* add(const DateTime* dt) const;
240
242
245 DLLEXPORT DateTimeNode* add(const DateTime& dt) const;
246
248
251 DLLEXPORT DateTimeNode* subtractBy(const DateTime* dt) const;
252
254
257 DLLEXPORT DateTimeNode* subtractBy(const DateTime& dt) const;
258
260 DLLEXPORT DateTimeNode* unaryMinus() const;
261
263 DLLEXPORT DateTimeNode* refSelf() const;
264
266 DLLEXPORT virtual int parseInit(QoreValue& val, QoreParseContext& parse_context);
267
269 DLLLOCAL static const char* getStaticTypeName() {
270 return "date";
271 }
272
274 DLLLOCAL static qore_type_t getStaticTypeCode() {
275 return NT_DATE;
276 }
277
279
286 DLLEXPORT static DateTimeNode* getDateFromISOWeek(int year, int week, int day, ExceptionSink* xsink);
287
289 DLLEXPORT static DateTimeNode* makeNow(const AbstractQoreZoneInfo* zone = currentTZ());
290
292 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);
293
295
297 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);
298
300
305 DLLEXPORT static DateTimeNode* makeAbsolute(const AbstractQoreZoneInfo* zone, int64 seconds, int us = 0);
306
308
313 DLLEXPORT static DateTimeNode* makeAbsoluteLocal(const AbstractQoreZoneInfo* zone, int64 seconds, int us = 0);
314
316 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);
317
319 DLLEXPORT static DateTimeNode* makeRelativeFromSeconds(int64 n_second, int n_us = 0);
320};
321
322DLLEXPORT extern DateTimeNode* ZeroDate;
323DLLEXPORT extern DateTimeNode* OneDate;
324
326
332public:
335
337 DLLEXPORT DateTimeValueHelper(const QoreValue& n);
338
341
342 DLLLOCAL const DateTime* operator->() { return dt; }
343 DLLLOCAL const DateTime* operator*() { return dt; }
344
345private:
346 const DateTime* dt;
347 bool del;
348
349 DLLLOCAL DateTimeValueHelper(const DateTimeValueHelper&) = delete;
350 DLLLOCAL DateTimeValueHelper& operator=(const DateTimeValueHelper&) = delete;
351 DLLLOCAL static void* operator new(size_t) = delete;
352};
353
355
359public:
362 if (!n) {
363 dt = ZeroDate;
364 del = false;
365 return;
366 }
367
368 // optmization without virtual function call for most common case
369 if (n->getType() == NT_DATE) {
370 dt = const_cast<DateTimeNode*>(reinterpret_cast<const DateTimeNode*>(n));
371 del = false;
372 return;
373 }
374
375 dt = new DateTimeNode;
377 del = true;
378 }
379
381
386
389
392 if (dt && del)
393 dt->deref();
394 }
395
396 DLLLOCAL const DateTimeNode* operator->() { return dt; }
397 DLLLOCAL const DateTimeNode* operator*() { return dt; }
398
400
405 if (del)
406 del = false;
407 else if (dt)
408 dt->ref();
409 return dt;
410 }
411
412private:
413 DateTimeNode* dt;
414 bool del;
415
416 DLLLOCAL DateTimeNodeValueHelper(const DateTimeNodeValueHelper&) = delete;
417 DLLLOCAL DateTimeNodeValueHelper& operator=(const DateTimeNodeValueHelper&) = delete;
418 DLLLOCAL static void* operator new(size_t) = delete;
419};
420
421#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:47
static DLLLOCAL qore_type_t getStaticTypeCode()
returns the type code (useful in templates)
Definition: DateTimeNode.h:274
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,...
static DLLEXPORT DateTimeNode * makeNow(const AbstractQoreZoneInfo *zone=currentTZ())
static "constructor" to create the current time
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:269
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:358
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:404
DLLLOCAL ~DateTimeNodeValueHelper()
dereferences the DateTimeNode value if necessary
Definition: DateTimeNode.h:391
DLLLOCAL DateTimeNodeValueHelper(const AbstractQoreNode *n)
gets the DateTimeNode value and sets the temporary flag
Definition: DateTimeNode.h:361
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:331
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:279