32#ifndef QORE_DATETIME_H
34#define QORE_DATETIME_H
38class 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 DateTime * getDateFromISOWeek(int year, int week, int day, ExceptionSink *xsink)
returns a DateTime value from ISO-8601 week and day offsets
DLLEXPORT DateTime * unaryMinus() const
returns the negative time from the current time
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 DateTime(const char *date, ExceptionSink *xsink)
constructor for setting the date from a string with a flexible format, throws a Qore-language excepti...
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...
DLLEXPORT void setDate(int64 seconds, int ms)
sets the absolute date value based on the number of seconds from January 1, 1970 UTC (plus millisecon...
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 * 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 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 DateTime(const AbstractQoreZoneInfo *zone, const QoreValue v)
constructor for creating an absolute date from a value representing a number of seconds
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 void setNow(const AbstractQoreZoneInfo *zone)
sets the current date and time in the given time zone; current contents are overwritten
DLLEXPORT bool isRelative() const
returns true if the value is a relative date-time value
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 DateTime(const char *date)
constructor for setting the date from a string
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
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 void setRelativeDateSeconds(int64 s, int us=0)
set the object to a relative date/time value as given in seconds and optionally microseconds
DLLEXPORT DateTime(int64 seconds)
constructor for setting an absolute date based on the number of seconds from January 1,...
DLLEXPORT DateTime(int64 seconds, int ms)
constructor for setting an absolute date based on the number of seconds from January 1,...
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 DateTime(const AbstractQoreZoneInfo *zone, const char *date)
constructor for setting the date from a string with a flexible format
DLLEXPORT void setDate(const char *str)
sets an absolute date value from a string with a flexible format
DLLEXPORT void setDate(const char *str, ExceptionSink *xsink)
sets an absolute date value from a string with a flexible format
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
static DLLEXPORT DateTime * 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 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...
DLLEXPORT void setDate(const DateTime &date)
sets the date from a DateTime reference
DLLEXPORT void setDate(const AbstractQoreZoneInfo *zone, const char *str)
sets an absolute date value from a time zone pointer and a string with a flexible format
DLLEXPORT const AbstractQoreZoneInfo * getZone() const
gets the time zone for the object; returns 0 for relative date/time values
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 DateTime(const DateTime &dt)
copy constructor
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(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 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)
sets the date to an absolute date/time as given
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...
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...
DLLEXPORT bool isAbsolute() const
returns true if the value is an absolute date-time value
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 void unaryMinusInPlace()
converts the current value to the negative of itself
DLLEXPORT void setDate(const hashdecl tm *tms, short ms=0)
sets the absolute date from a "hashdecl tm" pointer and millisecond value
DLLEXPORT DateTime(const hashdecl tm *tms)
constructor for setting an absolute date based on a "hashdecl tm"
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 DateTime(const QoreValue v)
constructor for creating a relative date from a value representing a number of seconds
DLLEXPORT DateTime(bool r=false)
constructor for an empty object
static DLLEXPORT DateTime * makeRelativeFromSeconds(int64 n_second, int n_us=0)
static "constructor" to create a relative time, including microseconds
DLLEXPORT int64 getEpochMillisecondsUTC() const
gets the number of milliseconds since January 1, 1970Z for the current date
DLLEXPORT void getInfo(qore_tm &info) const
returns the broken-down time in the current time zone
DLLEXPORT int getMicrosecond() const
returns the microsecond portion of the date-time value
DLLEXPORT void setDate(const AbstractQoreZoneInfo *zone, int64 seconds, int us)
sets the absolute date value based on the number of seconds from January 1, 1970 UTC (plus microsecon...
Qore's parse tree/value type for date-time values, reference-counted, dynamically-allocated only.
Definition: DateTimeNode.h:47
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
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:279
for returning broken-down time information
Definition: DateTime.h:41
DLLEXPORT int secsEast() const
returns seconds east of UTC for zone
DLLEXPORT const char * regionName() const
returns the region name of the zone