DateTime Class Reference

Holds absolute and relative date/time values in Qore with precision to the millisecond. More...

#include <DateTime.h>

Inheritance diagram for DateTime:

DateTimeNode

List of all members.

Public Member Functions

DLLEXPORT DateTime (bool r=false)
 constructor for an empty object
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 DateTime (int64 seconds)
 constructor for setting an absolute date based on the number of seconds from January 1, 1970
DLLEXPORT DateTime (int64 seconds, int ms)
 constructor for setting an absolute date based on the number of seconds from January 1, 1970 (plus milliseconds)
DLLEXPORT DateTime (const char *date)
 constructor for setting the date from a string in the format YYYYMMDDHHmmSS
DLLEXPORT DateTime (const struct tm *tms)
 constructor for setting an absolute date based on a "struct tm"
DLLEXPORT DateTime (const DateTime &dt)
 copy constructor
DLLEXPORT ~DateTime ()
 destroys the object and frees all memory
DLLEXPORT void getTM (struct tm *tms) const
 sets a "struct tm" from the current date/time value
DLLEXPORT void setDate (int64 seconds)
 sets the absolute date value based on the number of seconds from January 1, 1970
DLLEXPORT void setDate (int64 seconds, int ms)
 sets the absolute date value based on the number of seconds from January 1, 1970 (plus milliseconds)
DLLEXPORT void setDate (const char *str)
 sets an absolute date value from a string in the format YYYYMMDDHHmmSS
DLLEXPORT void setRelativeDate (const char *str)
 sets a relative date from a string in the format YYYYMMDDHHmmSS
DLLEXPORT void setDate (const struct tm *tms, short ms=0)
 sets the absolute date from a "struct tm" pointer and millisecond value
DLLEXPORT void setDate (const DateTime &date)
 sets the date from a DateTime reference
DLLEXPORT void setTime (int h, int m, int s, short ms=0)
 sets the time from hours, minutes, seconds, and milliseconds
DLLEXPORT int64 getEpochSeconds () const
 gets the number of seconds since January 1, 1970 for the current date
DLLEXPORT int getDayNumber () const
 returns the ordinal number of the day in the year for absolute dates, sometimes (mistakenly) referred to as the Julian date
DLLEXPORT int getDayOfWeek () const
 returns the day of week for the current date (0-6, Sun-Sat)
DLLEXPORT void getISOWeek (int &year, int &week, int &day) const
 returns the ISO-8601 week information
DLLEXPORT void format (class QoreString &str, const char *fmt) const
 formats the date/time value to a QoreString
DLLEXPORT bool isRelative () const
 returns true if the value is a relative date-time value
DLLEXPORT bool isAbsolute () const
 returns true if the value is an absolute date-time value
DLLEXPORT short getYear () const
 returns the year portion of the date-time value
DLLEXPORT int getMonth () const
 returns the month portion of the date-time value
DLLEXPORT int getDay () const
 returns the day portion of the date-time value
DLLEXPORT int getHour () const
 returns the hour portion of the date-time value
DLLEXPORT int getMinute () const
 returns the minute portion of the date-time value
DLLEXPORT int getSecond () const
 returns the second portion of the date-time value
DLLEXPORT int getMillisecond () const
 returns the millisecond portion of the date-time value
DLLEXPORT int64 getRelativeSeconds () const
 returns the difference as the number of seconds between the date/time value and the local time at the moment of the call
DLLEXPORT int64 getRelativeMilliseconds () const
 returns the difference as the number of milliseconds between the date/time value and the local time at the moment of the call

Static Public Member Functions

static DLLEXPORT bool isLeapYear (int year)
 returns true if the year passed is a leap year according to a proleptic gregorian calendar
static DLLEXPORT int getLastDayOfMonth (int month, int year)
 returns the number of days in the month given according to a proleptic gregorian calendar
static DLLEXPORT class DateTimegetDateFromISOWeek (int year, int week, int day, class ExceptionSink *xsink)
 returns a DateTime value from ISO-8601 week and day offsets
