DB Link
API Reference Guide
Product Documentation:

Visualization DB Link
Documentation Home
List of all members | Public Member Functions
IldDateTime Class Reference

Provides data members, member functions, and operators to manage dates and times as objects. More...

#include <ildblink/ilidtime.h>

Inherited by IldUnicodeDateTime.

Public Member Functions

 IldDateTime (IlEnvironment *envt)
 Initializes an empty instance of IldDateTime refers to the given environment. More...
 
 IldDateTime (IlEnvironment *envt, IldDateTime &dt)
 Initializes a new instance of IldDateTime that refers to the given environment using the value of another IldDateTime. More...
 
 IldDateTime (IlEnvironment *envt, short year, IlUShort month, IlUShort day, IlUShort hour=0, IlUShort minute=0, IlUShort second=0, IlUShort msecond=0)
 Initialializes a new instance of IldDateTime in which the data members are initialized to the provided parameter values. More...
 
virtual ~IldDateTime ()
 Cleans up the instance. More...
 
IlBoolean get (short &y, IlUShort &mth, IlUShort &d, IlUShort &h, IlUShort &m, IlUShort &s, IlUShort &ms)
 Gets all date and time values. More...
 
IlUShort getDay () const
 Gets the day. More...
 
IlUShort getHour () const
 Gets the hour. More...
 
IlUShort getMinute () const
 Gets the minutes. More...
 
IlUShort getMonth () const
 Gets the month. More...
 
IlUShort getMSecond () const
 Gets the millisecond. More...
 
IlUShort getSecond () const
 Gets the second. More...
 
IlInt getTime () const
 Gets the time. More...
 
short getYear () const
 Gets the year. More...
 
 operator IlInt () const
 Gets the time. More...
 
void set (short year, IlUShort month, IlUShort day, IlUShort hour, IlUShort minute, IlUShort second, IlUShort msecond=0)
 Sets the date and time. More...
 
void setDate (short year, IlUShort month, IlUShort day)
 Sets the date. More...
 
void setDay (IlUShort day)
 Assigns the day. More...
 
void setHour (IlUShort hour)
 Assigns the hour. More...
 
void setMinute (IlUShort minute)
 Assigns the minute. More...
 
void setMonth (IlUShort month)
 Assigns the month. More...
 
void setMSecond (IlUShort msecond)
 Assigns the millisecond. More...
 
IlBoolean setNow ()
 Sets the date and time values to be those of the exact moment this function is called. More...
 
void setSecond (IlUShort second)
 Assigns the seconds. More...
 
void setTime (IlUShort hour, IlUShort minute, IlUShort second, IlUShort msecond=0)
 Sets the time specification. More...
 
void setYear (short year)
 Assigns the year. More...
 

Detailed Description

Provides data members, member functions, and operators to manage dates and times as objects.

Library: dbkernel

By default, DB Link handles dates and times as character strings. But this choice creates dependence upon the way the client API of the particular RDBMS formats dates and times as data values. To achieve independence from the configuration of the RDBMS, DB Link defines the class IldDateTime to handle DATE, TIME, DATETIME, INTERVAL, and TIMESTAMP values (whichever of these exist in the RDBMS that you are accessing).

Compared to previous versions, this class has been enhance to provide internationalization capabilities. Most methods existing in former versions have been redefined to support the internationalization constraints.

Note
The former methods, that do not make use of the internationalization context, have been kept for compatibility but are deprecated and will be removed from the library in a future version. When developing a globalized application these methods should be avoided and preference should be given to the new methods.

The constructors and methods of the IldDateTime class are redefined but do not take into account the environment (time zone and locale); New, but equivalent, constructors are defined that take an IlEnvironment object as their first argument. These constructors do make use, and keep a reference to, the time zone and locale set in this environment object.

Note
The environment reference should be valid during the whole life-time of the date/time object.

If the "date as string" feature is turned off, DB Link sends dates and times to the database, or retrieves dates and times from the database, using instances of this class.

Warning
When you use an instance of IldDateTime as input, beware that DB Link does no checking to enforce the correctness of the value. In fact, none of the modifiers in this class check the value of their arguments. You must make sure that the value of a month is between 1 and 12, the value of a day is between 1 and 31, and so on.

