#include <rw/db/datetime.h> RWDBDateTime now; // construct current date and time RWDBDateTime then((unsigned)1993,2,27,10,2,54)
RWDBDateTime represents a date stored as a Julian day number, plus a time stored as the number of milliseconds since midnight. The member function isValid() can be used to determine whether an RWDBDateTime is a valid date and time. Note that RWDBDateTime is instantiated from the local system and not the database.
RWDBDateTime instances can be converted to and from RWDate and/or RWTime instances, and to and from the Standard C library type struct tm defined in <time.h>.
Output formatting is done using an RWLocale object. The default locale formats data according to US conventions. See the Tools.h++ Class Reference for further discussion of RWLocale.
Because the default constructor for this class creates an instance holding the current date and time as provided by the local system, constructing a large array of RWDBDateTimes may be quite slow. If this is an issue, declare your arrays with a class derived from RWDBDateTime that provides a faster constructor.
RWDate and RWTime can be used to create RWDBDateTime instances. Please see your Tools.h++ documentation for information on RWDate and RWTime.
RWLocale is used to format the output of RWDBDateTime. Please see your Tools.h++ documentation for information on RWLocale. Note that the character u can be used with RWLocale to denote milliseconds.
RWDBDateTime();
The default constructor creates an instance holding the current date and time. Note that RWDBDateTime is instantiated from the local system and not the database. The millisecond part of self is set to zero.
RWDBDateTime(const RWDBDateTime&);
Copy constructor. RWDBDateTime obeys value semantics.
RWDBDateTime(const struct tm* tm, const RWZone& zone = RWZone::local());
Constructs an RWDBDateTime from the tm_year, tm_mon, tm_mday, tm_hour, tm_minute, and tm_sec components of tm, with
milliseconds = 0. These components are understood to be relative to the time zone, zone, which defaults to local time. Note that the numbering of months and years in a struct tm differs from numbering in RWDBDateTime arguments.
RWDBDateTime(const RWTime& time, const RWZone& zone = RWZone::local());
Constructs an RWDBDateTime from the date and time provided by RWTime. The time component is understood to be relative to the time zone, zone, which defaults to local time.
RWDBDateTime(const RWDate& date, unsigned hour = 0, unsigned minute = 0, unsigned second = 0, unsigned millisecond = 0, const RWZone& zone = RWZone::local());
Constructs an RWDBDateTime from the given date and the given time components. The time components are taken to be relative to the time zone, zone, which defaults to local time.
RWDBDateTime(const RWDate& date, const RWCString& str, const RWZone& zone = RWZone::local(), const RWLocale& = RWLocale::global());
Constructs an RWDBDateTime for the given date, extracting the time from the string str. The time is understood to be relative to the time zone, zone, which defaults to local time. The specified locale is used for formatting information. You can use isValid() to check the results.
RWDBDateTime(unsigned year, unsigned month, unsigned day, unsigned hour = 0, unsigned minute = 0, unsigned second = 0, unsigned millisecond = 0, const RWZone& zone = RWZone::local());
Constructs an RWDBDateTime from the given components. The date and time components are understood to be relative to the time zone, zone, which defaults to local time.
RWDBDateTime(unsigned long jd, unsigned hour = 0, unsigned minute = 0, unsigned second = 0, unsigned millisecond = 0, const RWZone& zone = RWZone::local());
Constructs an RWDBDateTime from the Julian Day number jd and the given time components. The time components are understood to be relative to the time zone, zone, which defaults to local time.
RWDBDateTime& operator=(const RWDBDateTime& dt);
Assignment operator. RWDBDateTime obeys value semantics.
RWDBDateTime addDays(int num);
Adds num days to self.
RWDBDateTime addHours(int num);
Adds num hours to self.
RWDBDateTime addMilliseconds(long num);
Adds num milliseconds to self.
RWDBDateTime addMinutes(int num);
Adds num minutes to self.
RWDBDateTime addMonths(int num);
Adds num months to self's month part. The result is not necessarily a valid date. For example, January 31 plus one month is not a valid date.
RWDBDateTime addSeconds(int num);
Adds num seconds to self.
RWDBDateTime addYears(int num);
Adds num years to self's years part. The result is not necessarily a valid date. For example, February 29 1992 plus one year is not a valid date.
RWCString asString() const;
Returns asString('\0', RWZone::local(), RWLocale::global()).
RWCString asString(char format, const RWZone& zone = RWZone::local(), const RWLocale& locale = RWLocale::global()) const;
Returns self as a string, formatted by the given locale, with the time zone adjusted according to the given zone. The valid values for format are as defined by RWLocale. The default format is '\0', which is the same as 'x X'. See RWLocale in the Tools.h++ Class Reference for a complete listing of possible formats.
RWCString asString(const char *format) const;
Returns asString(format,RWZone::local(),RWLocale::global()). See the description of the following asString() function.
RWCString asString(const char* format, const RWZone& zone = RWZone::local(), const RWLocale& locale = RWLocale::global())const;
Returns self as a string, formatted by the given locale, with the time zone adjusted according to the given zone. The format string may consist of any sequence of characters containing single formats as defined by RWLocale. Preceding a single format character with a % escapes the character for inclusion in the resulting string. The default format is the date followed by the time: x X. See RWLocale in the Tools.h++ Class Reference for a complete listing of possible formats.
RWBoolean between(const RWDBDateTime& dt1, const RWDBDateTime& dt2) const;
Returns TRUE if self is between dt1 and dt2, inclusive.
RWspace binaryStoreSize() const;
Returns the number of bytes necessary to store self.
int compareTo(const RWDate* d) const;
Comparison function. Returns -1, 0, or 1, depending upon whether self's date part is less than, equal to, or greater than the RWDate addressed by d.
int compareTo(const RWDBDateTime* dt) const;
Comparison function. Returns -1, 0, or 1, depending upon whether self is less than, equal to, or greater than the RWDBDateTime addressed by dt.
int compareTo(const RWTime* t) const;
Comparison function. Returns -1, 0, or 1, depending upon whether self's time part is less than, equal to, or greater than the RWTime addressed by t.
unsigned day() const;
Returns the day of the year (1 - 366) of self.
unsigned dayOfMonth() const;
Returns the day of the month (1 - 31) of self.
void extract(struct tm* tmbuf, const RWZone& zone = RWZone::local()) const;
Returns with the tm argument filled out entirely, with tm_isdst set to -1. Note that the encoding for months and days of the week used in struct tm differs from that used in RWDBDateTime. If self is invalid, all fields in tm are set to -1.
unsigned firstDayOfMonth() const;
Returns the day of the year (1 - 366) corresponding to the first day of self's month.
unsigned firstDayOfMonth(unsigned month) const;
Returns the day of the year (1 - 366) corresponding to the first day of the given month (1 - 12) in self's year.
unsigned hash() const;
Returns a suitable hashing value.
unsigned hour(const RWZone& zone = RWZone::local()) const;
Returns the hour part of self, adjusted to the given time zone.
unsigned hourGMT() const;
Returns self's hour in UTC (GMT).
RWBoolean isDST(const RWZone& zone = RWZone::local()) const;
Returns TRUE if self is during daylight-saving time in the specified time zone, otherwise returns FALSE.
RWBoolean isEqual(const RWDBDateTime& dt) const;
Returns TRUE if compareTo(this, &dt) == 0, otherwise returns FALSE.
RWBoolean isValid() const;
Returns TRUE if self represents a valid date and time, otherwise returns FALSE.
RWBoolean leap() const;
Returns TRUE if self represents a leap year, otherwise returns FALSE.
RWDBDateTime max(const RWDBDateTime& dt) const;
Returns the later of self and dt.
unsigned millisecond() const;
Returns the milliseconds part of self.
RWDBDateTime min(const RWDBDateTime& dt) const;
Returns the earlier of self and dt.
unsigned minute(const RWZone& timezone = RWZone::local()) const;
Returns the minutes part of self, adjusted to the given timezone.
unsigned minuteGMT() const;
Returns self's minute in UTC (GMT).
unsigned month() const;
Returns the month number (1 - 12) of self.
RWCString monthName(const RWLocale& locale = RWLocale::global()) const;
Returns the name of self's month, formatted for the given locale.
void now();
Sets self to the current date and time. The millisecond part of self is set to zero (0).
RWDBDateTime previous(unsigned dayNum) const;
Returns an RWDBDateTime representing the previous numbered day of the week, where Monday = 1, ..., Sunday = 7. The argument dayNum must be between 1 and 7, inclusive.
RWDBDateTime previous(const char* dayName, const RWLocale& locale = RWLocale::global()) const;
Returns an RWDBDateTime representing the previous dayName, for example, the previous Monday. The dayName is interpreted according to the given locale.
void restoreFrom(RWFile& file);
Reads file, replacing the contents of self.
void restoreFrom(RWvistream& vis);
Reads vis, replacing contents of self.
RWDate rwdate() const;
Returns the date portion of self as an RWDate.
RWTime rwtime() const;
Returns the time portion of self as an RWTime.
void saveOn(RWFile& file) const;
Writes contents of self to file.
void saveOn(RWvostream& vos) const;
Writes contents of self to vos.
unsigned second() const;
Returns the seconds part of self.
unsigned long seconds() const;
Returns the number of seconds since 00:00:00 January 1, 1901 UTC.
unsigned weekDay() const;
Returns the weekdays number (Monday = 1, ..., Sunday = 7) of self.
RWCString weekDayName(const RWLocale& locale = RWLocale::global()) const;
Returns the name of self's weekdays, formatted for the given locale.
unsigned year() const;
Returns the year part of self.
RWBoolean operator<(const RWDBDateTime& dt1, const RWDBDateTime& dt2);
Returns TRUE if dt1 is before dt2, otherwise returns FALSE.
RWBoolean operator<=(const RWDBDateTime& dt1, const RWDBDateTime& dt2);
Returns TRUE if dt1 is earlier or the same as dt2, otherwise returns FALSE.
RWBoolean operator>(const RWDBDateTime& dt1, const RWDBDateTime& dt2);
Returns TRUE if dt1 is after dt2, otherwise returns FALSE.
RWBoolean operator>=(const RWDBDateTime& dt1, const RWDBDateTime& dt2);
Returns TRUE if dt1 is after or the same as dt2, otherwise returns FALSE.
RWBoolean operator==(const RWDBDateTime& dt1, const RWDBDateTime& dt2);
Returns TRUE if dt1 is the same as dt2, otherwise returns FALSE.
RWBoolean operator!=(const RWDBDateTime& dt1, const RWDBDateTime& dt2);
Returns TRUE if dt1 is not the same as dt2, otherwise returns FALSE.
©Copyright 1999, Rogue Wave Software, Inc.
Contact Rogue Wave about documentation or support issues.