24 #ifndef QORE_DATETIME_H
26 #define QORE_DATETIME_H
30 class AbstractQoreZoneInfo;
34 int year, month, day, hour, minute, second, us, utc_secs_east;
36 const char *zone_name;
37 const AbstractQoreZoneInfo *zone;
39 DLLLOCAL
void clear() {
53 DLLLOCAL
bool isTimeNull()
const {
54 return !hour && !minute && !second && !us;
90 class qore_date_private *
priv;
92 DLLLOCAL
void setDateLiteral(int64 date);
93 DLLLOCAL
void setRelativeDateLiteral(int64 date);
99 DLLLOCAL
DateTime(qore_date_private *n_priv);
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);
132 DLLEXPORT
DateTime(int64 seconds,
int ms);
137 DLLEXPORT
DateTime(
const char *date);
143 DLLEXPORT
DateTime(
const AbstractQoreZoneInfo *zone,
const char *date);
149 DLLEXPORT
DateTime(
const struct tm *tms);
158 DLLEXPORT
void getTM(
struct tm *tms)
const;
169 DLLEXPORT
void setNow(
const AbstractQoreZoneInfo *zone);
175 DLLEXPORT
void setDate(int64 seconds);
182 DLLEXPORT
void setDate(int64 seconds,
int ms);
189 DLLEXPORT
void setDate(
const AbstractQoreZoneInfo *zone, int64 seconds,
int us);
196 DLLEXPORT
void setLocalDate(
const AbstractQoreZoneInfo *zone, int64 seconds,
int us);
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);
205 DLLEXPORT
void setDate(
const char *str);
212 DLLEXPORT
void setDate(
const AbstractQoreZoneInfo *zone,
const char *str);
218 DLLEXPORT
void setDate(
const struct tm *tms,
short ms = 0);
230 DLLEXPORT
void setTime(
int h,
int m,
int s,
short ms = 0);
232 DLLEXPORT
bool checkValidity()
const;
233 DLLEXPORT
bool isEqual(
const DateTime *dt)
const;
279 DLLEXPORT
void getISOWeek(
int &year,
int &week,
int &day)
const;
339 DLLEXPORT
short getYear()
const;
351 DLLEXPORT
int getDay()
const;
410 DLLEXPORT
void getInfo(
const AbstractQoreZoneInfo *n_zone,
qore_tm &info)
const;
416 DLLEXPORT
void setZone(
const AbstractQoreZoneInfo *n_zone);
419 DLLEXPORT
const AbstractQoreZoneInfo*
getZone()
const;
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);
451 DLLEXPORT
static DateTime *
makeAbsolute(
const AbstractQoreZoneInfo *zone, int64 seconds,
int us = 0);
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);
DLLLOCAL DateTime(qore_date_private *n_priv)
this constructor is not exported in the library
DLLEXPORT DateTime * unaryMinus() const
returns the negative time from the current time
DLLLOCAL DateTime & operator=(const DateTime &)
this function is not implemented; it is here as a private function in order to prohibit it from being...
class qore_date_private * priv
private date data - most are ints so relative dates can hold a lot of data
Definition: DateTime.h:90
DLLEXPORT const char * regionName() const
returns the region name of the zone
DLLEXPORT int getMinute() const
returns the minute portion of the date-time value (in local time according to the time zone for absol...
DLLEXPORT int64 getRelativeMicroseconds() const
returns the difference as the number of microseconds between the date/time value and the local time a...
Holds absolute and relative date/time values in Qore with precision to the microsecond.
Definition: DateTime.h:85
DLLEXPORT void setDate(int64 seconds)
sets the absolute date value based on the number of seconds from January 1, 1970
DLLEXPORT void setZone(const AbstractQoreZoneInfo *n_zone)
changes the time zone for the time without updating the epoch offset
DLLEXPORT int64 getRelativeSeconds() const
returns the difference as the number of seconds between the date/time value and the local time at the...
DLLEXPORT bool hasValue() const
returns true if the object has a value, false if not (zero value = 1970-01-01Z for absolute times...
static DLLEXPORT bool isLeapYear(int year)
returns true if the year passed is a leap year according to a proleptic gregorian calendar ...
DLLEXPORT int secsEast() const
returns seconds east of UTC for zone
DLLEXPORT int64 getEpochMicrosecondsUTC() const
gets the number of microseconds since January 1, 1970Z for the current date
DLLEXPORT int getMicrosecond() const
returns the microsecond portion of the date-time value
static DLLEXPORT DateTime * getDateFromISOWeek(int year, int week, int day, ExceptionSink *xsink)
returns a DateTime value from ISO-8601 week and day offsets
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()
destroys the object and frees all memory
DLLEXPORT int getMillisecond() const
returns the microsecond portion of the date-time value divided by 1000
Qore's string type supported by the QoreEncoding class.
Definition: QoreString.h:42
DLLEXPORT int getDay() const
returns the day portion of the date-time value (in local time according to the time zone for absolute...
DLLEXPORT int getDayOfWeek() const
returns the day of week for the current date (0-6, Sun-Sat)
DLLEXPORT bool isRelative() const
returns true if the value is a relative date-time value
DLLEXPORT void setRelativeDate(const char *str)
sets a relative date from a string in the format YYYYMMDDHHmmSS
DLLEXPORT int64 getEpochSeconds() const
gets the number of seconds since January 1, 1970 for the current date offset in local time ...
DLLEXPORT int64 getEpochMillisecondsUTC() const
gets the number of milliseconds since January 1, 1970Z for the current date
Qore's parse tree/value type for date-time values, reference-counted, dynamically-allocated only...
Definition: DateTimeNode.h:36
static DLLEXPORT int getLastDayOfMonth(int month, int year)
returns the number of days in the month given according to a proleptic gregorian calendar ...
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 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 getEpochSecondsUTC() const
gets the number of seconds since January 1, 1970Z for the current date
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 int64 getRelativeMilliseconds() const
returns the difference as the number of milliseconds between the date/time value and the local time a...
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 const AbstractQoreZoneInfo * getZone() const
gets the time zone for the object; returns 0 for relative date/time values
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...
DLLEXPORT short getYear() const
returns the year portion of the date-time value (in local time according to the time zone for absolut...
container for holding Qore-language exception information and also for registering a "thread_exit" ca...
Definition: ExceptionSink.h:35
DLLEXPORT void getISOWeek(int &year, int &week, int &day) const
returns the ISO-8601 week information
DLLEXPORT bool isAbsolute() const
returns true if the value is an absolute date-time value
DLLEXPORT int getHour() const
returns the hour portion of the date-time value (in local time according to the time zone for absolut...
DLLEXPORT void format(QoreString &str, const char *fmt) const
formats the date/time value to a QoreString
DLLEXPORT void unaryMinusInPlace()
converts the current value to the negative of itself
DLLEXPORT void setNow()
sets the current date and time in the current time zone; current contents are overwritten ...
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 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 int getDayNumber() const
returns the ordinal number of the day in the year for absolute dates, sometimes (mistakenly) referred...
DLLEXPORT void setTime(int h, int m, int s, short ms=0)
sets the time from hours, minutes, seconds, and milliseconds
for returning broken-down time information
Definition: DateTime.h:33
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