Gadgets > Rogue Wave Views Gadgets > Using Common Gadgets > Using IlvDateField
 
Using IlvDateField
The class IlvDateField defines a special text field gadget for editing dates with various formats. IlvDateField is a subclass of IlvTextField.
Figure 11.6    A Date Field
This section covers the following topics:
*Formatting a Date
*Setting and Retrieving a Date Value
Formatting a Date
The IlvDateField can display dates in many formats. To specify the date format, use the member function setFormat.
A date is composed of three elements: the day, the month, and the year. These elements are divided by separation characters. The setFormat member function allows you to specify these elements and which separator to use.
The default value is: 12/31/1995 (df_Month, df_Day, df_Year).
The formats are defined as follows:
enum format
{
df_day, // 1
df_Day, // 01
 
df_month, // 3
df_Month, // 03
df_month_text, // March
df_abbrev_month, // Mar
 
df_year, // 95
df_Year // 1995
};
*df_day  Writes the day as a number with no leading zero.
*df_Day  Writes the day as a number with a leading zero, if necessary.
*df_month  Writes the month as a number with no leading zero.
*df_Month  Writes the month as a number with a leading zero, if necessary.
*df_month_text  Writes the month name. If the following month names appear in the language database, the corresponding name is taken from it. Otherwise, the month name is taken with the character ‘&’ removed.
Month names: &January, &February, &March, &April, &May, &June, &July, &August, &September, &October, &November, &December.
*df_abbrev_month  Writes the abbreviated month name. If the following abbreviated month names appear in the language database, the corresponding name is taken from it. Otherwise, the abbreviated month name is taken with the character ‘&’ removed.
Abbreviated month names: &january, &february, &march, &april, &may, &june, &july, &august, &september, &october, &november, &december.
*df_year  Writes the last two digits of the year.
*df_Year  Writes the year.
If you change the format when the field contains a value, this value is applied the new format.
Note: Only a single day, year, or month format can be passed to the setFormat member function. Otherwise, the function returns IlFalse and the format remains unchanged. Formats are defined in an embedded enum declaration. They are set as follows:
obj->setFormat(IlvDateField::df_day);
Examples of Formats
April,2,1995   (df_month_text, df_day, df_Year with separator ,)
2/4/95  (df_day, df_month, df_year with separator /)
02/04/1995  (df_Day, df_Month, df_Year with separator /)
Setting and Retrieving a Date Value
To set the date of an IlvDateField or retrieve it, use the member functions setValue and getValue.
Year 2000 Management
The right way to avoid problems linked to the new millenium is to use four digits to represent the year. This can be done in the IlvDateField class by using the setFormat member function.
However, if you must use a two-digits value to represent the year part of the date, the IlvDateField API offers several methods to solve the problem:
1. SetBaseCentury lets you specify the base century that will be used to recompute the full year
2. GetBaseCentury returns the base century set by SetBaseCentury. The default value is 1900
3. SetCenturyThreshold lets you specify the threshold over which the base century used will be the value returned by GetBaseCentury() plus 1
4. GetCenturyThreshold returns the value set by SetCenturyThreshold. The default value is 30
For example, with a base century of 1900 and a threshold of 30, a value of 10 is converted to 2010, and a value of 40 is converted to 1940.

Version 5.8
Copyright © 2014, Rogue Wave Software, Inc. All Rights Reserved.