The range of valid years for DB Link is from -32767 to 32767. However, the range of the valid years in the particular RDBMS that you are using probably differs.

RDBMSRange of Valid Years
IBM DB20001 through 9999
Informix0001 through 9999
MS SQL1753 through 9999
ODBC0 through 9999 (depending on the target RDBMS)
Oracle-4712 through 9999
Sybase1753 through 9999

The accessors (member functions that begin with get) have a range of valid values. For example, the range of valid values for getHour() is 0 to 23. The parameter values passed to the modifiers (member functions that begin with set) must be within the appropriate range because DB Link does not check their validity.

See also
IldColumnType, "Date As String" feature and "Handling Date and Time Values" in the Rogue Wave Views DB Link User's Manual.

Constructor & Destructor Documentation

◆ IldDateTime() [1/3]

IldDateTime::IldDateTime ( IlEnvironment envt)

Initializes an empty instance of IldDateTime refers to the given environment.

Parameters
envtA valid environment object.

Initially the value is set to the epoch origin following the UNIX convention (1970/01/01 00:00:00.000).

When retrieving the display form of the date and time object, the locale and time zone of the current environment are used.

See also
getString().

◆ IldDateTime() [2/3]

IldDateTime::IldDateTime ( IlEnvironment envt,
IldDateTime dt 
)

Initializes a new instance of IldDateTime that refers to the given environment using the value of another IldDateTime.

Parameters
envtA valid environment object.
dtAn existing date time object.

When retrieving the display form of the date and time object, the locale and time zone of the current environment are used.

See also
getString().

◆ IldDateTime() [3/3]

IldDateTime::IldDateTime ( IlEnvironment envt,
short  year,
IlUShort  month,
IlUShort  day,
IlUShort  hour = 0,
IlUShort  minute = 0,
IlUShort  second = 0,
IlUShort  msecond = 0 
)

Initialializes a new instance of IldDateTime in which the data members are initialized to the provided parameter values.

Parameters
envtA valid environment object.
yearThe value for the year field of the date.
monthThe value for the month field of the date.
dayThe value for the day field of the date.
hourThe value for the hour field of the time.
minuteThe value for the minute field of the time.
secondThe value for the second field of the time.
msecondThe value for the millisecond field of the time.

Any data member for which a parameter is not passed is initialized to 0 (zero).

The given values are supposed to be relative to the time zone from the environment.

Note
  1. The value for the month number is 1-based following the usual convention; that is the month number for January is 1.
  2. The hour value is the hour in the day, that is ranges from 0 to 24.

◆ ~IldDateTime()

virtual IldDateTime::~IldDateTime ( )
virtual

Cleans up the instance.

The environment value setting is not altered.

Member Function Documentation

◆ get()

IlBoolean IldDateTime::get ( short &  y,
IlUShort mth,
IlUShort d,
IlUShort h,
IlUShort m,
IlUShort s,
IlUShort ms 
)

Gets all date and time values.

Parameters
yOn ouptut, will contain the year number.
mthOn ouptut, will contain the month number.
dOn ouptut, will contain the day number in month.
hOn ouptut, will contain the number of hours.
mOn ouptut, will number of minutes.
sOn ouptut, will contain the number of seconds.
msOn ouptut, will contain the number of millisecond. If the number of milliseconds was not set, ms is set to 0.
Returns
IlTrue if all values retrieval succeeded.
Note
In case an error happened, the object will be set in the bogus state (isBad() call will return IlTrue).

◆ getDay()

IlUShort IldDateTime::getDay ( ) const

Gets the day.

Returns
The day or the maximum unsigned short integer (USHRT_MAX).

◆ getHour()

IlUShort IldDateTime::getHour ( ) const

Gets the hour.

Returns
The hour or the maximum unsigned short integer (USHRT_MAX).

The range of valid hours is 0 through 23.

Note
The hour is always relative to the day, thus the returned value is not in the range 0-12 but 0-23.

◆ getMinute()

IlUShort IldDateTime::getMinute ( ) const

Gets the minutes.

Returns
The minute or the maximum unsigned short integer (USHRT_MAX).

◆ getMonth()

IlUShort IldDateTime::getMonth ( ) const