static DLLEXPORT int compareDates (const class DateTime *left, const class DateTime *right)
 returns -1, 0, or 1 if the left date is less than, equal, or greater than the right date

Friends

class DateTimeNode


Detailed Description

Holds absolute and relative date/time values in Qore with precision to the millisecond.

Date arithmetic and date formatting is supported by this class. Conversion to and from integers is based on a 64-bit offset in seconds since January 1, 1970 (the start of the UNIX epoch). Qore's DateTime values have years, months, days, hours, minutes, seconds, and millisecond fields. This is a "normal" class, for the equivalent Qore parse tree/value type, see DateTimeNode

See also:
DateTimeNode

Constructor & Destructor Documentation

DLLEXPORT DateTime::DateTime ( bool  r = false  ) 

constructor for an empty object

Parameters:
r sets the "relative" flag for the object

DLLEXPORT DateTime::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

Parameters:
n_year the year value
n_month the months value
n_day the days value
n_hour the hours value
n_minute the minutes value
n_second the seconds value
n_ms the milliseconds value
n_relative the relative flag

DLLEXPORT DateTime::DateTime ( int64  seconds  ) 

constructor for setting an absolute date based on the number of seconds from January 1, 1970

Parameters:
seconds the number of seconds from January 1, 1970

DLLEXPORT DateTime::DateTime ( int64  seconds,
int  ms 
)

constructor for setting an absolute date based on the number of seconds from January 1, 1970 (plus milliseconds)

Parameters:
seconds the number of seconds from January 1, 1970
ms the milliseconds portion of the time

DLLEXPORT DateTime::DateTime ( const char *  date  ) 

constructor for setting the date from a string in the format YYYYMMDDHHmmSS

additionally a milliseconds value can be appended with a period and 3 integers in the format [.xxx]

Parameters:
date the string to use to set the date in the format YYYYMMDDHHmmSS[.xxx]

DLLEXPORT DateTime::DateTime ( const struct tm *  tms  ) 

constructor for setting an absolute date based on a "struct tm"

Parameters:
tms a structure giving the absolute date to set


Member Function Documentation

DLLEXPORT void DateTime::setDate ( int64  seconds  ) 

sets the absolute date value based on the number of seconds from January 1, 1970

Parameters:
seconds the number of seconds from January 1, 1970

DLLEXPORT void DateTime::setDate ( int64  seconds,
int  ms 
)

sets the absolute date value based on the number of seconds from January 1, 1970 (plus milliseconds)

Parameters:
seconds the number of seconds from January 1, 1970
ms the milliseconds portion of the time

DLLEXPORT void DateTime::setDate ( const char *  str  ) 

sets an absolute date value from a string in the format YYYYMMDDHHmmSS

additionally a milliseconds value can be appended with a period and 3 integers in the format [.xxx]

Parameters:
str the string to use to set the date in the format YYYYMMDDHHmmSS[.xxx]

DLLEXPORT void DateTime::setTime ( int  h,
int  m,
int  s,
short  ms = 0 
)

sets the time from hours, minutes, seconds, and milliseconds

Parameters:
h the hours value
m the minutes value
s the seconds value
ms the milliseconds value

DLLEXPORT int64 DateTime::getEpochSeconds (  )  const

gets the number of seconds since January 1, 1970 for the current date

Returns:
the number of seconds since January 1, 1970

DLLEXPORT int DateTime::getDayNumber (  )  const

returns the ordinal number of the day in the year for absolute dates, sometimes (mistakenly) referred to as the Julian date

does not return sensible values for relative dates

Returns:
the number of the day in the year

DLLEXPORT int DateTime::getDayOfWeek (  )  const

returns the day of week for the current date (0-6, Sun-Sat)

Returns:
the day of week for the current date (0-6, Sun-Sat)

DLLEXPORT void DateTime::getISOWeek ( int &  year,
int &  week,
int &  day 
) const

returns the ISO-8601 week information

NOTE: the year may be different than the actual year

Parameters:
year the year portion of the ISO-9601 week information
week the ISO-9601 week number
day the day offset in the week (1-7 = Mon-Sun)

