Qore Programming Language: include/qore/DateTime.h (6585) Source File

Qore Programming Language 0.8.11

- Main Page
- Related Pages
- Modules
- Classes
- Files

- File List
- File Members

All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
DateTime.h
1 /* -*- mode: c++; indent-tabs-mode: nil -*- */
2 /*
3 DateTime.h
4
5 Qore programming language
6
7 Copyright 2003 - 2013 David Nichols
8
9 This library is free software; you can redistribute it and/or
10 modify it under the terms of the GNU Lesser General Public
11 License as published by the Free Software Foundation; either
12 version 2.1 of the License, or (at your option) any later version.
13
14 This library is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 Lesser General Public License for more details.
18
19 You should have received a copy of the GNU Lesser General Public
20 License along with this library; if not, write to the Free Software
21 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 */
23
24 #ifndef QORE_DATETIME_H
25
26 #define QORE_DATETIME_H
27
28 #include <time.h>
29
30 class AbstractQoreZoneInfo;
31
33 struct qore_tm {
34 int year, month, day, hour, minute, second, us, utc_secs_east;
35 bool dst;
36 const char *zone_name;
37 const AbstractQoreZoneInfo *zone;
38
39 DLLLOCAL void clear() {
40 year = 0;
41 month = 0;
42 day = 0;
43 hour = 0;
44 minute = 0;
45 second = 0;
46 us = 0;
47 utc_secs_east = 0;
48 dst = false;
49 zone_name = 0;
50 zone = 0;
51 }
52
53 DLLLOCAL bool isTimeNull() const {
54 return !hour && !minute && !second && !us;
55 }
56
58 DLLEXPORT int secsEast() const;
59
61 DLLEXPORT const char *regionName() const;
62 };
63
65
85 class DateTime {
86 friend class DateTimeNode;
87
88 protected:
90 class qore_date_private *priv;
91
92 DLLLOCAL void setDateLiteral(int64 date);
93 DLLLOCAL void setRelativeDateLiteral(int64 date);
94
96 DLLLOCAL DateTime& operator=(const DateTime&);
97
99 DLLLOCAL DateTime(qore_date_private *n_priv);
100
101 public:
103
106 DLLEXPORT DateTime(bool r = false);
107
109
119 DLLEXPORT DateTime(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);
120
122
125 DLLEXPORT DateTime(int64 seconds);
126
128
132 DLLEXPORT DateTime(int64 seconds, int ms);
133
135
137 DLLEXPORT DateTime(const char *date);
138
140
143 DLLEXPORT DateTime(const AbstractQoreZoneInfo *zone, const char *date);
144
146
149 DLLEXPORT DateTime(const struct tm *tms);
150
152 DLLEXPORT DateTime(const DateTime &dt);
153
155 DLLEXPORT ~DateTime();
156
158 DLLEXPORT void getTM(struct tm *tms) const;
159
161
163 DLLEXPORT void setNow();
164
166
169 DLLEXPORT void setNow(const AbstractQoreZoneInfo *zone);
170
172
175 DLLEXPORT void setDate(int64 seconds);
176
178
182 DLLEXPORT void setDate(int64 seconds, int ms);
183
185
189 DLLEXPORT void setDate(const AbstractQoreZoneInfo *zone, int64 seconds, int us);
190
192
196 DLLEXPORT void setLocalDate(const AbstractQoreZoneInfo *zone, int64 seconds, int us);
197
199 DLLEXPORT void setDate(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);
200
202
205 DLLEXPORT void setDate(const char *str);
206
208
212 DLLEXPORT void setDate(const AbstractQoreZoneInfo *zone, const char *str);
213
215 DLLEXPORT void setRelativeDate(const char *str);
216
218 DLLEXPORT void setDate(const struct tm *tms, short ms = 0);
219
221 DLLEXPORT void setDate(const DateTime &date);
222
224
230 DLLEXPORT void setTime(int h, int m, int s, short ms = 0);
231
232 DLLEXPORT bool checkValidity() const;
233 DLLEXPORT bool isEqual(const DateTime *dt) const;
234 DLLEXPORT DateTime *add(const DateTime *dt) const;
235 DLLEXPORT DateTime *subtractBy(const DateTime *dt) const;
236
238
241 DLLEXPORT int64 getEpochSeconds() const;
242
244
247 DLLEXPORT int64 getEpochSecondsUTC() const;
248
250
253 DLLEXPORT int64 getEpochMicrosecondsUTC() const;
254
256
259 DLLEXPORT int64 getEpochMillisecondsUTC() const;
260
262
265 DLLEXPORT int getDayNumber() const;
266
268
271 DLLEXPORT int getDayOfWeek() const;
272
274
279 DLLEXPORT void getISOWeek(int &year, int &week, int &day) const;
280
282
321 DLLEXPORT void format(QoreString &str, const char *fmt) const;
322
324
327 DLLEXPORT bool isRelative() const;
328
330
333 DLLEXPORT bool isAbsolute() const;
334
336
339 DLLEXPORT short getYear() const;
340
342
345 DLLEXPORT int getMonth() const;
346
348
351 DLLEXPORT int getDay() const;
352
354
357 DLLEXPORT int getHour() const;
358
360
363 DLLEXPORT int getMinute() const;
364
366
369 DLLEXPORT int getSecond() const;
370
372
375 DLLEXPORT int getMillisecond() const;
376
378
380 DLLEXPORT int getMicrosecond() const;
381
383
386 DLLEXPORT int64 getRelativeSeconds() const;
387
389
392 DLLEXPORT int64 getRelativeMilliseconds() const;
393
395
398 DLLEXPORT int64 getRelativeMicroseconds() const;
399
401 DLLEXPORT bool hasValue() const;
402
404 DLLEXPORT DateTime *unaryMinus() const;
405
407 DLLEXPORT void unaryMinusInPlace();
408
410 DLLEXPORT void getInfo(const AbstractQoreZoneInfo *n_zone, qore_tm &info) const;
411
413 DLLEXPORT void getInfo(qore_tm &info) const;
414
416 DLLEXPORT void setZone(const AbstractQoreZoneInfo *n_zone);
417
419 DLLEXPORT const AbstractQoreZoneInfo* getZone() const;
420
421 // static methods
423 DLLEXPORT static bool isLeapYear(int year);
424
426 DLLEXPORT static int getLastDayOfMonth(int month, int year);
427
429
437 DLLEXPORT static DateTime *getDateFromISOWeek(int year, int week, int day, ExceptionSink *xsink);
438
440 DLLEXPORT static int compareDates(const DateTime *left, const DateTime *right);
441
443 DLLEXPORT static DateTime *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);
444
446
451 DLLEXPORT static DateTime *makeAbsolute(const AbstractQoreZoneInfo *zone, int64 seconds, int us = 0);
452
454
459 DLLEXPORT static DateTime *makeAbsoluteLocal(const AbstractQoreZoneInfo *zone, int64 seconds, int us = 0);
460
462 DLLEXPORT static DateTime *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);
463 };
464
465 #endif
DateTime::DateTime
DLLLOCAL DateTime(qore_date_private *n_priv)
this constructor is not exported in the library
DateTime::unaryMinus
DLLEXPORT DateTime * unaryMinus() const
returns the negative time from the current time
DateTime::operator=
DLLLOCAL DateTime & operator=(const DateTime &)
this function is not implemented; it is here as a private function in order to prohibit it from being...
DateTime::priv
class qore_date_private * priv
private date data - most are ints so relative dates can hold a lot of data
Definition: DateTime.h:90
qore_tm::regionName
DLLEXPORT const char * regionName() const
returns the region name of the zone
DateTime::getMinute
DLLEXPORT int getMinute() const
returns the minute portion of the date-time value (in local time according to the time zone for absol...
DateTime::getRelativeMicroseconds
DLLEXPORT int64 getRelativeMicroseconds() const
returns the difference as the number of microseconds between the date/time value and the local time a...
DateTime
Holds absolute and relative date/time values in Qore with precision to the microsecond.
Definition: DateTime.h:85
DateTime::setDate
DLLEXPORT void setDate(int64 seconds)
sets the absolute date value based on the number of seconds from January 1, 1970
DateTime::setZone
DLLEXPORT void setZone(const AbstractQoreZoneInfo *n_zone)
changes the time zone for the time without updating the epoch offset
DateTime::getRelativeSeconds
DLLEXPORT int64 getRelativeSeconds() const
returns the difference as the number of seconds between the date/time value and the local time at the...
DateTime::hasValue
DLLEXPORT bool hasValue() const
returns true if the object has a value, false if not (zero value = 1970-01-01Z for absolute times...
DateTime::isLeapYear
static DLLEXPORT bool isLeapYear(int year)
returns true if the year passed is a leap year according to a proleptic gregorian calendar ...
qore_tm::secsEast
DLLEXPORT int secsEast() const
returns seconds east of UTC for zone
DateTime::getEpochMicrosecondsUTC
DLLEXPORT int64 getEpochMicrosecondsUTC() const
gets the number of microseconds since January 1, 1970Z for the current date
DateTime::getMicrosecond
DLLEXPORT int getMicrosecond() const
returns the microsecond portion of the date-time value
DateTime::getDateFromISOWeek
static DLLEXPORT DateTime * getDateFromISOWeek(int year, int week, int day, ExceptionSink *xsink)
returns a DateTime value from ISO-8601 week and day offsets
DateTime::getMonth
DLLEXPORT int getMonth() const
returns the month portion of the date-time value (in local time according to the time zone for absolu...
DateTime::~DateTime
DLLEXPORT ~DateTime()
destroys the object and frees all memory
DateTime::getMillisecond
DLLEXPORT int getMillisecond() const
returns the microsecond portion of the date-time value divided by 1000
QoreString
Qore's string type supported by the QoreEncoding class.
Definition: QoreString.h:42
DateTime::getDay
DLLEXPORT int getDay() const
returns the day portion of the date-time value (in local time according to the time zone for absolute...
DateTime::getDayOfWeek
DLLEXPORT int getDayOfWeek() const
returns the day of week for the current date (0-6, Sun-Sat)
DateTime::isRelative
DLLEXPORT bool isRelative() const
returns true if the value is a relative date-time value
DateTime::setRelativeDate
DLLEXPORT void setRelativeDate(const char *str)
sets a relative date from a string in the format YYYYMMDDHHmmSS
DateTime::getEpochSeconds
DLLEXPORT int64 getEpochSeconds() const
gets the number of seconds since January 1, 1970 for the current date offset in local time ...
DateTime::getEpochMillisecondsUTC
DLLEXPORT int64 getEpochMillisecondsUTC() const
gets the number of milliseconds since January 1, 1970Z for the current date
DateTimeNode
Qore's parse tree/value type for date-time values, reference-counted, dynamically-allocated only...
Definition: DateTimeNode.h:36
DateTime::getLastDayOfMonth
static DLLEXPORT int getLastDayOfMonth(int month, int year)
returns the number of days in the month given according to a proleptic gregorian calendar ...
DateTime::getSecond
DLLEXPORT int getSecond() const
returns the second portion of the date-time value (in local time according to the time zone for absol...
DateTime::compareDates
static DLLEXPORT int compareDates(const DateTime *left, const DateTime *right)
returns -1, 0, or 1 if the left date is less than, equal, or greater than the right date ...
DateTime::getEpochSecondsUTC
DLLEXPORT int64 getEpochSecondsUTC() const
gets the number of seconds since January 1, 1970Z for the current date
DateTime::makeAbsolute
static DLLEXPORT DateTime * 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
DateTime::getRelativeMilliseconds
DLLEXPORT int64 getRelativeMilliseconds() const
returns the difference as the number of milliseconds between the date/time value and the local time a...
DateTime::getInfo
DLLEXPORT void getInfo(const AbstractQoreZoneInfo *n_zone, qore_tm &info) const
returns the broken-down time in the given time zone (n_zone = 0 means UTC)
DateTime::getZone
DLLEXPORT const AbstractQoreZoneInfo * getZone() const
gets the time zone for the object; returns 0 for relative date/time values
DateTime::getTM
DLLEXPORT void getTM(struct tm *tms) const
sets a "struct tm" from the current date/time value for the time zone for the object; use DateTime::g...
DateTime::getYear
DLLEXPORT short getYear() const
returns the year portion of the date-time value (in local time according to the time zone for absolut...
ExceptionSink
container for holding Qore-language exception information and also for registering a "thread_exit" ca...
Definition: ExceptionSink.h:35
DateTime::getISOWeek
DLLEXPORT void getISOWeek(int &year, int &week, int &day) const
returns the ISO-8601 week information
DateTime::isAbsolute
DLLEXPORT bool isAbsolute() const
returns true if the value is an absolute date-time value
DateTime::getHour
DLLEXPORT int getHour() const
returns the hour portion of the date-time value (in local time according to the time zone for absolut...
DateTime::format
DLLEXPORT void format(QoreString &str, const char *fmt) const
formats the date/time value to a QoreString
DateTime::unaryMinusInPlace
DLLEXPORT void unaryMinusInPlace()
converts the current value to the negative of itself
DateTime::setNow
DLLEXPORT void setNow()
sets the current date and time in the current time zone; current contents are overwritten ...
DateTime::makeAbsoluteLocal
static DLLEXPORT DateTime * 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...
DateTime::setLocalDate
DLLEXPORT void setLocalDate(const AbstractQoreZoneInfo *zone, int64 seconds, int us)
sets the absolute date value based on the number of seconds from January 1, 1970 in the given time zo...
DateTime::getDayNumber
DLLEXPORT int getDayNumber() const
returns the ordinal number of the day in the year for absolute dates, sometimes (mistakenly) referred...
DateTime::setTime
DLLEXPORT void setTime(int h, int m, int s, short ms=0)
sets the time from hours, minutes, seconds, and milliseconds
qore_tm
for returning broken-down time information
Definition: DateTime.h:33
DateTime::makeRelative
static DLLEXPORT DateTime * 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