< previous page page_73 next page >

Page 73
5.2
Formatting Functions
There are many ways to format times and dates. The SCDTL system supplies a relatively small number of functions for a few of the most popular formats. These functions should be considered examples, not an exhaustive suite of formatting functions.
In particular, formatting is addressed to some degree by the header files <locale.h> and <time.h>. The SCDTL system largely adopts the strategy of noninterference with the existing C standard in these areas.
Date/time formatting typically involves the use of widely used standard formats or else formats very specific to a locale. The former are covered by the function set provided, whereas the multitude of the latter cannot be covered by a function set of practical size.
As a strategic design consideration, I have avoided the temptation of writing ''giant army knife" formatting routines, which produce hundreds of formats with the expense of a huge parameter list that users find annoying and difficult to use. Maintenance is more difficult, and execution speed and size are penalized. The typical application area simply does not use that many different formats, so specialization is a preferred strategy.
5.2.1
Date Formatting
The three major formats for dates are:
YMD, or yearmonthday. This order is the most logical and useful, since dates can be sorted directly in this format. This format is often called "ISO" or "Japanese" (Listing 5.4).
DMY, or daymonthyear. This order cannot be sorted directly, but it does have the virtue of arranging the units in ascending order. This format is often called "European." [format_date_alpha_DMY ()]
MDY, or monthdayyear. This format is accepted in the United States but has little to recommend it except the fact of its use, since the order of units is an illogical jumble. [format_date_alpha_MDY ()]
Within these three major formats are infinite variations. Years may be abbreviated to two digits or expanded to four. Months may be displayed alphabetically or numerically. If alphabetical, they may be abbreviated or displayed in full. If numerical, they may display or suppress leading zeroes. The same is true for days. Days of week may be displayed, either in abbreviated or full form. The character used for a separator varies with country and often with individual preference. The slash (/), dash (-) and period (.) are common. The names of the months vary, of course, with language, as do the names of the days of the week.

 
< previous page page_73 next page >