Gets the month.

Returns
The month or the maximum unsigned short integer (USHRT_MAX).

The range of valid month number starts from 1.

◆ getMSecond()

IlUShort IldDateTime::getMSecond ( ) const

Gets the millisecond.

Returns
The millisecond or the maximum unsigned short integer (USHRT_MAX).

◆ getSecond()

IlUShort IldDateTime::getSecond ( ) const

Gets the second.

Returns
The second or the maximum unsigned short integer (USHRT_MAX).

◆ getTime()

IlInt IldDateTime::getTime ( ) const

Gets the time.

Returns
An integer indicating the time of day in number of seconds elapsed since midnight.

◆ getYear()

short IldDateTime::getYear ( ) const

Gets the year.

Returns
The year value or the smallest short number (SHRT_MIN).

◆ operator IlInt()

IldDateTime::operator IlInt ( ) const

Gets the time.

Returns
An integer indicating the time of day in number of seconds elapsed since midnight.

That is, it returns the same value as getTime().

◆ set()

void IldDateTime::set ( short  year,
IlUShort  month,
IlUShort  day,
IlUShort  hour,
IlUShort  minute,
IlUShort  second,
IlUShort  msecond = 0 
)

Sets the date and time.

Parameters
yearA valid year number.
monthA valid month number.
dayA valid day number in month.
hourA valid number of hours.
minuteA valid number of minutes.
secondA valid number of seconds.
msecondA valid number of millisecond.
See also
setYear(), setMonth(), setDay(), setHour(), setMinute(), setSecond(), setMSecond().

◆ setDate()

void IldDateTime::setDate ( short  year,
IlUShort  month,
IlUShort  day 
)

Sets the date.

Parameters
yearA valid year number.
monthA valid month number.
dayA valid day number in month.
Note
The preexisting values of hour, minute, second and milli-second are not altered.
See also
setYear(), setMonth(), setDay().

◆ setDay()

void IldDateTime::setDay ( IlUShort  day)

Assigns the day.

Parameters
dayA valid day number in month.
Note
Valid day number ranges from 1 to 31. No internal check is made to ensure the day number is actually valid with respect to the month or year.

◆ setHour()

void IldDateTime::setHour ( IlUShort  hour)

Assigns the hour.

Parameters
hourA valid hour number.
Note
The range is relative to the day; that is ranges from 0 to 23. Giving a value less than 12 will always set an AM hour.

◆ setMinute()

void IldDateTime::setMinute ( IlUShort  minute)

Assigns the minute.

Parameters
minuteA valid minute number.

The range of valid minutes is 0 through 59.

◆ setMonth()

void IldDateTime::setMonth ( IlUShort  month)

Assigns the month.

Parameters
monthAn assumed valid month number.
Note
Valid month number range starts from 1. This is not the convention of the underlying ICU Calendar class for which month numbering starts from 0. No internal check is made to enforce the validity of the month number.
See also
getMonth(), setYear().

◆ setMSecond()

void IldDateTime::setMSecond ( IlUShort  msecond)

Assigns the millisecond.

Parameters
msecondA valid number of milliseconds.

The range of valid milliseconds is 0 through 999.

◆ setNow()

IlBoolean IldDateTime::setNow ( )

Sets the date and time values to be those of the exact moment this function is called.

Returns
IlTrue if the assignment succeeded.

◆ setSecond()

void IldDateTime::setSecond ( IlUShort  second)

Assigns the seconds.

Parameters
secondA valid number of seconds.

The range of valid seconds is 0 through 59.

◆ setTime()

void IldDateTime::setTime ( IlUShort  hour,
IlUShort  minute,
IlUShort  second,
IlUShort  msecond = 0 
)

Sets the time specification.

Parameters
hourA valid number of hours.
minuteA valid number of minutes.
secondA valid number of seconds.
msecondA valid number of millisecond.
Note
The preexisting values of year, month and day are not altered.
See also
setHour(), setMinute(), setSecond(), setMSecond().

◆ setYear()

void IldDateTime::setYear ( short  year)

Assigns the year.

Parameters
yearA valid year number.
Note
Beware no internal check is made on the validity of this number. This is intentional as it allows you to use calendars different from the Gregorian one.