00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #ifndef _QORE_DATETIMENODE_H
00027
00028 #define _QORE_DATETIMENODE_H
00029
00030 #include <qore/AbstractQoreNode.h>
00031 #include <qore/DateTime.h>
00032
00033 class qore_date_private;
00034
00036 class DateTimeNode : public SimpleValueQoreNode, public DateTime {
00037 private:
00039 DLLLOCAL DateTimeNode(const DateTime *);
00040
00042 DLLLOCAL DateTimeNode& operator=(const DateTimeNode &);
00043
00045
00049 DLLEXPORT virtual bool getAsBoolImpl() const;
00050
00052
00055 DLLEXPORT virtual int getAsIntImpl() const;
00056
00058
00061 DLLEXPORT virtual int64 getAsBigIntImpl() const;
00062
00064
00067 DLLEXPORT virtual double getAsFloatImpl() const;
00068
00070 DLLLOCAL DateTimeNode(qore_date_private *n_priv);
00071
00072 protected:
00074 DLLEXPORT virtual ~DateTimeNode();
00075
00076 public:
00078
00081 DLLEXPORT DateTimeNode(bool r = false);
00082
00084
00094 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);
00095
00097
00100 DLLEXPORT DateTimeNode(int64 seconds);
00101
00103
00107 DLLEXPORT DateTimeNode(int64 seconds, int ms);
00108
00110
00113 DLLEXPORT DateTimeNode(const char *date);
00114
00116
00119 DLLEXPORT DateTimeNode(struct tm *tms);
00120
00122 DLLEXPORT DateTimeNode(const DateTimeNode &dt);
00123
00125 DLLEXPORT DateTimeNode(const DateTime &dt);
00126
00128
00133 DLLEXPORT virtual QoreString *getStringRepresentation(bool &del) const;
00134
00136
00139 DLLEXPORT virtual void getStringRepresentation(QoreString &str) const;
00140
00142
00146 DLLEXPORT virtual DateTime *getDateTimeRepresentation(bool &del) const;
00147
00149
00152 DLLEXPORT virtual void getDateTimeRepresentation(DateTime &dt) const;
00153
00155
00164 DLLEXPORT virtual QoreString *getAsString(bool &del, int foff, ExceptionSink *xsink) const;
00165
00167
00174 DLLEXPORT virtual int getAsString(QoreString &str, int foff, ExceptionSink *xsink) const;
00175
00176 DLLEXPORT virtual class AbstractQoreNode *realCopy() const;
00177
00179
00183 DLLEXPORT virtual bool is_equal_soft(const AbstractQoreNode *v, ExceptionSink *xsink) const;
00184 DLLEXPORT virtual bool is_equal_hard(const AbstractQoreNode *v, ExceptionSink *xsink) const;
00185
00187 DLLEXPORT virtual const char *getTypeName() const;
00188
00189 DLLLOCAL static const char *getStaticTypeName() {
00190 return "date";
00191 }
00192
00194
00197 DLLEXPORT DateTimeNode *copy() const;
00198
00200
00203 DLLEXPORT DateTimeNode *add(const DateTime *dt) const;
00204
00206
00209 DLLEXPORT DateTimeNode *subtractBy(const DateTime *dt) const;
00210
00212 DLLEXPORT DateTimeNode *unaryMinus() const;
00213
00215
00222 DLLEXPORT static DateTimeNode *getDateFromISOWeek(int year, int week, int day, ExceptionSink *xsink);
00223
00225 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);
00226
00228
00233 DLLEXPORT static DateTimeNode *makeAbsolute(const AbstractQoreZoneInfo *zone, int64 seconds, int us = 0);
00234
00236
00241 DLLEXPORT static DateTimeNode *makeAbsoluteLocal(const AbstractQoreZoneInfo *zone, int64 seconds, int us = 0);
00242
00244 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);
00245 };
00246
00247 DLLEXPORT extern DateTimeNode *ZeroDate;
00248
00250
00255 class DateTimeValueHelper {
00256 private:
00257 const DateTime *dt;
00258 bool del;
00259
00260 DLLLOCAL DateTimeValueHelper(const DateTimeValueHelper&);
00261 DLLLOCAL DateTimeValueHelper& operator=(const DateTimeValueHelper&);
00262 DLLLOCAL void *operator new(size_t);
00263
00264 public:
00266 DLLLOCAL DateTimeValueHelper(const AbstractQoreNode *n) {
00267
00268 if (n) {
00269 if (n->getType() == NT_DATE) {
00270 dt = reinterpret_cast<const DateTimeNode *>(n);
00271 del = false;
00272 }
00273 else
00274 dt = n->getDateTimeRepresentation(del);
00275 }
00276 else {
00277 dt = ZeroDate;
00278 del = false;
00279 }
00280 }
00281
00283 DLLLOCAL ~DateTimeValueHelper() {
00284 if (del)
00285 delete const_cast<DateTime *>(dt);
00286 }
00287 DLLLOCAL const DateTime *operator->() { return dt; }
00288 DLLLOCAL const DateTime *operator*() { return dt; }
00289 };
00290
00292
00295 class DateTimeNodeValueHelper {
00296 private:
00297 DateTimeNode *dt;
00298 bool temp;
00299
00300 DLLLOCAL DateTimeNodeValueHelper(const DateTimeNodeValueHelper&);
00301 DLLLOCAL DateTimeNodeValueHelper& operator=(const DateTimeNodeValueHelper&);
00302 DLLLOCAL void *operator new(size_t);
00303
00304 public:
00306 DLLLOCAL DateTimeNodeValueHelper(const AbstractQoreNode *n) {
00307 if (!n) {
00308 dt = ZeroDate;
00309 temp = false;
00310 return;
00311 }
00312
00313
00314 if (n->getType() == NT_DATE) {
00315 dt = const_cast<DateTimeNode *>(reinterpret_cast<const DateTimeNode *>(n));
00316 temp = false;
00317 return;
00318 }
00319
00320 dt = new DateTimeNode();
00321 n->getDateTimeRepresentation(*dt);
00322 temp = true;
00323 }
00324
00326 DLLLOCAL ~DateTimeNodeValueHelper() {
00327 if (dt && temp)
00328 dt->deref();
00329 }
00330
00331 DLLLOCAL const DateTimeNode *operator->() { return dt; }
00332 DLLLOCAL const DateTimeNode *operator*() { return dt; }
00333
00335
00339 DLLLOCAL DateTimeNode *getReferencedValue() {
00340 if (temp)
00341 temp = false;
00342 else if (dt)
00343 dt->ref();
00344 return dt;
00345 }
00346 };
00347
00348 #endif