What is returned from CFLocaleGetSystem?
What is returned from CFLocaleGetSystem?
- Subject: What is returned from CFLocaleGetSystem?
- From: Mark Schisler <email@hidden>
- Date: Wed, 06 Jul 2011 11:46:04 -0400
- Acceptlanguage: en-US
- Thread-topic: What is returned from CFLocaleGetSystem?
When attempting to use CFLocaleGetSystem() as a parameter to
CFDateFormatterCreate(), a call to
CFDateFormatterGetAbsoluteTimeFromString() using the created
CFDateFormatterRef seemed to always return false. However, when I changed
the code to use a locale created by CFLocaleCopyCurrent, formatting was
successful. See my static C++ function below:
GregorianDate GregorianDate::getFromFormat(
const ReferenceCountedNonMutableString& date, const
ReferenceCountedNonMutableString& format) {
CFAbsoluteTime absTime;
CFGregorianDate gregDate;
CFLocaleRef locale = CFLocaleGetSystem(); // or
CFLocaleCopyCurrent();
CFDateFormatterRef dateFormatter = CFDateFormatterCreate(
kCFAllocatorDefault, locale, kCFDateFormatterNoStyle,
kCFDateFormatterNoStyle);
CFDateFormatterSetFormat(dateFormatter, format.getAsCFStringRef());
CFDateFormatterSetProperty(dateFormatter,kCFDateFormatterIsLenient,
kCFBooleanTrue);
Boolean success =
CFDateFormatterGetAbsoluteTimeFromString(dateFormatter,
date.getAsCFStringRef(), NULL, &absTime);
// return an invalid date
if (!success)
{
return GregorianDate(0,0,0);
}
gregDate = CFAbsoluteTimeGetGregorianDate(absTime, NULL);
CFRelease(dateFormatter);
// CFRelease(locale);
return GregorianDate(gregDate);
}
The documentation states CFLocaleGetSystem returns "the root, canonical
locale", which "contains fixed backstop settings for all locale
information". Clearly, this appears to be something different from the
current user locale. My question is: is this a valid locale for anything?
What is its use-case?
Thanks in advance!
Mark
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden