32 #ifndef QORE_DATETIME_H
34 #define QORE_DATETIME_H
38 class AbstractQoreZoneInfo;
42 int year, month, day, hour, minute, second, us, utc_secs_east;
44 const char* zone_name;
45 const AbstractQoreZoneInfo* zone;
47 DLLLOCAL
void clear() {
61 DLLLOCAL
bool isTimeNull()
const {
62 return !hour && !minute && !second && !us;
95 friend class qore_relative_time;
96 friend class qore_absolute_time;
102 DLLLOCAL
void setDateLiteral(
int64 date);
103 DLLLOCAL
void setRelativeDateLiteral(
int64 date);
129 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);
176 DLLEXPORT
DateTime(
const AbstractQoreZoneInfo* zone,
const char* date);
191 DLLEXPORT
void getTM(
struct tm *tms)
const;
202 DLLEXPORT
void setNow(
const AbstractQoreZoneInfo* zone);
222 DLLEXPORT
void setDate(
const AbstractQoreZoneInfo* zone,
int64 seconds,
int us);
232 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);
254 DLLEXPORT
void setDate(
const AbstractQoreZoneInfo* zone,
const char* str);
260 DLLEXPORT
void setDate(
const struct tm *tms,
short ms = 0);
272 DLLEXPORT
void setTime(
int h,
int m,
int s,
short ms = 0);
277 DLLEXPORT
bool checkValidity()
const;
278 DLLEXPORT
bool isEqual(
const DateTime* dt)
const;
279 DLLEXPORT
bool isEqual(
const DateTime& dt)
const;
337 DLLEXPORT
void getISOWeek(
int& year,
int& week,
int& day)
const;
480 DLLEXPORT
void setZone(
const AbstractQoreZoneInfo* n_zone);
483 DLLEXPORT
const AbstractQoreZoneInfo*
getZone()
const;
507 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);
526 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);
Holds absolute and relative date/time values in Qore with precision to the microsecond.
Definition: DateTime.h:93
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
DLLEXPORT int64 getRelativeMilliseconds() const
returns the difference as the number of milliseconds between the date/time value and the local time a...
DLLEXPORT void addSecondsTo(int64 secs, int us=0)
adds the given number of seconds (and microseconds) to the date/time value
DLLEXPORT double getRelativeSecondsDouble() const
returns the difference as the number of seconds between the date/time value and the local time at the...
DLLLOCAL DateTime & operator=(const DateTime &)
this function is not implemented; it is here as a private function in order to prohibit it from being...
DLLEXPORT int64 getEpochSecondsUTC() const
gets the number of seconds since January 1, 1970Z for the current date
DLLEXPORT int getMillisecond() const
returns the microsecond portion of the date-time value divided by 1000
class qore_date_private * priv
private date data - most are ints so relative dates can hold a lot of data
Definition: DateTime.h:100
static DLLEXPORT DateTime * makeRelativeFromSeconds(int64 n_second, int n_us=0)
static "constructor" to create a relative time, including microseconds
DLLEXPORT int getDayNumber() const
returns the ordinal number of the day in the year for absolute dates, sometimes (mistakenly) referred...
DLLEXPORT void getISOWeek(int &year, int &week, int &day) const
returns the ISO-8601 week information
DLLEXPORT const AbstractQoreZoneInfo * getZone() const
gets the time zone for the object; returns 0 for relative date/time values
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
DLLEXPORT int getHour() const
returns the hour portion of the date-time value (in local time according to the time zone for absolut...
DLLEXPORT int getSecond() const
returns the second portion of the date-time value (in local time according to the time zone for absol...
static DLLEXPORT int getLastDayOfMonth(int month, int year)
returns the number of days in the month given according to a proleptic gregorian calendar
DLLEXPORT DateTime * unaryMinus() const
returns the negative time from the current time
DLLEXPORT bool isRelative() const
returns true if the value is a relative date-time value
DLLEXPORT bool hasValue() const
returns true if the object has a value, false if not (zero value = 1970-01-01Z for absolute times,...
DLLEXPORT void format(QoreString &str, const char *fmt) const
formats the date/time value to a QoreString
DLLEXPORT void setRelativeDateSeconds(int64 s, int us=0)
set the object to a relative date/time value as given in seconds and optionally microseconds
DLLEXPORT int64 getEpochMicrosecondsUTC() const
gets the number of microseconds since January 1, 1970Z for the current date
DLLEXPORT void setZone(const AbstractQoreZoneInfo *n_zone)
changes the time zone for the time without updating the epoch offset
DLLEXPORT void setRelativeDate(const char *str)
sets a relative date from a string in the format YYYYMMDDHHmmSS
DLLEXPORT int getDayOfWeek() const
returns the day of week for the current date (0-6, Sun-Sat)
DLLLOCAL DateTime(qore_date_private *n_priv)
this constructor is not exported in the library
DLLEXPORT void setTime(int h, int m, int s, short ms=0)
sets the time from hours, minutes, seconds, and milliseconds
DLLEXPORT int64 getRelativeSeconds() const
returns the difference as the number of seconds between the date/time value and the local time at the...
DLLEXPORT void setNow()
sets the current date and time in the current time zone; current contents are overwritten
DLLEXPORT int getMinute() const
returns the minute portion of the date-time value (in local time according to the time zone for absol...
static DLLEXPORT bool isLeapYear(int year)
returns true if the year passed is a leap year according to a proleptic gregorian calendar
DLLEXPORT void setDate(int64 seconds)
sets the absolute date value based on the number of seconds from January 1, 1970
DLLEXPORT int64 getRelativeMicroseconds() const
returns the difference as the number of microseconds between the date/time value and the local time a...
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,...
DLLEXPORT int64 getEpochSeconds() const
gets the number of seconds since January 1, 1970 for the current date offset in local time
DLLEXPORT int getMonth() const
returns the month portion of the date-time value (in local time according to the time zone for absolu...
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)
DLLEXPORT int getDay() const
returns the day portion of the date-time value (in local time according to the time zone for absolute...
DLLEXPORT ~DateTime()
destroys the object and frees all memory
DLLEXPORT short getYear() const
returns the year portion of the date-time value (in local time according to the time zone for absolut...
static DLLEXPORT DateTime * getDateFromISOWeek(int year, int week, int day, ExceptionSink *xsink)
returns a DateTime value from ISO-8601 week and day offsets
DLLEXPORT void getTM(hashdecl tm *tms) const
sets a "hashdecl tm" from the current date/time value for the time zone for the object; use DateTime::g...
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
DLLEXPORT bool isAbsolute() const
returns true if the value is an absolute date-time value
DLLEXPORT void unaryMinusInPlace()
converts the current value to the negative of itself
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...
DLLEXPORT int64 getEpochMillisecondsUTC() const
gets the number of milliseconds since January 1, 1970Z for the current date
DLLEXPORT int getMicrosecond() const
returns the microsecond portion of the date-time value
Qore's parse tree/value type for date-time values, reference-counted, dynamically-allocated only.
Definition: DateTimeNode.h:45
container for holding Qore-language exception information and also for registering a "thread_exit" ca...
Definition: ExceptionSink.h:48
Qore's string type supported by the QoreEncoding class.
Definition: QoreString.h:93
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
The main value class in Qore, designed to be passed by value.
Definition: QoreValue.h:275
for returning broken-down time information
Definition: DateTime.h:41
DLLEXPORT const char * regionName() const
returns the region name of the zone
DLLEXPORT int secsEast() const
returns seconds east of UTC for zone