Appendix A. Business logic examples 147
Rules to remember when handling dates in business logic
Consider the following rules when handling dates in business logic:
Make sure you know the date type definitions:
External format—Any of the more than 20 formats from which a Web Access user can
choose. The external format is what is seen on any HTML page or 3270 screen. It is the
format that the user employs when the user enters dates. Web Access allows each user to
choose an external date format preference. If UT is in effect, all external format date and
time pairs defined in the TIMEZONE reference record are adjusted using the user's time
zone preference.
46
Internal format—There is only one internal date format, and it is “YYYY/MM/DD.” TSX
BLQTXCVT can be used to convert any of the more than 20 external formats to and from
the internal format. Web users do not know of or use the internal format. The internal
format is important to business logic because it can be easily translated to the REXX
“Standard” date format.
Standard format—Dates in “YYYYMMDD” format (that are used by the REXX Date()
function). Standard format dates can easily be translated to internal format.
Base format—Dates in integer format, defined by the REXX Date() function as the
number of days that have passed since January 1 of the year 1. Since Base format dates
are integers, they can easily be added and subtracted.
All dates used by Web Access in CREATE, UPDATE, and RETRIEVE HLAPI/REXX
transactions are in external format.
Use BLQTXDAT to obtain the current date and time.
Avoid using the REXX Date() and Time() functions to obtain the current date and time,
since those functions do not support user date and time zone preferences.
For calculations, convert all external dates to internal dates using BLQTXCVT.
This TSX can convert more than one date at a time.
47
Use the REXX code to translate internal dates to Standard format dates and then to Base
date and back.
See the sample code included in Example A-8.
Example: A-8 Translating internal dates to Standard to Base and back
/* REXX */
date_int = '2002/05/13'
/* Remove slashes to create Standard date*/
date_std = Translate('01235689',date_int,'0123456789')
date_base = Date('B',date_std,'S') /* Standard to Base */
/* Then to go from Base to Standard to internal. */
date_std = Date('S',date_base,'B')
/* Add slashes to standard date to get internal date */
date_int = Translate('0123/45/67',date_std,'01234567')
Even if you are not using UT, build your code as though you were.
Use time_zone and date_format on any HLAPI/REXX transaction that could have dates.
This way, you do not have to recode your business logic in the event that UT is eventually
implemented.
46
See the validation data in Data Attribute record BLQ&DFMT for the complete list used by Web Access. See
BLG&DFMT for the list used by 3270 users.
47
See '“Calculating a duration: An example using BLQUXVAL” on page 148 for instructions about handling multiple
dates.
Get IBM Tivoli Web Access for Information Management now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.