background image
C H A P T E R 2 0
Localizing Newton Applications
20-12
Using the Localization Features of the Newton
To use one of these values, access the appropriate slot by dereferencing
ROM_dateTimeStrSpecs
with a dot operator, as in the following example:
LongDateStr(Time(),ROM_datetimestrspecs.longDateStrSpec);
Using these predefined format specifications also saves the trouble of defining them
at compile time and initializing slots with the compile-time variables at run time.
Format specifications available from the
ROM_dateTimeStrSpecs
object are
listed in "System-Defined Format Specifications" (page 17-11) in Newton
Programmer's Reference
Using GetDateStringSpec
20
A date or time format specification is an array, the elements of which are
themselves two-element arrays. The first element in each two-element array is a
constant specifying the item to display. The second element is a constant specifying
the format in which to display that item.
The complete set of constants is listed in "Constants to Create Your Own
Specification" (page 17-13) in Newton Programmer's Reference.
For example, the two-element array
[kElementDayOfWeek, kFormatAbbr]
specifies that the day in a date string is to be displayed in abbreviated format, such
as "Wed". On the other hand, the two-element array
[kElementDayOfWeek,
kFormatLong]
specifies that the day of the week is to be displayed in long
format, such as "Wednesday".
The following code example uses system-supplied constants to build an array of
[
element
,
format
]
pairs specifying the output of a date string. This array is
supplied as the argument to the
GetDateStringSpec
function, which returns the
format specification passed to the
LongDateStr
function. The
LongDateStr
function returns a string with the current time (returned by the
Time
function)
formatted as specified by the format specification:
// at compile time, define my array of
// element and format pairs
DefConst('myArray,
[
[kElementYear, kFormatNumeric],// year
[kElementDay, kFormatNumeric],// day of month
[kElementMonth, kFormatLong],// name of month
[kElementDayOfWeek, kFormatLong]// day of week
]);
// create the formatSpec
// this spec returns a string such as "February 1, 1994"
DefConst('kmyDateSpec, GetDateStringSpec(myArray));
© 2007-2024, o7 studio » при воспроизведении материала сайта ссылка обязательна