Just as you used Date Format to convert ColdFusion’s internal dates into user-readable formats you can use Time Format to do the same for times. By default the ColdFusion date format stores information about both date and time and these same values are used by TimeFormat to produce user-friendly strings
TimeFormat takes two arguments: TimeFormat(Time ,Mask). By default when no mask is provided, times are output in the form 07: 35 AM or 11: 52 pm
Aside from using relevant punctuation such as a colon masks are built from the following special characters:
h Displays the hour as a number from the 12-hour clock with no leading zero on single-
hh Displays the hour as a number from the 12-hour clock with a leading zero on single-
H Displays the hour as a number from the 24-hour clock with no leading zero on single-
HH Displays the hour as a number from the 24-hoUI clock with a leading zero on single-
m Displays the minutes with no leading zero on single-digit numbers
III!I Displays the minutes with a leading zero on single-digit numbers
5 Displays the seconds with no leading zero on single-digit numbers
55 Displays the seconds with a leading zero on single-digit numbers
t Displays a single character, A or P, indicating AM or PM
tt Displays AM or PM
Formatting Boolean Values
Boolean values (those that are true or false or 1 or 0) are usually viewed by users in yes no terms. That is a true value equates to yes and a false value equates to no.
The Yes No Format function returns YESor NOas appropriate based on a Boolean or numeric argument: YesNoFormat(Va 1ue). True values and nonzero numbers cause YES to be returned. False values and zero cause NOto be returned .
Handling International Locales
You have probably noticed the U.S.-centric nature of the functions we have discussed for formatting data. For instance, the DollarFormat function is clearly aimed at North America and the default formats for many functions are also American-centric (consider the default 12-hour clock format of the Ti meFormat function
Cold Fusion provides a series of formatting functions that result in output that is dependent on the current locale of the server. When Cold Fusion starts, it generates a list of supported locales for ColdFusion and the operating system. ColdFusion supports the following locales listed in this table.
English (New Zealand) .
. Italian (Swiss)
The Set Locale function can be used to set a new locale as the current locale (for instance Set Locale(” Eng1ish (US) “). GetLoca1 e returns the current locale
Table 12.4 provides an outline of the international formatting functions their corresponding standard functions, and their descriptions and usage.
The CFSETTING tag takes the following two possible attributes both of which are relevant to output
ENABLECFOUTPlTTONL Y This is a required attribute. If set to YES it indicates that only subsequent output within CFOUTPUT tags should be displayed. This state continues until another CFSETTING tag sets the value of ENABlECFOUTPUTONl Y to NO.
SHOWDEBUGOUTPUT This is an optional attribute. When set to NO,it suppresses debugging information that is displayed at the end of pages when errors OCCUI. By default the value is YES.
What concerns us is the ENABLECFOUTPUTONLY attribute. The main advantage of this tag i sthat it is usedto eliminate excess source code from the HTML generated by a template. For instance the following template:
<CFSET C-A + B>
The result ;s tet
generates source code that has a blank line for each line of purely ColdFusion code. That means there are four blank lines before the one line of output and one blank line after it in the source code
The result is #C#
In large templates this can mean many blank lines in a large block of ColdFusion code. By setting ENABlECFOUTPUTONl Y to YES you require all output destined to be in the final source code to appear between beginning and ending CFOUTPUT tags. This eliminates excess blank lines caused by the processing of Cold Fusion code so that the following lines of code:
<CFSET C-A + B> •
The result is IC#
will have only one excess blank line in the source code output (that being the line of the CFSmING tag itself):
The result is 3
Where Do We Go from Here?.
This chapter has been far reaching covering many advanced aspects of output-from grouping and nesting the results of queries to easily formatting a variety of data formats by using ColdFusion functions.
In the next chapter you will learn about a central programming concept: loops. In a sense you have already learned about loops while learning to use CFOUTPUT which effectively enables you to loop through a query result and perform the same action each time through the loop.
In the next-chapter though you will learn about the CFLooP tag which provides much more power than CFOUTPUT (in fact CFLooP can be used to recreate the exact behavior of CFOUTPUT and more). CFLOCP is less restricted in terms of the types of actions that can be performed on the data that is being looped through and it can be used in many more circumstances