Marty asked:
At 12:00am -0700 00-05-10, Palm Developer Forum digest wrote:
>Subject: Converting DayOfWeek to a string
>From: "Marty Rice" <[EMAIL PROTECTED]>
>Date: Tue, 9 May 2000 18:02:37 -0400
>X-Message-Number: 82
>
>I would like to display the day of the week after calling DayOfWeek()...
>I've got an array of strings in my application that stores the names of the
>days of the week, but as an international user of mine pointed out, it would
>be nice to display the day in the host device's language. Is there a way to
>do this using the API?
and Steve said:
>Try using the system preferences (PrefGetPreference or PrefGetPreferences).
>Preferences.h gives the system preference structures. I think the system
>preferences database has creator id 'psys' and type 'rsrc'. The days and
>months are spelled out in that database in the local language. Hope this
>helps!
Actually the system preferences don't contain the names of the days
of weeks or the months.
There are system resources that have this information, but directly
accessing them will cause compatibility problems. For example,
there's a single string that has the DOW names, separated by spaces.
On Latin devices, each name uses three bytes plus a trailing space.
On Japanese devices, each name uses two bytes (one double-byte
character) plus a space. So apps that assumed a fixed
four-bytes-per-name format fail. In the future, this DOW name string
might be removed entirely.
The compatible way to handle this is to use the DateTemplateToAscii
routine. This was added in 3.5, so there's still the issue of what to
do on older ROMs. We'll be adding a DateGlueTemplateToAscii routine
to the next release of the PalmOSGlue library, but for now the
following code snippet should work. Note that it only returns the
standard (medium) day of week name, whereas DateTemplateToAscii also
supports short and long formats. Also note that it's
uncompiled/untested, so be careful.
static const UInt32 kPalm35version = sysMakeROMVersion(3, 5, 0,
sysROMStageRelease, 0);
static const UInt32 kMaxMedDOWNameSize = 8;
void GetDOWName(Int16 iDOWNumber, Char* oDayNameString)
{
UInt32 attribute;
UInt16 bytesPerDayName;
MemHandle dayOfWeekStringsH;
Char* dayOfWeekStringsP;
// If the ROM version is recent enough, use DateTemplateToAscii
if ((FtrGet(sysFtrCreator, sysFtrNumROMVersion, &attribute) == errNone)
&& (attribute >= kPalm35version)) {
// I know May 7th, 2000 is a Sunday, so generate an appropriate
// date for the call.
DateTemplateToAscii("^1r", 5, 7 + iDOWNumber, 2000,
oDayNameString, kMaxMedDOWNameSize);
return;
}
// We have to load the appropriate string resource ourselves.
We know it contains
// seven DOW names, each terminated by a space, in the
appropriate order.
dayOfWeekStringsH = DmGetResource (strRsc, daysOfWeekStrID);
dayOfWeekStringsP = (Char*)MemHandleLock(dayOfWeekStringsH);
bytesPerDayName = StrLen(dayOfWeekStringsP) / daysInWeek;
MemMove(oDayNameString, dayOfWeekStringsP + (iDOWNumber *
bytesPerDayName), bytesPerDayName - 1);
oDayNameString[bytesPerDayName] = '\0';
}
-- Ken
Ken Krugler
TransPac Software, Inc.
<http://www.transpac.com>
+1 530-470-9200
--
For information on using the Palm Developer Forums, or to unsubscribe, please see
http://www.palmos.com/dev/tech/support/forums/