All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
DateTime.h
/* -*- mode: c++; indent-tabs-mode: nil -*- */
/*
DateTime.h
Qore programming language
Copyright 2003 - 2013 David Nichols
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef QORE_DATETIME_H
#define QORE_DATETIME_H
#include <time.h>
class AbstractQoreZoneInfo;
struct qore_tm {
int year, month, day, hour, minute, second, us, utc_secs_east;
bool dst;
const char *zone_name;
const AbstractQoreZoneInfo *zone;
DLLLOCAL void clear() {
year = 0;
month = 0;
day = 0;
hour = 0;
minute = 0;
second = 0;
us = 0;
utc_secs_east = 0;
dst = false;
zone_name = 0;
zone = 0;
}
DLLLOCAL bool isTimeNull() const {
return !hour && !minute && !second && !us;
}
DLLEXPORT int secsEast() const;
DLLEXPORT const char *regionName() const;
};
class DateTime {
friend class DateTimeNode;
protected:
class qore_date_private *priv;
DLLLOCAL void setDateLiteral(int64 date);
DLLLOCAL void setRelativeDateLiteral(int64 date);
DLLLOCAL DateTime& operator=(const DateTime&);
DLLLOCAL DateTime(qore_date_private *n_priv);
public:
DLLEXPORT DateTime(bool r = false);
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);
DLLEXPORT DateTime(int64 seconds);
DLLEXPORT DateTime(int64 seconds, int ms);
DLLEXPORT DateTime(const char *date);
DLLEXPORT DateTime(const AbstractQoreZoneInfo *zone, const char *date);
DLLEXPORT DateTime(const struct tm *tms);
DLLEXPORT DateTime(const DateTime &dt);
DLLEXPORT ~DateTime();
DLLEXPORT void getTM(struct tm *tms) const;
DLLEXPORT void setNow();
DLLEXPORT void setNow(const AbstractQoreZoneInfo *zone);
DLLEXPORT void setDate(int64 seconds);
DLLEXPORT void setDate(int64 seconds, int ms);
DLLEXPORT void setDate(const AbstractQoreZoneInfo *zone, int64 seconds, int us);
DLLEXPORT void setLocalDate(const AbstractQoreZoneInfo *zone, int64 seconds, int us);
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);
DLLEXPORT void setDate(const char *str);
DLLEXPORT void setDate(const AbstractQoreZoneInfo *zone, const char *str);
DLLEXPORT void setRelativeDate(const char *str);
DLLEXPORT void setDate(const struct tm *tms, short ms = 0);
DLLEXPORT void setDate(const DateTime &date);
DLLEXPORT void setTime(int h, int m, int s, short ms = 0);
DLLEXPORT bool checkValidity() const;
DLLEXPORT bool isEqual(const DateTime *dt) const;
DLLEXPORT DateTime *add(const DateTime *dt) const;
DLLEXPORT DateTime *subtractBy(const DateTime *dt) const;
DLLEXPORT int64 getEpochSeconds() const;
DLLEXPORT int64 getEpochSecondsUTC() const;
DLLEXPORT int64 getEpochMicrosecondsUTC() const;
DLLEXPORT int64 getEpochMillisecondsUTC() const;
DLLEXPORT int getDayNumber() const;
DLLEXPORT int getDayOfWeek() const;
DLLEXPORT void getISOWeek(int &year, int &week, int &day) const;
DLLEXPORT void format(QoreString &str, const char *fmt) const;
DLLEXPORT bool isRelative() const;
DLLEXPORT bool isAbsolute() const;
DLLEXPORT short getYear() const;
DLLEXPORT int getMonth() const;
DLLEXPORT int getDay() const;
DLLEXPORT int getHour() const;
DLLEXPORT int getMinute() const;
DLLEXPORT int getSecond() const;
DLLEXPORT int getMillisecond() const;
DLLEXPORT int getMicrosecond() const;
DLLEXPORT int64 getRelativeSeconds() const;
DLLEXPORT int64 getRelativeMilliseconds() const;
DLLEXPORT int64 getRelativeMicroseconds() const;
DLLEXPORT bool hasValue() const;
DLLEXPORT DateTime *unaryMinus() const;
DLLEXPORT void unaryMinusInPlace();
DLLEXPORT void getInfo(const AbstractQoreZoneInfo *n_zone, qore_tm &info) const;
DLLEXPORT void getInfo(qore_tm &info) const;
DLLEXPORT void setZone(const AbstractQoreZoneInfo *n_zone);
DLLEXPORT const AbstractQoreZoneInfo* getZone() const;
// static methods
DLLEXPORT static bool isLeapYear(int year);
DLLEXPORT static int getLastDayOfMonth(int month, int year);
DLLEXPORT static DateTime *getDateFromISOWeek(int year, int week, int day, ExceptionSink *xsink);
DLLEXPORT static int compareDates(const DateTime *left, const DateTime *right);
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);
DLLEXPORT static DateTime *makeAbsolute(const AbstractQoreZoneInfo *zone, int64 seconds, int us = 0);
DLLEXPORT static DateTime *makeAbsoluteLocal(const AbstractQoreZoneInfo *zone, int64 seconds, int us = 0);
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);
};
#endif