Additional Core facilities provide additional support for
manipulating and supporting internationalization of dates, numbers,
and currency via the dojo.date
,
dojo.number
, and dojo.currency
modules, respectively. In
Part II, you'll learn that Dijit makes
extensive use of these modules to provide advanced support for
commonly used widgets. This section provides a quick inventory of
these features.
Table 6-2 shows a quick
overview of the dojo.date
module.
As you'll see, there are some real gems in here if you ever need to
perform any routine processing of the built-in Date
object.
Table 6-2. Summary of the date module
Name | Return type | Comment |
---|---|---|
|
| Returns the number of
days in |
|
| Returns |
|
| Returns time zone
information as defined by the browser. A |
|
| Returns 0 if the two
parameters are equal; returns a positive number if |
|
| Provides a convenient
way to add an incremental amount to a |
|
| Provides a convenient
way to calculate the difference between two |
Warning
As of version 1.1 of the toolkit, getTimezoneName
is not localized.
The dojo.number
module
provides some handy functions, shown in Table 6-3 and Table 6-4, for parsing String
values into numbers, formatting a
Number
in accordance with a
specific pattern template, or rounding to a specific number of
decimal places.
Table 6-3. Formatting options for the number module that are used in the dojo.number.format and dojo.number.parse functions provided in Table 6-4
dojo.number.format options | Type | Comment |
---|---|---|
|
| Can be used to override the formatting pattern. |
|
| A format type based
on the locale. Valid values include |
|
| Provides a fixed number of places to show, which overrides any information provided by pattern. |
|
| Specifies rounding properties based on a multiple. For example, 5 would round to the nearest 0.5 and 0 would round to the nearest whole number. |
|
| A currency code that meets the ISO4217 standard. For example, "USD" would signify U.S. Dollars. |
|
| A localized currency symbol. |
|
| Allows a specific locale to be provided which drives formatting rules. |
Table 6-4. Summary of the number module
Name | Return type | Comment |
---|---|---|
|
| Formats a |
|
| Rounds a number to a given number of places after the decimal. |
|
| Converts a properly
formatted |
The dojo.currency
module,
described in Table 6-5
and Table 6-6, is similar to
dojo.number
in that it provides a
means of formatting numeric values, only this time it is currency
codes as defined in ISO427.[15]
Table 6-5. Formatting options for the currency module as used by the dojo.currency.format and dojo.currency.parse functions
Name | Type | Comment |
---|---|---|
|
| A three-letter
currency code as defined in ISO4217 such as |
|
| A value that may be used to override the default currency symbol. |
|
| Used to override the default currency pattern. |
|
| Used to provide
rudimentary rounding: |
|
| Override the default locale, which determines the formatting rules. |
|
| The number of decimal places to accept (default is defined by currency.) |
Table 6-6. Summary of the currency module
Name | Return type | Comment |
---|---|---|
|
| Formats a |
|
| Converts a properly
formatted |
Tip
Some of Dojo's build tools can be used to generate support for arbitrary locales and currencies since a lot of this work simply entails building lookup tables of information. See the file located at util/buildscripts/cldr/README for more details.
Get Dojo: The Definitive Guide 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.