Module: DB Interface Module Group: Data Type Classes
Does not inherit
#include <rw/db/datetime.h> RWDBDateTime now; // construct current date and time RWDBDateTime then((unsigned)1993,2,27,10,2,54)
NOTE -- Class RWDBDateTime is deprecated. Please use RWDateTime. For more information, see Section 7.4.3 of the DB Interface Module User's Guide and the entry for RWDateTime in the Essential Tools Module Reference Guide.
RWDBDateTime represents a date and time stored as the number of milliseconds since January 1 1901 00:00:00:000 UTC. 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, RWDateTime, 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 Essential Tools Module Reference Guide for further discussion of RWLocale.
RWDate, RWTime, and RWDateTime can be used to create RWDBDateTime instances. Please see your Essential Tools Module documentation for information on RWDate, RWTime, and RWDateTime.
RWLocale is used to format the output of RWDBDateTime. Please see your Essential Tools Module documentation for information on RWLocale. Note that the character u can be used with RWLocale to denote milliseconds.
typedef enum Persistence { Default, Legacy };
Member that provides compatibility with the old storage format.
NOTE -- For more information on persistence in RWDBDateTime, see Section 7.4.3.2 in the DB Interface Module User's Guide.
static void persistence(const RWDBDateTime::Persistence per);
Sets the persistence to either Persistence::Default or Persistence::Legacy. This affects the member functions saveOn() and restoreFrom().
static Persistence persistence(void);
Returns a copy of the current persistence mechanism in use.
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.
RWDBDateTime(const RWDBDateTime&);
Copy constructor. RWDBDateTime obeys value semantics.
explicit RWDBDateTime(const RWDateTime&);
Conversion constructor. Constructs an instance of RWDBDateTime out of an instance of RWDateTime.
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.
operator RWDateTime();
Conversion operator. Used to convert an instance of RWDBDateTime to an instance of RWDateTime.
RWDBDateTime& operator=(const RWDBDateTime& dt);
Assignment operator. RWDBDateTime obeys value semantics.
RWDBDateTime addDays(long int num);
Adds num days to self. The result is not necessarily a valid date. For example, April 1 2000 2:03am plus one day is not a valid date.
RWDBDateTime addHours(rwint64 num);
Adds num hours to self.
RWDBDateTime addMilliseconds(rwint64 num);
Adds num milliseconds to self.
RWDBDateTime addMinutes(rwint64 num);
Adds num minutes to self.
RWDBDateTime addMonths(long 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(rwint64 num);
Adds num seconds to self.
RWDBDateTime addYears(long 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(char format = (char)'\0', 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 except for the `u' character which will print the milliseconds. The default format is `\0', which is the same as `x X'. See RWLocale in the Essential Tools Module Reference Guide for a complete listing of possible formats.
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 except for the `u' character which will print the milliseconds. The default format is the date followed by the time: x X. See RWLocale in the Essential Tools Module Reference Guide for a complete listing of possible formats.
bool 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 RWZone& zone = RWZone::local()) const;
Returns the day of the year (1 - 366) of self, adjusted to the given time zone.
unsigned dayOfMonth(const RWZone& zone = RWZone::local()) const;
Returns the day of the month (1 - 31) of self, adjusted to the given time zone.
void extract(struct tm* tmbuf, const RWZone& zone = RWZone::local()) const;
Returns with the tm argument filled out entirely. 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 0 if RWZone does not observe DST and to 1 if DST is observed.
unsigned firstDayOfMonth(const RWZone& zone = RWZone::local()) const;
Returns the day of the year (1 - 366) corresponding to the first day of self's month, adjusted to the given time zone.
unsigned firstDayOfMonth(unsigned month, const RWZone& zone = RWZone::local()) const;
Returns the day of the year (1 - 366) corresponding to the first day of the given month (1 - 12) in self's year, adjusted to the given time zone.
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).
bool isDST(const RWZone& zone = RWZone::local()) const;
Returns true if self is during daylight-saving time in the specified time zone, otherwise returns false.
bool isEqual(const RWDBDateTime& dt) const;
Returns true if compareTo(this, &dt) == 0, otherwise returns false.
bool isValid() const;
Returns true if self represents a valid date and time, otherwise returns false.
bool leap(const RWZone& zone = RWZone::local()) const;
Returns true if self represents a leap year, otherwise returns false. Result is adjusted to the given time zone.
RWDBDateTime max(const RWDBDateTime& dt) const;
Returns the later of self and dt.
rwint64 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 RWZone& zone = RWZone::local()) const;
Returns the month number (1 - 12) of self, adjusted to the given time zone.
RWCString monthName(const RWLocale& locale = RWLocale::global(), const RWZone& zone = RWZone::local()) const;
Returns the name of self's month, formatted for the given locale, adjustted to the given time zone.
void now();
Sets self to the current date and time.
RWDBDateTime previous(unsigned dayNum, const RWZone& zone = RWZone::local()) 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. Result is adjusted to the given time zone.
RWDBDateTime previous(const char* dayName, const RWLocale& locale = RWLocale::global(), const RWZone& zone = RWZone::local()) const;
Returns an RWDBDateTime representing the previous dayName, for example, the previous Monday. The dayName is interpreted according to the given locale. Result is adjusted to the given time zone.
void restoreFrom(RWFile& file);
Reads file, replacing the contents of self. There are two ways or reading and writing the date. See the persistence member functions or the SourcePro DB User's Guide for details.
void restoreFrom(RWvistream& vis);
Reads vis, replacing contents of self. There are two ways of reading and writing the date. See the persistence member functions or the SourcePro DB User's Guide for details.
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. There are two ways of reading and writing the date. See the persistence() member functions or the Source Pro DB User's Guide for details.
void saveOn(RWvostream& vos) const;
Writes contents of self to vos. There are two ways of reading and writing the date. See the persistence() member functions or the Source Pro DB User's Guide for details.
unsigned second() const;
Returns the seconds part of self.
unsigned rwint64 seconds() const;
Returns the number of seconds since 00:00:00 January 1, 1901 UTC.
unsigned weekDay(const RWZone& zone = RWZone::local()) const;
Returns the weekdays number (Monday = 1, ..., Sunday = 7) of self, adjusted to the given time zone.
RWCString weekDayName(const RWLocale& locale = RWLocale::global(), const RWZone& zone = RWZone::local()) const;
Returns the name of self's weekdays, formatted for the given locale, adjusted to the given time zone.
unsigned year(const RWZone& zone = RWZone::local()) const;
Returns the year part of self, adjusted to the given time zone.
bool operator<(const RWDBDateTime& dt1, const RWDBDateTime& dt2);
Returns true if dt1 is before dt2, otherwise returns false.
bool operator<=(const RWDBDateTime& dt1, const RWDBDateTime& dt2);
Returns true if dt1 is earlier or the same as dt2, otherwise returns false.
bool operator>(const RWDBDateTime& dt1, const RWDBDateTime& dt2);
Returns true if dt1 is after dt2, otherwise returns false.
bool operator>=(const RWDBDateTime& dt1, const RWDBDateTime& dt2);
Returns true if dt1 is after or the same as dt2, otherwise returns false.
bool operator==(const RWDBDateTime& dt1, const RWDBDateTime& dt2);
Returns true if dt1 is the same as dt2, otherwise returns false.
bool operator!=(const RWDBDateTime& dt1, const RWDBDateTime& dt2);
Returns true if dt1 is not the same as dt2, otherwise returns false.
© Copyright Rogue Wave Software, Inc. All Rights Reserved.
Rogue Wave and SourcePro are registered trademarks of Rogue Wave Software, Inc. in the United States and other countries. All other trademarks are the property of their respective owners.
Contact Rogue Wave about documentation or support issues.