Newton 2.x Q&A Category: Localization

Copyright © 1997 Newton, Inc. All Rights Reserved. Newton, Newton Technology, Newton Works, the Newton, Inc. logo, the Newton Technology logo, the Light Bulb logo and MessagePad are trademarks of Newton, Inc. and may be registered in the U.S.A. and other countries. Windows is a registered trademark of Microsoft Corp. All other trademarks and company names are the intellectual property of their respective owners.


For the most recent version of the Q&As on the World Wide Web, check the URL: http://www.newton-inc.com/dev/techinfo/qa/qa.htm
If you've copied this file locally, click here to go to the main Newton Q&A page.
This document was exported on 7/23/97.

Localization


StringToDateFrame & StringToTime Don't Use Seconds (5/9/96)

Q: When passed a string with seconds, for example "12:23:34", StringToDateFrame and StringToTime don't seem to work. StringToDateFrame returns a frame with NIL for all the time & day slots, and StringToTime returns NIL.

A: To correctly handle strings with seconds, seconds must be stripped from the string. If the application might be used outside the US, check for the Locale time delimiter. Here is a function which prepares a string for StringToDateFrame and StringToTime:
    PrepareStringForDateTime := func (str)
    begin   // str is just a time string, nothing else belongs 
        local newStr := clone (str);
        local tf:= GetLocale().timeFormat;
        local startMin := StrPos (str, tf.timeSepStr1, 0);
        local startSec := StrPos (str, tf.timeSepStr2, startMin+1);
        // If a time seperator for seconds, then strip out seconds
        if startSec then        

            begin
                local skipSecSep := startSec + StrLen (tf.timeSepStr2);
                local remainderStr := SubStr (
                    str, skipSecSep, StrLen (str) - skipSecSep);
                local appendStr := StringFilter (
                    remainderStr, "1234567890", 'rejectBeginning);
                newStr := SubStr (str, 0, startSec) & appendStr;
        end;
        return newStr;
    end;


How GetDateStringSpec Uses Its Element Array (3/31/97)

Q: It appears that the compile-time function GetDateStringSpec formats the supplied date elements in reverse order. Is this is a bug?

A: This is the defined behavior. The Newton Programmer's Guide implies that the order does not matter, but that is not correct. GetDateStringSpec uses the elements in reverse order, although some functions that use dateStringSpecs may not observe the order defined by the dateStringSpec. For instance, some functions may use the elements of the dateStringSpec, but use the element ordering defined by the locale bundle.

For instance, you can use this call to define a dateStringSpec for use in a locale bundle with the order Day/Month/Year:
        GetDateStringSpec([[kElementYear, kFormatNumeric],[kElementMonth,
        kFormatNumeric],[kElementDay, kFormatNumeric] ]);