DLLEXPORT void DateTime::format ( class QoreString str,
const char *  fmt 
) const

formats the date/time value to a QoreString

the formatted date/time value will be appended to the QoreString argument according to the format string FIXME: currently locale settings are ignored Format codes are as follows:

  • YY: last two-digits of year
  • YYYY: four-digit year
  • M: month number (1-12)
  • MM: month number (1-12), zero padded
  • Month: long month string (ex: January)
  • MONTH: long month string capitalised (ex: JANUARY)
  • Mon: abbreviated month (ex: Jan)
  • MON: abbreviated month capitalised (ex: JAN)
  • D: day number (1 - 31)
  • DD: day number (1 - 31), zero padded
  • Day: long day of week string (ex: Monday)
  • DAY: long day of week string capitalised (ex: MONDAY)
  • Dy: abbreviated day of week string (ex: Mon)
  • DY: abbreviated day of week string capitalised (ex: MON)
  • H: hour number (0 - 23)
  • HH: hour number (00 - 23), zero padded
  • h: hour number (1 - 12)
  • hh: hour number (01 - 12), zero padded
  • m: minute number (0 - 59)
  • mm: minute number (00 - 59), zero padded
  • S: second number (0 - 59)
  • SS: second number (00 - 59), zero padded
  • ms: milliseconds (000 - 999), zero padded
  • P: AM or PM
  • p: am or pm
Parameters:
str the QoreString where the formatted date data will be written (appended)
fmt the format string as per the above description

DLLEXPORT bool DateTime::isRelative (  )  const

returns true if the value is a relative date-time value

Returns:
true if the value is a relative date-time value

DLLEXPORT bool DateTime::isAbsolute (  )  const

returns true if the value is an absolute date-time value

Returns:
true if the value is an absolute date-time value

DLLEXPORT short DateTime::getYear (  )  const

returns the year portion of the date-time value

Returns:
the year portion of the date-time value

DLLEXPORT int DateTime::getMonth (  )  const

returns the month portion of the date-time value

Returns:
the month portion of the date-time value

DLLEXPORT int DateTime::getDay (  )  const

returns the day portion of the date-time value

Returns:
the day portion of the date-time value

DLLEXPORT int DateTime::getHour (  )  const

returns the hour portion of the date-time value

Returns:
the hour portion of the date-time value

DLLEXPORT int DateTime::getMinute (  )  const

returns the minute portion of the date-time value

Returns:
the minute portion of the date-time value

DLLEXPORT int DateTime::getSecond (  )  const

returns the second portion of the date-time value

Returns:
the second portion of the date-time value

DLLEXPORT int DateTime::getMillisecond (  )  const

returns the millisecond portion of the date-time value

Returns:
the millisecond portion of the date-time value

DLLEXPORT int64 DateTime::getRelativeSeconds (  )  const

returns the difference as the number of seconds between the date/time value and the local time at the moment of the call

Returns:
the difference as the number of seconds between the date/time value and the local time at the moment of the call

DLLEXPORT int64 DateTime::getRelativeMilliseconds (  )  const

returns the difference as the number of milliseconds between the date/time value and the local time at the moment of the call

Returns:
the difference as the number of milliseconds between the date/time value and the local time at the moment of the call

static DLLEXPORT class DateTime* DateTime::getDateFromISOWeek ( int  year,
int  week,
int  day,
class ExceptionSink xsink 
) [static]

returns a DateTime value from ISO-8601 week and day offsets

note that ISO-8601 week days go from 1 - 7 = Mon - Sun a 0 return value means an exception was raised

Parameters:
year the year portion of the date in which the ISO-8601 week is found in
week the ISO-8601 week number
day the day offset in the week (1-7 = Mon-Sun)
xsink if an error occurs, the Qore-language exception information will be added here
Returns:
the DateTime value corresponding to the ISO-8601 week information (or 0 if an error occured)

Reimplemented in DateTimeNode.


The documentation for this class was generated from the following file:

Generated on Mon Oct 26 09:09:49 2009 for Qore Programming Language by  doxygen 1.5.6