ICU-10979 add udat_adoptNumberFormat & update doc

X-SVN-Rev: 36035
This commit is contained in:
Tom Zhang 2014-07-15 20:39:51 +00:00
parent f58b3f8fd7
commit 8787394bd1
3 changed files with 32 additions and 0 deletions

View File

@ -356,6 +356,13 @@ udat_setNumberFormat(UDateFormat* fmt,
((DateFormat*)fmt)->setNumberFormat(*((NumberFormat*)numberFormatToSet));
}
U_DRAFT void U_EXPORT2
udat_adoptNumberFormat( UDateFormat* fmt,
UNumberFormat* numberFormatToAdopt)
{
((DateFormat*)fmt)->adoptNumberFormat((NumberFormat*)numberFormatToAdopt);
}
U_CAPI const char* U_EXPORT2
udat_getAvailable(int32_t index)
{

View File

@ -1088,6 +1088,7 @@ udat_getNumberFormat(const UDateFormat* fmt);
* Set the UNumberFormat associated with an UDateFormat.
* A UDateFormat uses a UNumberFormat to format numbers within a date,
* for example the day number.
* Note: udat_setNumberFormat will clone the UNumberFormat*
* @param fmt The formatter to set.
* @param numberFormatToSet A pointer to the UNumberFormat to be used by fmt to format numbers.
* @see udat_getNumberFormat
@ -1097,6 +1098,19 @@ U_STABLE void U_EXPORT2
udat_setNumberFormat( UDateFormat* fmt,
const UNumberFormat* numberFormatToSet);
/**
* Adopt the UNumberFormat associated with an UDateFormat.
* A UDateFormat uses a UNumberFormat to format numbers within a date,
* for example the day number.
* @param fmt The formatter to set.
* @param numberFormatToAdopt A pointer to the UNumberFormat to be used by fmt to format numbers.
* @see udat_getNumberFormat
* @draft ICU 54
*/
U_DRAFT void U_EXPORT2
udat_adoptNumberFormat( UDateFormat* fmt,
UNumberFormat* numberFormatToAdopt);
/**
* Get a locale for which date/time formatting patterns are available.
* A UDateFormat in a locale returned by this function will perform the correct

View File

@ -66,6 +66,7 @@ static void TestDateFormat()
UChar* result = NULL;
const UCalendar *cal;
const UNumberFormat *numformat1, *numformat2;
UNumberFormat *adoptNF;
UChar temp[50];
int32_t numlocales;
UDate d1;
@ -338,6 +339,16 @@ static void TestDateFormat()
log_err("FAIL: error in setNumberFormat or getNumberFormat()\n");
else
log_verbose("PASS:setNumberFormat and getNumberFormat succesful\n");
/*Test getNumberFormat() and adoptNumberFormat() */
log_verbose("\nTesting the get and adopt NumberFormat properties of date format\n");
adoptNF= unum_open(UNUM_DEFAULT, NULL, 0, NULL, NULL, &status);
udat_adoptNumberFormat(def1, adoptNF);
numformat2=udat_getNumberFormat(def1);
if(u_strcmp(myNumformat(adoptNF, num), myNumformat(numformat2, num)) !=0)
log_err("FAIL: error in adoptNumberFormat or getNumberFormat()\n");
else
log_verbose("PASS:adoptNumberFormat and getNumberFormat succesful\n");
/*try setting the number format to another format */
numformat1=udat_getNumberFormat(def);